module onnxrt.ops_cpu.op_batch_normalization#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_batch_normalization

Short summary#

module mlprodict.onnxrt.ops_cpu.op_batch_normalization

Runtime operator.

source on GitHub

Classes#

class

truncated documentation

BatchNormalization_14

BatchNormalization ================== Carries out batch normalization as described in the paper https://arxiv.org/abs/1502.03167. …

BatchNormalization_14

BatchNormalization ================== Carries out batch normalization as described in the paper https://arxiv.org/abs/1502.03167. …

BatchNormalization_9

Functions#

function

truncated documentation

_batchnorm_test_mode

_batchnorm_training_mode

Properties#

property

truncated documentation

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

Methods#

method

truncated documentation

__init__

__init__

__init__

_run

_run

_run

Documentation#

Runtime operator.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_batch_normalization.BatchNormalization#

alias of BatchNormalization_14

class mlprodict.onnxrt.ops_cpu.op_batch_normalization.BatchNormalization_14(onnx_node, desc=None, **options)#

Bases: OpRun

BatchNormalization#

Carries out batch normalization as described in the paper https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, There are five required inputs ‘X’, ‘scale’, ‘B’, ‘input_mean’ and ‘input_var’. Note that ‘input_mean’ and ‘input_var’ are expected to be the estimated statistics in inference mode (training_mode=False, default), and the running statistics in training mode (training_mode=True). There are multiple cases for the number of outputs, which we list below:

Output case #1: Y, running_mean, running_var (training_mode=True) Output case #2: Y (training_mode=False)

When training_mode=False, extra outputs are invalid. The outputs are updated as follows when training_mode=True: `` running_mean = input_mean * momentum + current_mean * (1 - momentum) running_var = input_var * momentum + current_var * (1 - momentum)

Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B

where:

current_mean = ReduceMean(X, axis=all_except_channel_index) current_var = ReduceVar(X, axis=all_except_channel_index)

Notice that ReduceVar refers to the population variance, and it equals to sum(sqrd(x_i - x_avg)) / N where N is the population size (this formula does not use sample size N - 1).

``

When training_mode=False: `` Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B ``

For previous (depreciated) non-spatial cases, implementors are suggested to flatten the input shape to (N x C * D1 * D2 * … * Dn) before a BatchNormalization Op. This operator has optional inputs/outputs. See ONNX for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument’s name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.

Attributes

  • epsilon: The epsilon value to use to avoid division by zero. Default value is nameepsilonf9.999999747378752e-06typeFLOAT (FLOAT)

  • momentum: Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum). Default value is namemomentumf0.8999999761581421typeFLOAT (FLOAT)

  • training_mode: If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated. Default value is nametrainingmodei0typeINT (INT)

Inputs

  • X (heterogeneous)T: Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1

  • scale (heterogeneous)T: Scale tensor of shape (C).

  • B (heterogeneous)T: Bias tensor of shape (C).

  • input_mean (heterogeneous)U: running (training) or estimated (testing) mean tensor of shape (C).

  • input_var (heterogeneous)U: running (training) or estimated (testing) variance tensor of shape (C).

Outputs

Between 1 and 3 outputs.

  • Y (heterogeneous)T: The output tensor of the same shape as X

  • running_mean (optional, heterogeneous)U: The running mean after the BatchNormalization operator.

  • running_var (optional, heterogeneous)U: The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1.

Type Constraints

  • T tensor(float16), tensor(float), tensor(double), tensor(bfloat16): Constrain input and output types to float tensors.

  • U tensor(float16), tensor(float), tensor(double), tensor(bfloat16): Constrain mean and variance types to float tensors. It allows all float type for U.

Version

Onnx name: BatchNormalization

This version of the operator has been available since version 14.

Runtime implementation: BatchNormalization

__init__(onnx_node, desc=None, **options)#
_run(x, scale, bias, mean, var, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_batch_normalization.BatchNormalization_9(onnx_node, desc=None, **options)#

Bases: OpRun

__init__(onnx_node, desc=None, **options)#
_run(x, scale, bias, mean, var, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_batch_normalization._batchnorm_test_mode(x, s, bias, mean, var, epsilon=1e-05)#
mlprodict.onnxrt.ops_cpu.op_batch_normalization._batchnorm_training_mode(x, s, bias, mean, var, momentum=0.9, epsilon=1e-05)#