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 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(inputValues, qScale, qOffset));
64 auto mean = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, -2 }, qScale, qOffset));
65 auto variance = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 4, 9 }, qScale, qOffset));
66 auto beta = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, 2 }, qScale, qOffset));
67 auto gamma = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 2, 1 }, qScale, qOffset));
71 result.outputExpected = MakeTensor<T, 4>(inputTensorInfo,
72 QuantizedVector<T>(expectedOutputValues, qScale, qOffset));
74 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
75 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
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>>
123 const unsigned int width = 2;
124 const unsigned int height = 3;
125 const unsigned int channels = 2;
126 const unsigned int num = 1;
133 if(armnn::IsQuantizedType<T>())
136 inputTensorInfo.SetQuantizationOffset(qOffset);
137 outputTensorInfo.SetQuantizationScale(qScale);
138 outputTensorInfo.SetQuantizationOffset(qOffset);
139 tensorInfo.SetQuantizationScale(qScale);
140 tensorInfo.SetQuantizationOffset(qOffset);
143 auto input = MakeTensor<T, 4>(inputTensorInfo,
152 auto mean = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, -2 }, qScale, qOffset));
153 auto variance = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 4, 9 }, qScale, qOffset));
154 auto beta = MakeTensor<T, 1>(tensorInfo, QuantizedVector<T>({ 3, 2 }, qScale, qOffset));
155 auto gamma = MakeTensor<T, 1>(tensorInfo, 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;
185 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo,
196 inputHandle->Allocate();
197 outputHandle->Allocate();
221 std::vector<float> inputValues
233 std::vector<float> expectedOutputValues
246 return BatchNormTestImpl<armnn::DataType::Float32>(
252 expectedOutputValues,
269 std::vector<float> inputValues
283 std::vector<float> expectedOutputValues
298 return BatchNormTestImpl<armnn::DataType::Float32>(
304 expectedOutputValues,
321 std::vector<float> inputValues
333 std::vector<float> expectedOutputValues
346 return BatchNormTestImpl<armnn::DataType::Float16>(
352 expectedOutputValues,
369 std::vector<float> inputValues
383 std::vector<float> expectedOutputValues
398 return BatchNormTestImpl<armnn::DataType::Float16>(
404 expectedOutputValues,
421 std::vector<float> inputValues
433 std::vector<float> expectedOutputValues
446 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
452 expectedOutputValues,
469 std::vector<float> inputValues
483 std::vector<float> expectedOutputValues
498 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
502 inputOutputShape, inputValues, expectedOutputValues,
517 std::vector<float> inputValues
529 std::vector<float> expectedOutputValues
542 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
548 expectedOutputValues,
565 std::vector<float> inputValues
579 std::vector<float> expectedOutputValues
594 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
600 expectedOutputValues,
614 const unsigned int width = 2;
615 const unsigned int height = 3;
616 const unsigned int channels = 5;
617 const unsigned int batchSize = 3;
623 constexpr
unsigned int shape[] = {batchSize, channels, height, width};
624 constexpr
unsigned int tensorShape[] = {channels};
630 auto input = MakeRandomTensor<float, 4>(inputTensorInfo, 21312);
632 auto mean = MakeRandomTensor<float, 1>(tensorInfo, 123);
633 auto variance = MakeRandomTensor<float, 1>(tensorInfo, 234, 0.0f);
634 auto beta = MakeRandomTensor<float, 1>(tensorInfo, 123);
635 auto gamma = MakeRandomTensor<float, 1>(tensorInfo, 345);
639 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
640 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
642 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refTensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
643 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refTensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
657 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
658 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
659 data.
m_Mean = &meanTensor;
661 data.
m_Beta = &betaTensor;
667 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
668 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
673 inputHandle->Allocate();
674 outputHandle->Allocate();
675 inputHandleRef->Allocate();
676 outputHandleRef->Allocate();
681 workload->PostAllocationConfigure();
683 workloadRef->PostAllocationConfigure();
684 workloadRef->Execute();
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)
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 inputs and outputs to a layer.
const ConstTensorHandle * m_Mean
const ConstTensorHandle * m_Beta
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)