28 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
33 const std::vector<float>& inputValues,
34 const std::vector<float>& expectedOutputValues,
45 armnn::TensorInfo tensorInfo({ inputOutputTensorShape[dataLayoutIndexed.GetChannelsIndex()] },
49 if (armnn::IsQuantizedType<T>())
52 inputTensorInfo.SetQuantizationOffset(qOffset);
53 outputTensorInfo.SetQuantizationScale(qScale);
54 outputTensorInfo.SetQuantizationOffset(qOffset);
55 tensorInfo.SetQuantizationScale(qScale);
56 tensorInfo.SetQuantizationOffset(qOffset);
59 auto inputTensor = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(inputValues, qScale, qOffset));
62 auto mean = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, -2 }, qScale, qOffset));
63 auto variance = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 4, 9 }, qScale, qOffset));
64 auto beta = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, 2 }, qScale, qOffset));
65 auto gamma = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 2, 1 }, qScale, qOffset));
69 result.outputExpected = MakeTensor<T, 4>(inputTensorInfo,
70 QuantizedVector<T>(expectedOutputValues, qScale, qOffset));
73 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.
CreateTensorHandle(inputTensorInfo);
74 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.
CreateTensorHandle(outputTensorInfo);
83 descriptor.
m_Mean = &meanTensor;
85 descriptor.
m_Beta = &betaTensor;
86 descriptor.
m_Gamma = &gammaTensor;
96 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
97 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
101 inputHandle->Allocate();
102 outputHandle->Allocate();
113 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
122 const unsigned int width = 2;
123 const unsigned int height = 3;
124 const unsigned int channels = 2;
125 const unsigned int num = 1;
132 if(armnn::IsQuantizedType<T>())
135 inputTensorInfo.SetQuantizationOffset(qOffset);
136 outputTensorInfo.SetQuantizationScale(qScale);
137 outputTensorInfo.SetQuantizationOffset(qOffset);
138 tensorInfo.SetQuantizationScale(qScale);
139 tensorInfo.SetQuantizationOffset(qOffset);
142 auto input = MakeTensor<T, 4>(inputTensorInfo,
151 auto mean = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, -2 }, qScale, qOffset));
152 auto variance = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 4, 9 }, qScale, qOffset));
153 auto beta = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, 2 }, qScale, qOffset));
154 auto gamma = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 2, 1 }, qScale, qOffset));
158 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.
CreateTensorHandle(inputTensorInfo);
159 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.
CreateTensorHandle(outputTensorInfo);
174 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
175 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
176 data.m_Mean = &meanTensor;
177 data.m_Variance = &varianceTensor;
178 data.m_Beta = &betaTensor;
179 data.m_Gamma = &gammaTensor;
180 data.m_Parameters.m_Eps = 0.0f;
186 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo,
197 inputHandle->Allocate();
198 outputHandle->Allocate();
221 std::vector<float> inputValues
233 std::vector<float> expectedOutputValues
246 return BatchNormTestImpl<armnn::DataType::Float32>(
251 expectedOutputValues,
267 std::vector<float> inputValues
281 std::vector<float> expectedOutputValues
296 return BatchNormTestImpl<armnn::DataType::Float32>(
301 expectedOutputValues,
317 std::vector<float> inputValues
329 std::vector<float> expectedOutputValues
342 return BatchNormTestImpl<armnn::DataType::Float16>(
347 expectedOutputValues,
363 std::vector<float> inputValues
377 std::vector<float> expectedOutputValues
392 return BatchNormTestImpl<armnn::DataType::Float16>(
397 expectedOutputValues,
413 std::vector<float> inputValues
425 std::vector<float> expectedOutputValues
438 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
443 expectedOutputValues,
459 std::vector<float> inputValues
473 std::vector<float> expectedOutputValues
488 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
491 inputOutputShape, inputValues, expectedOutputValues,
505 std::vector<float> inputValues
517 std::vector<float> expectedOutputValues
530 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
535 expectedOutputValues,
551 std::vector<float> inputValues
565 std::vector<float> expectedOutputValues
580 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
585 expectedOutputValues,
597 const unsigned int width = 2;
598 const unsigned int height = 3;
599 const unsigned int channels = 5;
600 const unsigned int batchSize = 3;
606 constexpr
unsigned int shape[] = {batchSize, channels, height, width};
607 constexpr
unsigned int tensorShape[] = {channels};
613 auto input = MakeRandomTensor<float, 4>(inputTensorInfo, 21312);
615 auto mean = MakeRandomTensor<float, 1>(tensorInfo, 123);
616 auto variance = MakeRandomTensor<float, 1>(tensorInfo, 234, 0.0f);
617 auto beta = MakeRandomTensor<float, 1>(tensorInfo, 123);
618 auto gamma = MakeRandomTensor<float, 1>(tensorInfo, 345);
623 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.
CreateTensorHandle(inputTensorInfo);
624 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.
CreateTensorHandle(outputTensorInfo);
626 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refWorkloadFactory.
CreateTensorHandle(inputTensorInfo);
627 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.
CreateTensorHandle(outputTensorInfo);
642 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
643 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
644 data.m_Mean = &meanTensor;
645 data.m_Variance = &varianceTensor;
646 data.m_Beta = &betaTensor;
647 data.m_Gamma = &gammaTensor;
648 data.m_Parameters.m_Eps = 0.01f;
652 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
653 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
658 inputHandle->Allocate();
659 outputHandle->Allocate();
660 inputHandleRef->Allocate();
661 outputHandleRef->Allocate();
666 workload->PostAllocationConfigure();
668 workloadRef->PostAllocationConfigure();
669 workloadRef->Execute();
virtual std::unique_ptr< IWorkload > CreateBatchNormalization(const BatchNormalizationQueueDescriptor &descriptor, const WorkloadInfo &info) const
const ConstCpuTensorHandle * m_Gamma
const ConstCpuTensorHandle * m_Beta
LayerTestResult< int16_t, 4 > BatchNormInt16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
const ConstCpuTensorHandle * m_Mean
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const ConstCpuTensorHandle * m_Variance
void IgnoreUnused(Ts &&...)
LayerTestResult< uint8_t, 4 > BatchNormUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerDescriptor m_Parameters
LayerTestResult< uint8_t, 4 > BatchNormUint8NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
#define ARMNN_NO_DEPRECATE_WARN_END
LayerTestResult< float, 4 > BatchNormFloat32NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
LayerTestResult< armnn::Half, 4 > BatchNormFloat16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< int16_t, 4 > BatchNormInt16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
void SetQuantizationScale(float scale)
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
LayerTestResult< float, 4 > CompareBatchNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory)
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< float, 4 > BatchNormFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)