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_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.8907683 , -0.8053325 , -0.71989673],
       [-0.6344609 , -0.5490252 , -0.46358943, -0.37815365, -0.29271787],
       [-0.20728213, -0.12184634, -0.03641056,  0.04902524,  0.13446093],
       [ 0.2198967 ,  0.30533248,  0.3907683 ,  0.47620404,  0.5616397 ]],

      [[-1.3732797 , -1.202408  , -1.0315366 , -0.8606651 , -0.68979335],
       [-0.5189221 , -0.34805036, -0.17717886, -0.0063076 ,  0.16456437],
       [ 0.33543563,  0.50630736,  0.67717886,  0.8480501 ,  1.0189219 ],
       [ 1.1897931 ,  1.3606648 ,  1.5315366 ,  1.7024078 ,  1.8732796 ]],

      [[-1.6849194 , -1.4286122 , -1.1723042 , -0.91599655, -0.6596899 ],
       [-0.4033823 , -0.14707565,  0.1092329 ,  0.36553955,  0.62184715],
       [ 0.8781538 ,  1.1344604 ,  1.390769  ,  1.6470766 ,  1.9033833 ],
       [ 2.15969   ,  2.4159975 ,  2.672305  ,  2.9286127 ,  3.1849194 ]]],


     [[[-1.0616403 , -0.9762044 , -0.8907685 , -0.80533266, -0.7198968 ],
       [-0.6344614 , -0.54902554, -0.46358967, -0.3781538 , -0.29271793],
       [-0.20728254, -0.12184668, -0.03641081,  0.04902506,  0.13446093],
       [ 0.21989632,  0.30533218,  0.39076805,  0.47620392,  0.5616398 ]],

      [[-1.3732805 , -1.2024078 , -1.031538  , -0.8606653 , -0.6897936 ],
       [-0.5189228 , -0.34805012, -0.17718029, -0.0063076 ,  0.16456413],
       [ 0.3354349 ,  0.50630665,  0.6771774 ,  0.8480501 ,  1.0189219 ],
       [ 1.1897926 ,  1.3606644 ,  1.5315351 ,  1.7024078 ,  1.8732796 ]],

      [[-1.6849194 , -1.4286098 , -1.1723042 , -0.91599655, -0.65968895],
       [-0.40338135, -0.14707375,  0.10923195,  0.36553955,  0.62184906],
       [ 0.87815475,  1.1344624 ,  1.390768  ,  1.6470776 ,  1.9033852 ],
       [ 2.1596909 ,  2.4159985 ,  2.6723042 ,  2.9286137 ,  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 ]]]]

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#