LRN#

  • Domain: ai.onnx

  • Since version: 13

Local Response Normalization proposed in the AlexNet paper. It normalizes over local input regions. The local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor of shape (N x C x D1 x D2, ..., Dk), its region is {X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}.

square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2), where max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)).

Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta

Inputs

  • X (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. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].

Outputs

  • Y (T): Output tensor, which has the shape and type as input tensor

Attributes

  • alpha (float): Scaling parameter.

  • beta (float): The exponent.

  • bias (float)

  • size (int): The number of channels to sum over

Type Constraints

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

Examples#

test_cc_lrn

Node:
  LRN(x) -> (y)
  Attributes:
    alpha = 0.00019999999494757503
    beta = 0.5
    bias = 2.0
    size = 3
Inputs:
  x: shape=(2, 4, 5, 5), dtype=float32
    [[[[-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ],
       [ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ],
       [ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ]],

      [[ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334],
       [ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667],
       [ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ]],

      [[ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667],
       [ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ]],

      [[ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ],
       [ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ],
       [ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334]]],


     [[[ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667],
       [ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ],
       [ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667]],

      [[ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ],
       [ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ]],

      [[ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ],
       [ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334],
       [ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667]],

      [[ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ],
       [ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667],
       [ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334]]]]

Outputs:
  y: shape=(2, 4, 5, 5), dtype=float32
    [[[[-0.7070832 , -0.589239  , -0.47139558, -0.3535493 , -0.23570085],
       [-0.11785086,  0.        ,  0.11785108,  0.23570172,  0.35355127],
       [ 0.47139907,  0.5892444 ,  0.7070868 , -0.7070832 , -0.589239  ],
       [-0.47139558, -0.3535493 , -0.23570085, -0.11785086,  0.        ],
       [ 0.11785108,  0.23570172,  0.35355127,  0.47139907,  0.5892444 ]],

      [[ 0.707075  , -0.707075  , -0.58923465, -0.47139362, -0.35354865],
       [-0.23570074, -0.11785086,  0.        ,  0.11785086,  0.23570074],
       [ 0.35354865,  0.47139362,  0.58923465,  0.707075  , -0.707075  ],
       [-0.58923465, -0.47139362, -0.35354865, -0.23570074, -0.11785086],
       [ 0.        ,  0.11785086,  0.23570074,  0.35354865,  0.47139362]],

      [[ 0.58923465,  0.707075  , -0.707075  , -0.58923465, -0.47139362],
       [-0.35354865, -0.23570074, -0.11785086,  0.        ,  0.11785086],
       [ 0.23570074,  0.35354865,  0.47139362,  0.58923465,  0.707075  ],
       [-0.707075  , -0.58923465, -0.47139362, -0.35354865, -0.23570074],
       [-0.11785086,  0.        ,  0.11785086,  0.23570074,  0.35354865]],

      [[ 0.47139558,  0.589239  ,  0.7070832 , -0.7070868 , -0.5892444 ],
       [-0.47139907, -0.35355127, -0.23570172, -0.11785108,  0.        ],
       [ 0.11785086,  0.23570085,  0.3535493 ,  0.47139558,  0.589239  ],
       [ 0.7070832 , -0.7070868 , -0.5892444 , -0.47139907, -0.35355127],
       [-0.23570172, -0.11785108,  0.        ,  0.11785086,  0.23570085]]],


     [[[ 0.35355127,  0.47139907,  0.5892444 ,  0.7070868 , -0.7070832 ],
       [-0.589239  , -0.47139558, -0.3535493 , -0.23570085, -0.11785086],
       [ 0.        ,  0.11785108,  0.23570172,  0.35355127,  0.47139907],
       [ 0.5892444 ,  0.7070868 , -0.7070832 , -0.589239  , -0.47139558],
       [-0.3535493 , -0.23570085, -0.11785086,  0.        ,  0.11785108]],

      [[ 0.23570074,  0.35354865,  0.47139362,  0.58923465,  0.707075  ],
       [-0.707075  , -0.58923465, -0.47139362, -0.35354865, -0.23570074],
       [-0.11785086,  0.        ,  0.11785086,  0.23570074,  0.35354865],
       [ 0.47139362,  0.58923465,  0.707075  , -0.707075  , -0.58923465],
       [-0.47139362, -0.35354865, -0.23570074, -0.11785086,  0.        ]],

      [[ 0.11785086,  0.23570074,  0.35354865,  0.47139362,  0.58923465],
       [ 0.707075  , -0.707075  , -0.58923465, -0.47139362, -0.35354865],
       [-0.23570074, -0.11785086,  0.        ,  0.11785086,  0.23570074],
       [ 0.35354865,  0.47139362,  0.58923465,  0.707075  , -0.707075  ],
       [-0.58923465, -0.47139362, -0.35354865, -0.23570074, -0.11785086]],

      [[ 0.        ,  0.11785086,  0.23570085,  0.3535493 ,  0.47139558],
       [ 0.589239  ,  0.7070832 , -0.7070868 , -0.5892444 , -0.47139907],
       [-0.35355127, -0.23570172, -0.11785108,  0.        ,  0.11785086],
       [ 0.23570085,  0.3535493 ,  0.47139558,  0.589239  ,  0.7070832 ],
       [-0.7070868 , -0.5892444 , -0.47139907, -0.35355127, -0.23570172]]]]

