:mod:`blueoil.converter.core.operators` ======================================= .. py:module:: blueoil.converter.core.operators .. autoapi-nested-parse:: Definition of operators. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: blueoil.converter.core.operators.Operator blueoil.converter.core.operators.Variable blueoil.converter.core.operators.Input blueoil.converter.core.operators.Constant blueoil.converter.core.operators.Output blueoil.converter.core.operators.Identity blueoil.converter.core.operators.Quantizer blueoil.converter.core.operators.BinaryMeanScalingQuantizer blueoil.converter.core.operators.SpaceToDepth blueoil.converter.core.operators.Transpose blueoil.converter.core.operators.Conv blueoil.converter.core.operators.BatchNormalization blueoil.converter.core.operators.LinearMidTreadHalfQuantizer blueoil.converter.core.operators.Add blueoil.converter.core.operators.Sub blueoil.converter.core.operators.Pool blueoil.converter.core.operators.MaxPool blueoil.converter.core.operators.AveragePool blueoil.converter.core.operators.Reshape blueoil.converter.core.operators.Softmax blueoil.converter.core.operators.Relu blueoil.converter.core.operators.LeakyRelu blueoil.converter.core.operators.Flatten blueoil.converter.core.operators.Dropout blueoil.converter.core.operators.Gemm blueoil.converter.core.operators.Mul blueoil.converter.core.operators.BinaryChannelWiseMeanScalingQuantizer blueoil.converter.core.operators.ConcatOnDepth blueoil.converter.core.operators.Maximum blueoil.converter.core.operators.DepthToSpace blueoil.converter.core.operators.ResizeNearestNeighbor blueoil.converter.core.operators.Split blueoil.converter.core.operators.Slice blueoil.converter.core.operators.Pad blueoil.converter.core.operators.MatMul blueoil.converter.core.operators.Gather blueoil.converter.core.operators.Unique blueoil.converter.core.operators.UniqueValue blueoil.converter.core.operators.UniqueIndex blueoil.converter.core.operators.Cast blueoil.converter.core.operators.Minimum blueoil.converter.core.operators.StridedSlice blueoil.converter.core.operators.Lookup blueoil.converter.core.operators.Prod blueoil.converter.core.operators.Shape blueoil.converter.core.operators.BatchNormalizationOptimized .. data:: Ops .. data:: OutOps .. data:: warning_sign .. py:class:: Operator(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`object` Base class of operators. .. attribute:: _input_names :annotation: :List[str] = ['input'] .. attribute:: _output_names :annotation: :List[str] = ['output'] .. method:: update_shape(self, shape: List[int], dimension_format: str) -> None .. method:: __connect_to_outputs(self) -> None Connect input operators' outputs to this object. .. method:: _assert(self, predicate: bool, message: str = '') -> None Assert a predicate. When it fails, raise an error. This is a substitute for an `assert` statement. The `assert` is not checked in byte-compiled code, but this is always checked. :param predicate: Assertion to be true :type predicate: bool :param message: Error message in the failure of the assertion :type message: str .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: equals(self, other: Any) -> bool Return if these two objects are equivalent. .. method:: name(self) -> str :property: Return name. This must be a unique name in the graph. .. method:: op_type(self) -> str :property: Return the operation type. .. method:: input_ops(self) -> Ops :property: Return a dict of input operators. :returns: Collection of input operators in a dictionary format. The keys are input symbols, which can be taken from `input_names` property. :rtype: dict .. method:: input_names(cls) -> List[str] Return the input key names the operator provides. For example, `Conv` has two inputs, 'X' for the input data and 'W' for the weight. So `Conv.input_names` returns the list `['X', 'W']`. :returns: List of key names :rtype: list[str] .. method:: input_nodes(self) -> List['Operator'] :property: Return a list of input operators in proper order (original protobuf argument order). :returns: This list is already ordered following the order of the arguments in the original protobuf operators (positional order in the list of arguments). :rtype: list[Operator] .. method:: output_ops(self) -> OutOps :property: Return a dict of output operators. :returns: Collection of (list of) output operators in a dictionary format. The keys are output symbols, which can be taken from `output_names` property. :rtype: dict .. method:: output_op_list(self) -> List['Operator'] :property: Return a list of output operators. :returns: List of output operators. :rtype: list[Operator] .. method:: output_names(cls) -> List[str] Return the output key names the operator provides. For example, `Conv` has one output 'Y'. So `Conv.output_names` returns the list `['Y']`. :returns: List of key names :rtype: list[str] .. method:: add_input(self, ident: str, node: Operator) -> None Add input node. Args ident (str): key name of the input. This has to be in list `input_names`. node (Operator): Node to be registered as the input. .. method:: add_inputs(self, inputs: Ops) -> None Add input (possibly multiple) nodes at a once. :param outputs: Collection of pair of key name and a operator to be registered as the input. All the key names have to be in list `input_names`. :type outputs: dict .. method:: add_output(self, ident: str, node: Operator) -> None Add output node. :param ident: key name of the output. This has to be in list `output_names`. :type ident: str :param node: Node to be registered as the output. :type node: Operator .. method:: add_outputs(self, outputs: OutOps) -> None Add output (possibly multiple) nodes at a once. :param outputs: Collection of pair of key name :type outputs: Dict of str to list of Operators :param and a list of operators to be registered as the output.: All the key names have to be in list `output_names`. .. method:: remove_input(self, ident: str) -> None Remove an input node. :param ident: Key name of the input node to be removed. This key is in `input_names`, not the name of the operator. :type ident: str .. method:: remove_output(self, ident: str) -> None Remove an output node. :param ident: Key name of the output node to be removed. This key is in `output_names`, not the name of the operator. :type ident: str .. method:: shape(self) -> List[int] :property: Get the shape defined in this node. .. method:: dtype(self) -> DataType :property: Get the data type defined in this node. .. method:: ndims(self) -> int :property: Get the number of dimension defined in this node. .. method:: dimension(self) -> str :property: Return dimension in string. This dimension consists of 'N', 'C', 'H', and 'W', where 'N' is the number of batch size, 'C' is the number of channels, 'H' and 'C' are the height and the weight in the 2-D image. .. method:: size(self) -> int :property: Get the whole size of the output data. .. method:: is_variable(self) -> bool :property: Return if this node is a variable node (i.e. Input or Output). .. method:: is_scalar(self) -> bool :property: Return if this node is a scalar node (i.e. `ndims == 0`). .. method:: height(self) -> int :property: Get the size of height in the shape. .. method:: width(self) -> int :property: Get the size of width in the shape. .. method:: channels(self) -> int :property: Get the number of channels in the shape. .. method:: batchsize(self) -> int :property: Get the number of batch size in the shape. .. method:: rank(self) -> int :property: .. method:: available_buffer(self) -> str :property: .. method:: transpose(self, perm: List[int]) -> None Transpose the shape and format. This operation is destructive. .. method:: data(self) -> np.ndarray :property: Get the output data. This value is valid only after `run_forward()` or some value has assigned with the setter. .. method:: is_monotonic(self) -> bool :property: .. method:: run(self, **kwargs) -> Dict :abstractmethod: The intermediate runtime, run the operator with external data This is actually an abstract method and should be overridden. .. method:: run_forward(self) -> np.ndarray :abstractmethod: Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: _dispatch_name(self) -> str :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> Sequence[Optional[int]] :classmethod: :abstractmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Variable(name: str, shape: List[int], dtype: DataType, input_ops: Ops, data: np.ndarray, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Variable class, which must be Input, Output or a constant. .. method:: is_variable(self) -> bool :property: Return True, as this is a variable. .. method:: is_monotonic(self) -> bool :property: .. method:: transpose(self, perm: List[int]) -> None Transpose the shape and format. This operation is destructive. .. method:: data(self) -> np.ndarray :property: Return data. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Input(name: str, shape: List[int], dtype: DataType, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Variable` Input class. This is a placeholder. .. attribute:: _input_names :annotation: :List[str] = [] .. attribute:: _output_names :annotation: = ['output'] .. py:class:: Constant(name: str, dtype: DataType, data: np.ndarray, dimension_format: str = 'OHWI', transposed_dimension_format: str = 'OHWI', packed: bool = False, actual_shape: List[int] = [], transposed_data: Optional[List[int]] = None, transposed_shape: Optional[List[int]] = None, kn2row_data: Optional[List[int]] = None, kn2row_dimension_format: str = 'HWOI', kn2row_shape: Optional[List[int]] = None) Bases: :class:`blueoil.converter.core.operators.Variable` Constant class. This object has data inside. .. attribute:: _input_names :annotation: :List[str] = [] .. attribute:: _output_names :annotation: = ['output'] .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_packed(self) -> bool :property: .. method:: transposed_data(self) -> Optional[List[int]] :property: Return transposed data. .. method:: transposed_dimension_format(self) -> str :property: .. method:: transposed_shape(self) -> Optional[List[int]] :property: .. method:: kn2row_data(self) -> Optional[List[int]] :property: .. method:: kn2row_dimension_format(self) -> str :property: .. method:: kn2row_shape(self) -> Optional[List[int]] :property: .. py:class:: Output(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Variable` Output class. .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: :List[str] = [] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. py:class:: Identity(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Identity operator. Inputs ------ input Input tensor Output ------ output Tensor to copy input .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Quantizer(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Base class for quantizers. .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: equals(self, other: Any) -> bool Return if these two objects are equivalent. .. method:: nbit(self) -> int :property: .. method:: max_v(self) -> float :property: .. method:: scaling_factor(self) -> np.float32 :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. method:: binarizer(self, data: np.ndarray) -> np.ndarray :abstractmethod: Maps the quantized values into >= 0 integer values. This is actually an abstract method and should be overridden. .. py:class:: BinaryMeanScalingQuantizer(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Quantizer` Quantization operator using binary scaling. Input ----- input Input tensor, which must have float values. Output ------ output Quantized tensor .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: _dispatch_name(self) -> str :property: .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: run_forward_no_scaling_factor(self) -> np.ndarray .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: binarizer(self, data: np.ndarray) -> np.ndarray Maps the quantized values into >= 0 integer values. .. py:class:: SpaceToDepth(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', block_size: int = 2) Bases: :class:`blueoil.converter.core.operators.Operator` Space to Depth operator. Input ----- input Input tensor Output ------ output A tensor with reduced height and width and increased channels Attributes (optional constructor parameters) ---------- block_size : integer Input block size .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None This check the following constraints: Output channels must be 1. (multiple of kernel_size^2 * 32) OR 2. (kernel_size^2 * {8, 16}). .. method:: is_monotonic(self) -> bool :property: .. method:: _dispatch_name(self) -> str :property: .. method:: block_size(self) -> np.int32 :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Transpose(name: str, shape: List[int], dtype: DataType, input_ops: Ops, perm: List[int] = [], dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Transpose operator. Transpose the input tensor similar to numpy.transpose. For example, when perm=[3, 1, 0, 2], given an input tensor of shape [1, 2, 3, 4], the output shape will be [4, 2, 1, 3]. Inputs ------ data An input tensor. Outputs ------- transposed Transposed output. Attributes (optional constructor parameters) perm : list of ints A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given. .. attribute:: _input_names :annotation: = ['data'] .. attribute:: _output_names :annotation: = ['transposed'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: permutation(self) -> List[int] :property: Get transpose permutation in list of ints. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Conv(name: str, shape: List[int], dtype: DataType, input_ops: Ops, kernel_shape: List[int] = [], kernel_dimensions: int = 2, dimension_format: str = 'NHWC', kernel_dim_format: str = 'HW', dilations: List[int] = [1, 1], pads: List[int] = [0, 0, 0, 0], strides: List[int] = [1, 1], quantized: bool = False, thresholds: List[float] = []) Bases: :class:`blueoil.converter.core.operators.Operator` Convolution operator. The convolution operator consumes an input tensor and a weight, and computes the output. Currently this is only for 2-D images. Inputs ------ X Input data tensor from previous layer. Note that this is for the 2D image. W The weight tensor that will be used in the convolutions. B (Optional) 1D bias. Outputs ------- Y Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths. Attributes (Optional constructor parameters) ---------- kernel_shape : list of ints The shape of the convolution kernel. If not present, should be inferred from input W. kernel_dimensions : int The dimension of the input. The default value is 2, which means 2-D image. dimension_format : str Dimension denotation, which must consists of 'N', 'C', 'H', and 'W', where 'N' is the number of batch size, 'C' is the number of channels, 'H' and 'W' are the height and width of input image. The default is 'NHWC'. kernel_dim_format : str Dimension denotation, which must consists of 'H' and 'W', where 'H' and 'W' are the height and width of input image. The default is 'HW'. dilations : list of ints Dilation value along each axis of the filter. If not present, the dilation defaults to 1 along each axis. pads : list of ints Padding for the beginning and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin, x1_end, x2_end], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. If not present, the padding defaults to 0 along start and end of each axis. strides : list of ints Stride along each axis. If not present, the stride defaults to 1 along each axis. quantized : bool Whether it is quantized. If not present, the switch defaults to False. thresholds : list of floats Threshold values that are used in threshold skipping. If not present, this defaults to an empty list. Ignored if `quantized` is not true. .. attribute:: _input_names :annotation: = ['X', 'W', 'B'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: kernel_dimensions(self) -> int :property: Get the number of dimensions. .. method:: dilations(self) -> List[int] :property: Get dilations. .. method:: pads(self) -> List[int] :property: Get pads. .. method:: strides(self) -> List[int] :property: Get strides. .. method:: is_monotonic(self) -> bool :property: .. method:: is_quantized(self) -> bool :property: Return if this operator is quantized. Currently it always returns False, as quantized version is not supported yet. .. method:: scaling_factor(self) -> float :property: .. method:: a_quantizer(self) -> List[Quantizer] :property: .. method:: quantizer(self) -> Optional[Quantizer] :property: .. method:: kernel_height(self) -> int :property: Return the height in the kernel shape. .. method:: kernel_width(self) -> int :property: Return the weight in the kernel shape. .. method:: has_thresholds(self) -> bool :property: .. method:: thresholds(self) -> List[float] :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its shape from inputs' shapes. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: BatchNormalization(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', epsilon: float = float(10**(-5)), is_test: bool = False) Bases: :class:`blueoil.converter.core.operators.Operator` Batch normalization operator. Carries out batch normalization as described in the paper https://arxiv.org/abs/1502.03167. Inputs ------ X The input 4-dimensional tensor. scale The scale as a 1-dimensional tensor of size C to be applied to the output. B The bias as a 1-dimensional tensor of size C to be applied to the output. mean The estimated mean (testing) as a 1-dimensional tensor of size C. var The estimated variance (testing) as a 1-dimensional tensor of size C. Outputs ------- Y The output 4-dimensional tensor of the same shape as X. Attributes (Optional constructor parameters) ---------- dimension_format : str Dimension denotation, which must consists of 'N', 'C', 'H', and 'W', where 'N' is the number of batch size, 'C' is the number of channels, 'H' and 'W' are the height and width of input image. The default is 'NHWC'. epsilon : float The epsilon value to use to avoid division by zero, default is 1e-5f. is_test : bool If set to True, run spatial batch normalization in test mode, default is False. .. attribute:: _input_names :annotation: = ['X', 'scale', 'B', 'mean', 'var'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run(self, **kwargs) -> Dict Return the forward calculation results of batch normalization. Currently this function is only used by threshold skipping optimization pass for recursively calculating thresholds of the skipping patterns. .. method:: de_run(self, **kwargs) -> Dict Return the reversed calculation results of batch normalization. Currently this function is only used by threshold skipping optimization pass for recursively calculating thresholds of the skipping patterns. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: epsilon(self) -> float :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: _dispatch_name(self) -> str :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: LinearMidTreadHalfQuantizer(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Quantizer` Quantization operator with 'linear mid tread half'. Input ----- X Input tensor Y Constant Z Another constant .. attribute:: _input_names :annotation: = ['X', 'Y', 'Z'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run(self, **kwargs) -> Dict Return the result of forward calculation of an activation quantizer. Currently this function is only used by threshold skipping optimization pass for recursively calculating thresholds of the skipping patterns. .. method:: de_run(self, **kwargs) -> Dict Return the result of reversed calculation of an activation quantizer. Currently this function is only used by threshold skipping optimization pass for recursively calculating thresholds of the skipping patterns. .. method:: run_forward(self) -> np.ndarray General function for this quantization operator. This function returns numpy array. .. method:: nbit(self) -> int :property: .. method:: max_v(self) -> float :property: .. method:: is_monotonic(self) -> bool :property: .. method:: _dispatch_name(self) -> str :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: binarizer(self, data: np.ndarray) -> np.ndarray Maps the quantized values into >= 0 integer values. .. py:class:: Add(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Add operator. Performs element-wise binary addition (with Numpy-style broadcasting support). This operator supports multidirectional (i.e., Numpy-style) broadcasting. Inputs ------ A First operand. B Second operand. Outputs ------- C Result, has same element type as two inputs .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Sub(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Subtract operator. Performs element-wise subtraction (with Numpy-style broadcasting support). This operator supports multidirectional (i.e., Numpy-style) broadcasting. Inputs ------ A First operand. B Second operand. Outputs ------- C Result, has same element type as two inputs .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Pool(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', kernel_shape: List[int] = [2, 2], kernel_dim_format: str = 'HW', dimensions: int = 2, pads: List[int] = [0, 0, 0, 0], strides: List[int] = [1, 1]) Bases: :class:`blueoil.converter.core.operators.Operator` Pooling operator. This is a base class and must not be instantiated directly. .. attribute:: _input_names :annotation: = ['X'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: kernel_height(self) -> int :property: Get the height in the kernel shape. .. method:: kernel_width(self) -> int :property: Get the Width in the kernel shape. .. method:: pads(self) -> List[int] :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its shape from inputs' shapes. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: MaxPool(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', kernel_shape: List[int] = [2, 2], kernel_dim_format: str = 'HW', dimensions: int = 2, pads: List[int] = [0, 0, 0, 0], strides: List[int] = [1, 1]) Bases: :class:`blueoil.converter.core.operators.Pool` Max pooling operator. MaxPool consumes an input tensor X and applies max pooling across the the tensor according to kernel sizes, stride sizes, and pad lengths. max pooling consisting of computing the max on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. Inputs ------ X Input data tensor from the previous operator. Outputs ------- Y Output data tensor from max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used. Attributes (Optional constructor parameters) -------------------------------------------- dimension_format : str Dimension denotation, which must consists of 'N', 'C', 'H', and 'W', where 'N' is the number of batch size, 'C' is the number of channels, 'H' and 'W' are the height and width of input image. The default is 'NHWC'. kernel_shape : list of ints The size of the kernel along each axis. kernel_dim_format : str Dimension denotation, which must consists of H', and 'W', where 'H' and 'W' are the height and width of input image. The default is 'HW'. dimensions : int Dimensions. This defaults to 2, which means 2-D image. Currently only 2 is available. pads : list of ints Padding for the beginning and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin, x1_end, x2_end], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. If not present, the padding defaults to 0 along start and end of each axis. strides : list of ints Stride along each axis. If not present, the stride defaults to 1 along each axis. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: AveragePool(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', kernel_shape: List[int] = [2, 2], kernel_dim_format: str = 'HW', dimensions: int = 2, pads: List[int] = [0, 0, 0, 0], strides: List[int] = [1, 1]) Bases: :class:`blueoil.converter.core.operators.Pool` Average pooling operator. AveragePool consumes an input tensor X and applies average pooling across the the tensor according to kernel sizes, stride sizes, and pad lengths. average pooling consisting of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. Inputs ------ X Input data tensor from the previous operator. Outputs ------- Y Output data tensor from average pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used. Attributes (Optional constructor parameters) -------------------------------------------- dimension_format : str Dimension denotation, which must consists of 'N', 'C', 'H', and 'W', where 'N' is the number of batch size, 'C' is the number of channels, 'H' and 'W' are the height and width of input image. The default is 'NHWC'. kernel_shape : list of ints The size of the kernel along each axis. kernel_dim_format : str Dimension denotation, which must consists of H', and 'W', where 'H' and 'W' are the height and width of input image. The default is 'HW'. dimensions : int Dimensions. This defaults to 2, which means 2-D image. Currently only 2 is available. pads : list of ints Padding for the beginning and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin, x1_end, x2_end], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. If not present, the padding defaults to 0 along start and end of each axis. strides : list of ints Stride along each axis. If not present, the stride defaults to 1 along each axis. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. py:class:: Reshape(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Reshape operator. Reshape the input tensor similar to numpy.reshape. It takes a tensor as input and an argument shape. It outputs the reshaped tensor. At most one dimension of the new shape can be -1. In this case, the value is inferred from the size of the tensor and the remaining dimensions. A dimension could also be 0, in which case the actual dimension value is unchanged (i.e. taken from the input tensor). Inputs ------ data An input tensor. Outputs ------- reshaped Reshaped data. .. attribute:: _input_names :annotation: = ['data', 'shape'] .. attribute:: _output_names :annotation: = ['reshaped'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Softmax(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Softmax operator. The operator computes the softmax (normalized exponential) values for each layer in the batch of the given input. The input is a 2-D tensor (Tensor) of size (batch_size x input_feature_dimensions). The output tensor has the same shape and contains the softmax values of the corresponding input. X does not need to explicitly be a 2D vector; rather, it will be coerced into one. For an arbitrary n-dimensional tensor X \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is the axis provided, then X will be coerced into a 2-dimensional tensor with dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default case where axis=1, this means the X tensor will be coerced into a 2D tensor of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. Each of these dimensions must be matched correctly, or else the operator will throw errors. Inputs ------ input The input tensor that's coerced into a 2D matrix of size (NxD) as described above. Outputs ------- output The output values with the same shape as input tensor. .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Relu(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Relu class. Relu takes one input data (Tensor) and produces one output data (Tensor) where the rectified linear function, y = max(0, x), is applied to the tensor elementwise. Inputs ------ X Input tensor Outputs ------- Y Output tensor .. attribute:: _input_names :annotation: = ['X'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: LeakyRelu(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', alpha: float = 0.2) Bases: :class:`blueoil.converter.core.operators.Operator` Leaky relu class. Leaky_relu takes one input data (Tensor) and produces one output data (Tensor) where the function, y = max(input * alpha, input), is applied to the tensor elementwise. Inputs ------ X Input tensor Outputs ------- Y Output tensor .. attribute:: _input_names :annotation: = ['X'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Flatten(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'HWCN', axis: int = 1) Bases: :class:`blueoil.converter.core.operators.Operator` Flatten class. Flattens the input tensor into a 2D matrix. If input tensor has shape [d_0, d_1, ... d_n] then the output will have shape [d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn]. Inputs ------ input A tensor of rank >= axis. Outputs ------- output A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output. .. attribute:: axis (Default to 1) Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R is the rank of the input tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n). :type: int .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Dropout(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'HWCN', ratio: float = 0.5) Bases: :class:`blueoil.converter.core.operators.Operator` Dropout operator. Dropout takes one input data (Tensor) and produces two Tensor outputs, output (Tensor) and mask (Tensor). Y will either be a random dropout, or a simple copy of the input. Note that our implementation of Dropout does scaling in the training phase, so during testing nothing needs to be done. This operator has optional inputs/outputs. Inputs ------ data The input data as Tensor. Outputs (1 - 2) ------- output The output. mask (optional) The output mask. .. attribute:: ratio (float, default 0.5) the ratio of random dropout :type: float .. attribute:: _input_names :annotation: = ['data'] .. attribute:: _output_names :annotation: = ['output', 'mask'] .. method:: ratio(self) :property: .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Gemm(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'HWCN', alpha: float = 1.0, beta: float = 1.0, transA: bool = False, transB: bool = False) Bases: :class:`blueoil.converter.core.operators.Operator` Gemm operator. General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 A' = transpose(A) if transA else A B' = transpose(B) if transB else B Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape [M, K] or [K, M], input tensor B has shape [K, N] or [N, K], input tensor C is broadcastable to shape [M, N], and output tensor Y has shape [M, N]. A will be transposed before doing the computation if attribute transA is True, same for B and transB. This operator supports unidirectional broadcasting (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check the doc. Inputs ------ A Input tensor A. The shape of A should be [M, K] if transA is False, or [K, M] if transA is True. B Input tensor B. The shape of B should be (K, N) if transB is False, or [N, K] if transB is True. C Input tensor C. The shape of C should be unidirectional broadcastable to [M, N]. Outputs ------- Y Output tensor of shape [M, N]. .. attribute:: alpha Scalar multiplier for the product of input tensors A * B .. attribute:: beta Scalar multiplier for input tensor C .. attribute:: transA Whether A should be transposed .. attribute:: transB Whether B should be transposed .. attribute:: _input_names :annotation: = ['A', 'B', 'C'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Mul(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Mul operator. Performs element-wise binary multiplication (with Numpy-style broadcasting support). This operator supports multidirectional (i.e., Numpy-style) broadcasting. Inputs ------ A First operand. B Second operand. Outputs ------- C Result, has same element type as two inputs .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. py:class:: BinaryChannelWiseMeanScalingQuantizer(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Quantizer` Quantization operator using binary channel wise scaling. Input ----- input Input tensor, which must have float values. Output ------ output Quantized tensor .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: run_forward_no_scaling_factor(self) -> np.ndarray .. method:: binarizer(self, data: np.ndarray) -> np.ndarray Maps the quantized values into >= 0 integer values. .. py:class:: ConcatOnDepth(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Concatenation operator. Input ----- input1 Input tensor input2 Input tensor input3 Input tensor input4 Input tensor input5 Input tensor Output ------ output A tensor which is the concatenation of the inputs in the channel axis Attributes (optional constructor parameters) ---------- block_size : integer Input block size .. attribute:: _input_names :annotation: = ['input1', 'input2', 'input3', 'input4', 'input5', 'input6'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Maximum(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Maximum operator. Performs element-wise max() operation. Inputs ------ A First operand. B Second operand. Outputs ------- C Result, has same shape and data type than the inputs .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: DepthToSpace(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', block_size: int = 2) Bases: :class:`blueoil.converter.core.operators.Operator` Depth to Space operator. Input ----- input Input tensor Output ------ output A tensor with increased height and width and decreased channels Attributes (optional constructor parameters) ---------- block_size : integer Input block size .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None This check the following constraints: 1. quantized-packed data requires channels of input must be multiple of kernel_size^2 * 32 .. method:: is_monotonic(self) -> bool :property: .. method:: _dispatch_name(self) -> str :property: .. method:: block_size(self) -> np.int32 :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: ResizeNearestNeighbor(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Resize Nearest Neighbor operator. Input ----- input Input tensor Output ------ output A tensor with resized height and width and same channels Attributes (optional constructor parameters) ---------- Align corners is not supported. .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: _dispatch_name(self) -> str :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Split(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Split operator (dummy). Split operator is converted to Slice operators by Importer. .. attribute:: _input_names :annotation: = ['A', 'B'] .. py:class:: Slice(name: str, shape: List[int], dtype: DataType, input_ops: Ops, begin: int, size: int, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Slice operator. Slice a tensor, along channels. Input ----- input The tensor to slice Output ------ output Output tensor after slice Attributes (optional constructor parameters) ---------- begin : integer slice starts from size : integer Length of output channels .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: begin(self) -> int :property: .. method:: slice_size(self) -> int :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Pad(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Pad operator. Pad a tensor. This operation pads a tensor according to the paddings specified Input ----- A The input to be padded B The padding size, this (B) is a numpy array that supports "CONSTANT" mode in tensorflow during importing, it has shape of [n, 2], where n is the rank of input A, assume input A has dimension of D the padded size of each dimension D of the output C is given by the formula below: B[D, 0] + A.dim_size(D) + B[D, 1] Note. currently only the channel-wise paddings are supported. Output ------ C A result after being padded. Has the same type as input tensor .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[Optional[int]] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: MatMul(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Matrix Multiplication operator. Matrix product. Multiplies matrix a by matrix b, producing a * b Generalized universal function signature, e.g., ``(m,n),(n,p)->(m,p)`` for ``np.matmul``. Input ----- A 2-dimensional matrix A B 2-dimensional matrix B Output ------ C Matrix multiply results from A * B .. attribute:: _input_names :annotation: = ['A', 'B'] .. attribute:: _output_names :annotation: = ['C'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: _dispatch_name(self) -> str :property: .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Gather(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Gather operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['x', 'out_idx'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Unique(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Unique operator (dummy). Unique operetor is converted to UniqueValue and UniqueIndex operators by Importer. .. attribute:: _input_names :annotation: = ['x'] .. py:class:: UniqueValue(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Unique operator (value version). Inputs ------ input The input tensor. Outputs ------- y The output. .. attribute:: _input_names :annotation: = ['x'] .. attribute:: _output_names :annotation: = ['y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: UniqueIndex(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Unique operator (index version). Inputs ------ input The input tensor. Outputs ------- idx The index of each value of input in the uniquified output. .. attribute:: _input_names :annotation: = ['x'] .. attribute:: _output_names :annotation: = ['idx'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Cast(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Cast operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['x'] .. attribute:: _output_names :annotation: = ['y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Minimum(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Minimum operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['x', 'y'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: StridedSlice(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` StridedSlice operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['input', 'begin', 'end', 'strides'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Lookup(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC', use_divide_by_255: bool = True) Bases: :class:`blueoil.converter.core.operators.Quantizer` Lookup operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['input', 'lsb', 'msb'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: nbit(self) -> int :property: .. method:: max_v(self) -> float :property: .. method:: use_divide_by_255(self) -> bool :property: .. py:class:: Prod(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Prod operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['input', 'indices'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: Shape(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Shape operator. Inputs ------ input The input tensor. Outputs ------- output The output. .. attribute:: _input_names :annotation: = ['input'] .. attribute:: _output_names :annotation: = ['output'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: is_monotonic(self) -> bool :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization .. py:class:: BatchNormalizationOptimized(name: str, shape: List[int], dtype: DataType, input_ops: Ops, dimension_format: str = 'NHWC') Bases: :class:`blueoil.converter.core.operators.Operator` Optimized batch normalization operator. This operator for only inference. Inputs ------ X The input 4-dimensional tensor. scale The scale as a 1-dimensional tensor of size C to be applied to the output. bias The bias as a 1-dimensional tensor of size C to be applied to the output. Outputs ------- Y The output 4-dimensional tensor of the same shape as X. .. attribute:: _input_names :annotation: = ['X', 'scale', 'bias'] .. attribute:: _output_names :annotation: = ['Y'] .. method:: _check_consistency(self) -> None Check data consistency in the initialization. .. method:: run(self, **kwargs) -> Dict Return the forward calculation results of batch normalization. Currently this function is only used by threshold skipping optimization pass for recursively calculating thresholds of the skipping patterns. .. method:: run_forward(self) -> np.ndarray Run the operator, calculate and set the result. This is actually an abstract method and should be overridden. .. method:: is_monotonic(self) -> bool :property: .. method:: infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str], attrs: Dict[str, Any]) -> List[int] :classmethod: Infer its output shape from inputs' shapes. This is actually an abstract method and should be overridden. .. method:: _dispatch_name(self) -> str :property: .. method:: preserve_quantization(self) -> bool :property: whether to preserve the operator for quantization