InstanceNormalization#

  • Domain: ai.onnx

  • Since version: 22

Carries out instance normalization as described in the paper https://arxiv.org/abs/1607.08022.

y = scale * (x - mean) / sqrt(variance + epsilon) + B, where mean and variance are computed per instance per channel.

Inputs

  • input (T): Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size.

  • scale (T): The input 1-dimensional scale tensor of size C.

  • B (T): The input 1-dimensional bias tensor of size C.

Outputs

  • output (T): The output tensor of the same shape as input.

Attributes

  • epsilon (float): The epsilon value to use to avoid division by zero.

Type Constraints

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

Examples#

test_cc_instancenorm_bfloat16_large_values

Node:
  InstanceNormalization(x, s, bias) -> (y)
Inputs:
  x: shape=(1, 1, 256), dtype=bfloat16
    [[[0, 2, 4, ..., 506, 508, 510]]]
  s: shape=(1,), dtype=bfloat16
    [1]
  bias: shape=(1,), dtype=bfloat16
    [0]

Outputs:
  y: shape=(1, 1, 256), dtype=bfloat16
    [[[-1.72656, -1.71094, -1.69531, ..., 1.69531, 1.71094, 1.72656]]]

test_cc_instancenorm_epsilon

Node:
  InstanceNormalization(x, s, bias) -> (y)
  Attributes:
    epsilon = 0.009999999776482582
Inputs:
  x: shape=(2, 3, 4, 5), dtype=float32
    [[[[-1.        , -0.9       , -0.8       , -0.7       , -0.6       ],
       [-0.5       , -0.39999998, -0.3       , -0.19999999, -0.09999996],
       [ 0.        ,  0.10000002,  0.20000005,  0.30000007,  0.39999998],
       [ 0.5       ,  0.6       ,  0.70000005,  0.8000001 ,  0.9       ]],

      [[ 1.        ,  1.1000001 ,  1.2       ,  1.3       ,  1.4000001 ],
       [ 1.5       ,  1.6000001 ,  1.7       ,  1.8       ,  1.9000001 ],
       [ 2.        ,  2.1000001 ,  2.2       ,  2.3       ,  2.4       ],
       [ 2.5       ,  2.6000001 ,  2.7       ,  2.8       ,  2.9       ]],

      [[ 3.        ,  3.1       ,  3.2000003 ,  3.3000002 ,  3.4       ],
       [ 3.5       ,  3.6       ,  3.7000003 ,  3.8000002 ,  3.9       ],
       [ 4.        ,  4.1       ,  4.2000003 ,  4.3       ,  4.4       ],
       [ 4.5       ,  4.6       ,  4.7000003 ,  4.8       ,  4.9       ]]],


     [[[ 5.        ,  5.1       ,  5.2000003 ,  5.3       ,  5.4       ],
       [ 5.5       ,  5.6       ,  5.7000003 ,  5.8       ,  5.9       ],
       [ 6.        ,  6.1       ,  6.2000003 ,  6.3       ,  6.4       ],
       [ 6.5       ,  6.6       ,  6.7000003 ,  6.8       ,  6.9       ]],

      [[ 7.        ,  7.1000004 ,  7.2       ,  7.3       ,  7.4000006 ],
       [ 7.5       ,  7.6000004 ,  7.7       ,  7.8       ,  7.9000006 ],
       [ 8.        ,  8.1       ,  8.2       ,  8.3       ,  8.400001  ],
       [ 8.5       ,  8.6       ,  8.7       ,  8.8       ,  8.900001  ]],

      [[ 9.        ,  9.1       ,  9.2       ,  9.3       ,  9.400001  ],
       [ 9.5       ,  9.6       ,  9.7       ,  9.8       ,  9.900001  ],
       [10.        , 10.1       , 10.2       , 10.3       , 10.400001  ],
       [10.5       , 10.6       , 10.7       , 10.8       , 10.900001  ]]]]
  s: shape=(3,), dtype=float32
    [0.5, 1. , 1.5]
  bias: shape=(3,), dtype=float32
    [-0.25,  0.25,  0.75]