test_cc_lrn_default

Node:
  LRN(x) -> (y)
  Attributes:
    size = 3
Inputs:
  x: shape=(2, 4, 5, 5), dtype=float32
    [[[[-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ],
       [ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ],
       [ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ]],

      [[ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334],
       [ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667],
       [ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ]],

      [[ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667],
       [ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ]],

      [[ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ],
       [ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ],
       [ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334]]],


     [[[ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667],
       [ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ],
       [ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667]],

      [[ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334],
       [-0.16666667,  0.        ,  0.16666667,  0.33333334,  0.5       ],
       [ 0.6666667 ,  0.8333333 ,  1.        , -1.        , -0.8333333 ],
       [-0.6666667 , -0.5       , -0.33333334, -0.16666667,  0.        ]],

      [[ 0.16666667,  0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ],
       [ 1.        , -1.        , -0.8333333 , -0.6666667 , -0.5       ],
       [-0.33333334, -0.16666667,  0.        ,  0.16666667,  0.33333334],
       [ 0.5       ,  0.6666667 ,  0.8333333 ,  1.        , -1.        ],
       [-0.8333333 , -0.6666667 , -0.5       , -0.33333334, -0.16666667]],

      [[ 0.        ,  0.16666667,  0.33333334,  0.5       ,  0.6666667 ],
       [ 0.8333333 ,  1.        , -1.        , -0.8333333 , -0.6666667 ],
       [-0.5       , -0.33333334, -0.16666667,  0.        ,  0.16666667],
       [ 0.33333334,  0.5       ,  0.6666667 ,  0.8333333 ,  1.        ],
       [-1.        , -0.8333333 , -0.6666667 , -0.5       , -0.33333334]]]]

