GroupNormalization#

GroupNormalization - 18#

Version

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

Summary

Attributes

  • epsilon - FLOAT : The epsilon value to use to avoid division by zero.

  • num_groups - INT (required) : The number of groups of channels. It should be a divisor of the number of channels C.

Inputs

  • X (heterogeneous) - T:

  • scale (heterogeneous) - T:

  • bias (heterogeneous) - T:

Outputs

  • Y (heterogeneous) - T:

Type Constraints

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

Examples

default

import numpy as np
import onnx

x = np.random.randn(3, 4, 2, 2).astype(np.float32)
num_groups = 2
scale = np.random.randn(num_groups).astype(np.float32)
bias = np.random.randn(num_groups).astype(np.float32)
y = _group_normalization(x, num_groups, scale, bias).astype(np.float32)

node = onnx.helper.make_node(
    "GroupNormalization",
    inputs=["x", "scale", "bias"],
    outputs=["y"],
    num_groups=num_groups,
)

expect(
    node,
    inputs=[x, scale, bias],
    outputs=[y],
    name="test_group_normalization_example",
)

x = np.random.randn(3, 4, 2, 2).astype(np.float32)
num_groups = 2
scale = np.random.randn(num_groups).astype(np.float32)
bias = np.random.randn(num_groups).astype(np.float32)
epsilon = 1e-2
y = _group_normalization(x, num_groups, scale, bias, epsilon).astype(np.float32)

node = onnx.helper.make_node(
    "GroupNormalization",
    inputs=["x", "scale", "bias"],
    outputs=["y"],
    epsilon=epsilon,
    num_groups=num_groups,
)

expect(
    node,
    inputs=[x, scale, bias],
    outputs=[y],
    name="test_group_normalization_epsilon",
)