Outputs:
  y: shape=(2, 3, 4, 5), dtype=float32
    [[[[-1.0616398 , -0.976204  , -0.89076823, -0.8053325 , -0.71989673],
       [-0.6344609 , -0.5490252 , -0.46358943, -0.37815365, -0.29271787],
       [-0.20728213, -0.12184635, -0.03641056,  0.04902524,  0.13446093],
       [ 0.21989673,  0.30533248,  0.3907683 ,  0.4762041 ,  0.5616398 ]],

      [[-1.3732797 , -1.2024078 , -1.0315365 , -0.8606651 , -0.68979335],
       [-0.518922  , -0.34805018, -0.17717883, -0.00630745,  0.16456431],
       [ 0.3354357 ,  0.5063075 ,  0.67717886,  0.8480502 ,  1.018922  ],
       [ 1.1897933 ,  1.3606651 ,  1.5315365 ,  1.7024078 ,  1.8732797 ]],

      [[-1.6849194 , -1.4286122 , -1.172304  , -0.915997  , -0.65969   ],
       [-0.4033829 , -0.14707589,  0.10923237,  0.36553943,  0.6218465 ],
       [ 0.8781535 ,  1.1344606 ,  1.3907688 ,  1.6470759 ,  1.9033829 ],
       [ 2.15969   ,  2.415997  ,  2.6723053 ,  2.9286122 ,  3.1849194 ]]],


     [[[-1.06164   , -0.97620434, -0.89076823, -0.80533254, -0.7198969 ],
       [-0.63446116, -0.54902554, -0.46358943, -0.37815374, -0.29271805],
       [-0.20728236, -0.12184668, -0.03641059,  0.04902509,  0.13446078],
       [ 0.21989647,  0.30533212,  0.39076823,  0.47620392,  0.5616396 ]],

      [[-1.37328   , -1.2024078 , -1.0315373 , -0.8606651 , -0.68979293],
       [-0.5189224 , -0.34805018, -0.17717963, -0.00630745,  0.16456473],
       [ 0.33543527,  0.5063075 ,  0.677178  ,  0.8480502 ,  1.0189223 ],
       [ 1.1897929 ,  1.3606651 ,  1.5315356 ,  1.7024078 ,  1.87328   ]],

      [[-1.6849189 , -1.4286106 , -1.1723046 , -0.91599643, -0.6596881 ],
       [-0.4033823 , -0.14707404,  0.10923177,  0.36554003,  0.62184834],
       [ 0.87815416,  1.1344624 ,  1.3907683 ,  1.6470765 ,  1.9033848 ],
       [ 2.1596906 ,  2.415999  ,  2.6723046 ,  2.928613  ,  3.1849213 ]]]]

test_cc_instancenorm_example

Node:
  InstanceNormalization(x, s, bias) -> (y)
Inputs:
  x: shape=(1, 2, 1, 3), dtype=float32
    [[[[-1.,  0.,  1.]],

      [[ 2.,  3.,  4.]]]]
  s: shape=(2,), dtype=float32
    [1. , 1.5]
  bias: shape=(2,), dtype=float32
    [0., 1.]

Outputs:
  y: shape=(1, 2, 1, 3), dtype=float32
    [[[[-1.2247356 ,  0.        ,  1.2247356 ]],

      [[-0.83710337,  1.        ,  2.8371034 ]]]]

test_cc_instancenorm_float16_large_values

Node:
  InstanceNormalization(x, s, bias) -> (y)
Inputs:
  x: shape=(1, 1, 256), dtype=float16
    [[[  0.,   2.,   4., ..., 506., 508., 510.]]]
  s: shape=(1,), dtype=float16
    [1.]
  bias: shape=(1,), dtype=float16
    [0.]

Outputs:
  y: shape=(1, 1, 256), dtype=float16
    [[[-1.726, -1.712, -1.698, ...,  1.698,  1.712,  1.726]]]

Differences with previous version (6)#

SchemaDiff: InstanceNormalization (domain 'ai.onnx')

  • old version: 6

  • new version: 22

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]

Version History#