Outputs:
  y: shape=(2, 4, 5, 5), dtype=float32
    [[[[-0.99995   , -0.833298  , -0.66664773, -0.49999133, -0.33333033],
       [-0.16666609,  0.        ,  0.16666655,  0.33333218,  0.4999955 ],
       [ 0.6666551 ,  0.8333096 ,  0.9999576 , -0.99995   , -0.833298  ],
       [-0.66664773, -0.49999133, -0.33333033, -0.16666609,  0.        ],
       [ 0.16666655,  0.33333218,  0.4999955 ,  0.6666551 ,  0.8333096 ]],

      [[ 0.99993265, -0.99993265, -0.8332887 , -0.66664356, -0.49998993],
       [-0.3333301 , -0.16666609,  0.        ,  0.16666609,  0.3333301 ],
       [ 0.49998993,  0.66664356,  0.8332887 ,  0.99993265, -0.99993265],
       [-0.8332887 , -0.66664356, -0.49998993, -0.3333301 , -0.16666609],
       [ 0.        ,  0.16666609,  0.3333301 ,  0.49998993,  0.66664356]],

      [[ 0.8332887 ,  0.99993265, -0.99993265, -0.8332887 , -0.66664356],
       [-0.49998993, -0.3333301 , -0.16666609,  0.        ,  0.16666609],
       [ 0.3333301 ,  0.49998993,  0.66664356,  0.8332887 ,  0.99993265],
       [-0.99993265, -0.8332887 , -0.66664356, -0.49998993, -0.3333301 ],
       [-0.16666609,  0.        ,  0.16666609,  0.3333301 ,  0.49998993]],

      [[ 0.66664773,  0.833298  ,  0.99995   , -0.9999576 , -0.8333096 ],
       [-0.6666551 , -0.4999955 , -0.33333218, -0.16666655,  0.        ],
       [ 0.16666609,  0.33333033,  0.49999133,  0.66664773,  0.833298  ],
       [ 0.99995   , -0.9999576 , -0.8333096 , -0.6666551 , -0.4999955 ],
       [-0.33333218, -0.16666655,  0.        ,  0.16666609,  0.33333033]]],


     [[[ 0.4999955 ,  0.6666551 ,  0.8333096 ,  0.9999576 , -0.99995   ],
       [-0.833298  , -0.66664773, -0.49999133, -0.33333033, -0.16666609],
       [ 0.        ,  0.16666655,  0.33333218,  0.4999955 ,  0.6666551 ],
       [ 0.8333096 ,  0.9999576 , -0.99995   , -0.833298  , -0.66664773],
       [-0.49999133, -0.33333033, -0.16666609,  0.        ,  0.16666655]],

      [[ 0.3333301 ,  0.49998993,  0.66664356,  0.8332887 ,  0.99993265],
       [-0.99993265, -0.8332887 , -0.66664356, -0.49998993, -0.3333301 ],
       [-0.16666609,  0.        ,  0.16666609,  0.3333301 ,  0.49998993],
       [ 0.66664356,  0.8332887 ,  0.99993265, -0.99993265, -0.8332887 ],
       [-0.66664356, -0.49998993, -0.3333301 , -0.16666609,  0.        ]],

      [[ 0.16666609,  0.3333301 ,  0.49998993,  0.66664356,  0.8332887 ],
       [ 0.99993265, -0.99993265, -0.8332887 , -0.66664356, -0.49998993],
       [-0.3333301 , -0.16666609,  0.        ,  0.16666609,  0.3333301 ],
       [ 0.49998993,  0.66664356,  0.8332887 ,  0.99993265, -0.99993265],
       [-0.8332887 , -0.66664356, -0.49998993, -0.3333301 , -0.16666609]],

      [[ 0.        ,  0.16666609,  0.33333033,  0.49999133,  0.66664773],
       [ 0.833298  ,  0.99995   , -0.9999576 , -0.8333096 , -0.6666551 ],
       [-0.4999955 , -0.33333218, -0.16666655,  0.        ,  0.16666609],
       [ 0.33333033,  0.49999133,  0.66664773,  0.833298  ,  0.99995   ],
       [-0.9999576 , -0.8333096 , -0.6666551 , -0.4999955 , -0.33333218]]]]

Differences with previous version (1)#

SchemaDiff: LRN (domain 'ai.onnx')

  • old version: 1

  • new version: 13

  • breaking: no

Type constraints:

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

Documentation:

  • line similarity: 0.45 (+6/-6 lines)

--- LRN v1
+++ LRN v13
@@ -1,11 +1,11 @@

 Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf).
 It normalizes over local input regions.
-The local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor
-of shape (N x C x D1 x D2, ..., Dk), its region is
-{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}.
+The local region is defined across the channels. For an element `X[n, c, d1, ..., dk]` in a tensor
+of shape `(N x C x D1 x D2, ..., Dk)`, its region is
+`{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}`.

-square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2),
-where max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)).
+`square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2)`,
+where `max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))`.

-Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta
+`Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta`

Version History#