27 unsigned int inputBatches = inputShape[0];
28 unsigned int inputHeight = inputShape[dataLayout.
GetHeightIndex()];
29 unsigned int inputWidth = inputShape[dataLayout.
GetWidthIndex()];
36 for (
unsigned int n = 0; n < inputBatches; ++n)
38 for (
unsigned int c = 0; c < inputChannels; ++c)
40 float mean = 0, var = 0;
43 for (
unsigned int h = 0; h < inputHeight; h++)
45 for (
unsigned int w = 0; w < inputWidth; w++)
47 unsigned int index = dataLayout.
GetIndex(inputShape, n, c, h, w);
50 float value = inputDecoder.
Get();
54 mean /=
static_cast<float>(inputHeight * inputWidth);
57 for (
unsigned int h = 0; h < inputHeight; h++)
59 for (
unsigned int w = 0; w < inputWidth; w++)
61 unsigned int index = dataLayout.
GetIndex(inputShape, n, c, h, w);
64 float value = inputDecoder.
Get();
65 var += (value - mean) * (value - mean);
68 var /=
static_cast<float>(inputHeight * inputWidth);
71 for (
unsigned int h = 0; h < inputHeight; ++h)
73 for (
unsigned int w = 0; w < inputWidth; ++w)
75 unsigned int index = dataLayout.
GetIndex(inputShape, n, c, h, w);
78 outputEncoder.
Set((inputDecoder.
Get() - mean) * gamma / std::sqrt ( var + eps) + beta);
virtual IType Get() const =0
virtual void Set(IType right)=0
const TensorShape & GetShape() const
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
unsigned int GetIndex(const armnn::TensorShape &shape, unsigned int batchIndex, unsigned int channelIndex, unsigned int heightIndex, unsigned int widthIndex) const
unsigned int GetWidthIndex() const
unsigned int GetHeightIndex() const
unsigned int GetChannelsIndex() const
Copyright (c) 2021 ARM Limited and Contributors.
void InstanceNorm(const InstanceNormalizationQueueDescriptor &data, const TensorInfo &inputInfo, Decoder< float > &inputDecoder, Encoder< float > &outputEncoder)
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f.
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_Beta
Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0.
LayerDescriptor m_Parameters