29 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
35 const std::vector<float>& inputValues,
36 const std::vector<float>& expectedOutputValues,
47 armnn::TensorInfo tensorInfo({ inputOutputTensorShape[dataLayoutIndexed.GetChannelsIndex()] },
51 if (armnn::IsQuantizedType<T>())
54 inputTensorInfo.SetQuantizationOffset(qOffset);
55 outputTensorInfo.SetQuantizationScale(qScale);
56 outputTensorInfo.SetQuantizationOffset(qOffset);
57 tensorInfo.SetQuantizationScale(qScale);
58 tensorInfo.SetQuantizationOffset(qOffset);
61 auto inputTensor = QuantizedVector<T>(inputValues, qScale, qOffset);
64 auto mean = QuantizedVector<T>({ 3, -2 }, qScale, qOffset);
65 auto variance = QuantizedVector<T>({ 4, 9 }, qScale, qOffset);
66 auto beta = QuantizedVector<T>({ 3, 2 }, qScale, qOffset);
67 auto gamma = QuantizedVector<T>({ 2, 1 }, qScale, qOffset);
69 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
70 std::vector<T> expectedOutput = QuantizedVector<T>(expectedOutputValues, qScale, qOffset);
72 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
73 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
81 descriptor.
m_Mean = &meanTensor;
83 descriptor.
m_Beta = &betaTensor;
84 descriptor.
m_Gamma = &gammaTensor;
94 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
95 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
99 inputHandle->Allocate();
100 outputHandle->Allocate();
110 outputHandle->GetShape(),
111 outputTensorInfo.GetShape());
114 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
124 const unsigned int width = 2;
125 const unsigned int height = 3;
126 const unsigned int channels = 2;
127 const unsigned int num = 1;
134 if(armnn::IsQuantizedType<T>())
137 inputTensorInfo.SetQuantizationOffset(qOffset);
138 outputTensorInfo.SetQuantizationScale(qScale);
139 outputTensorInfo.SetQuantizationOffset(qOffset);
140 tensorInfo.SetQuantizationScale(qScale);
141 tensorInfo.SetQuantizationOffset(qOffset);
144 auto input = QuantizedVector<T>(
153 auto mean = QuantizedVector<T>({ 3, -2 }, qScale, qOffset);
154 auto variance = QuantizedVector<T>({ 4, 9 }, qScale, qOffset);
155 auto beta = QuantizedVector<T>({ 3, 2 }, qScale, qOffset);
156 auto gamma = QuantizedVector<T>({ 2, 1 }, qScale, qOffset);
158 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
159 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
173 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
174 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
175 data.
m_Mean = &meanTensor;
177 data.
m_Beta = &betaTensor;
182 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
187 std::vector<T> expectedOutput = QuantizedVector<T>(
197 inputHandle->Allocate();
198 outputHandle->Allocate();
208 outputHandle->GetShape(),
209 outputTensorInfo.GetShape());
225 std::vector<float> inputValues
237 std::vector<float> expectedOutputValues
250 return BatchNormTestImpl<armnn::DataType::Float32>(
256 expectedOutputValues,
273 std::vector<float> inputValues
287 std::vector<float> expectedOutputValues
302 return BatchNormTestImpl<armnn::DataType::Float32>(
308 expectedOutputValues,
325 std::vector<float> inputValues
337 std::vector<float> expectedOutputValues
350 return BatchNormTestImpl<armnn::DataType::Float16>(
356 expectedOutputValues,
373 std::vector<float> inputValues
387 std::vector<float> expectedOutputValues
402 return BatchNormTestImpl<armnn::DataType::Float16>(
408 expectedOutputValues,
425 std::vector<float> inputValues
437 std::vector<float> expectedOutputValues
450 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
456 expectedOutputValues,
473 std::vector<float> inputValues
487 std::vector<float> expectedOutputValues
502 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
506 inputOutputShape, inputValues, expectedOutputValues,
521 std::vector<float> inputValues
533 std::vector<float> expectedOutputValues
546 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
552 expectedOutputValues,
569 std::vector<float> inputValues
583 std::vector<float> expectedOutputValues
598 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
604 expectedOutputValues,
618 const unsigned int width = 2;
619 const unsigned int height = 3;
620 const unsigned int channels = 5;
621 const unsigned int batchSize = 3;
627 constexpr
unsigned int shape[] = {batchSize, channels, height, width};
628 constexpr
unsigned int tensorShape[] = {channels};
634 auto input = MakeRandomTensor<float>(inputTensorInfo, 21312);
636 auto mean = MakeRandomTensor<float>(tensorInfo, 123);
637 auto variance = MakeRandomTensor<float>(tensorInfo, 234, 0.0f);
638 auto beta = MakeRandomTensor<float>(tensorInfo, 123);
639 auto gamma = MakeRandomTensor<float>(tensorInfo, 345);
641 std::vector<float> actualOutput(outputTensorInfo.
GetNumElements());
642 std::vector<float> expectedOutput(outputTensorInfo.
GetNumElements());
644 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
645 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
647 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refTensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
648 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refTensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
662 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
663 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
664 data.
m_Mean = &meanTensor;
666 data.
m_Beta = &betaTensor;
672 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
673 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
678 inputHandle->Allocate();
679 outputHandle->Allocate();
680 inputHandleRef->Allocate();
681 outputHandleRef->Allocate();
686 workload->PostAllocationConfigure();
688 workloadRef->PostAllocationConfigure();
689 workloadRef->Execute();
696 outputHandle->GetShape(),
virtual std::unique_ptr< IWorkload > CreateBatchNormalization(const BatchNormalizationQueueDescriptor &descriptor, const WorkloadInfo &info) const
LayerTestResult< float, 4 > CompareBatchNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, const armnn::ITensorHandleFactory &tensorHandleFactory, const armnn::ITensorHandleFactory &refTensorHandleFactory)
const TensorShape & GetShape() const
LayerTestResult< uint8_t, 4 > BatchNormUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< uint8_t, 4 > BatchNormUint8NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< int16_t, 4 > BatchNormInt16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
const ConstTensorHandle * m_Variance
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).
void IgnoreUnused(Ts &&...)
LayerDescriptor m_Parameters
LayerTestResult< int16_t, 4 > BatchNormInt16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
LayerTestResult< float, 4 > BatchNormFloat32NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void SetQuantizationScale(float scale)
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< float, 4 > BatchNormFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
const ConstTensorHandle * m_Gamma
LayerTestResult< armnn::Half, 4 > BatchNormFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
Contains information about TensorInfos of a layer.
const ConstTensorHandle * m_Mean
const ConstTensorHandle * m_Beta
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
unsigned int GetNumElements() const
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)