6 #include "../Graph.hpp" 7 #include "../Network.hpp" 8 #include "../NetworkQuantizerUtils.hpp" 9 #include "../OverrideInputRangeVisitor.hpp" 10 #include "../RangeTracker.hpp" 11 #include "../../armnnQuantizer/CommandLineProcessor.hpp" 22 #include <boost/test/unit_test.hpp> 24 #include <unordered_map> 46 , m_InputShape(inputShape)
47 , m_OutputShape(outputShape)
52 , m_InputShape(inputShape)
53 , m_OutputShape(outputShape)
54 , m_QuantizerOptions(options) {}
58 const char* name =
nullptr)
override 62 BOOST_TEST(m_InputShape == info.
GetShape());
72 const char* name =
nullptr)
override 76 BOOST_TEST(m_OutputShape == info.
GetShape());
86 switch (m_QuantizerOptions.m_ActivationFormat)
89 TestQuantizationParamsImpl(
93 TestQuantizationParamsImpl(
97 TestQuantizationParamsImpl(
101 TestQuantizationParamsImpl(
114 void TestConstantQuantizationParams(
const TensorInfo& info,
119 TestQuantizationParamsImpl(info, dataType, params.first, params.second);
122 void TestBiasQuantizationParams(
const TensorInfo& info,
129 switch (m_QuantizerOptions.m_ActivationFormat)
132 TestQuantizationParamsImpl(info, dataType, qAsymmU8Params.first, qAsymmU8Params.second);
135 TestQuantizationParamsImpl(info, dataType, qAsymmS8Params.first, qAsymmS8Params.second);
138 TestQuantizationParamsImpl(info, dataType, qSymmS8Params.first, qSymmS8Params.second);
141 TestQuantizationParamsImpl(info, dataType, qSymmS16Params.first, qSymmS16Params.second);
160 TestQuantizationParams(info, {inputScaleQAsymmU8, 128},
161 {inputScaleQAsymmS8, 0},
162 {inputScaleQSymmS8, 0},
163 {inputScaleQSymmS16, 0});
165 TestConstantQuantizationParams(weights.
GetInfo(), {weightsScale, 85});
169 TestBiasQuantizationParams(biases.
value().GetInfo(),
170 {inputScaleQAsymmU8 * weightsScale, 0},
171 {inputScaleQAsymmS8 * weightsScale, 0},
172 {inputScaleQSymmS8 * weightsScale, 0},
173 {inputScaleQSymmS16 * weightsScale, 0},
182 void TestQuantizationParamsImpl(
const TensorInfo& info,
DataType dataType,
float scale, int32_t offset)
194 auto network = PolymorphicDowncast<const Network*>(inputNetwork);
195 auto graph = network->GetGraph().TopologicalSort();
200 class TestAdditionQuantization :
public TestQuantization
204 : TestQuantization(inputShape, outputShape) {}
209 : TestQuantization(options, inputShape, outputShape) {}
212 const char* name =
nullptr)
override 250 TestAdditionQuantization validatorQAsymmU8(shape, shape);
255 TestAdditionQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
260 TestAdditionQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
265 TestAdditionQuantization validatorQSymmS16(qSymmS16options, shape, shape);
269 class TestActivationQuantization :
public TestQuantization
273 : TestQuantization(inputShape, outputShape) {}
278 : TestQuantization(options, inputShape, outputShape) {}
282 const char* name =
nullptr)
override 340 ARMNN_ASSERT_MSG(inputLayer->GetNumOutputSlots() == 1,
"Input layer should have exactly 1 output slot");
341 return inputLayer->GetOutputSlot(0).GetTensorInfo();
353 std::vector<float> inputData({0, 0, 0, -56, 98, 0, 0, 0});
357 inputTensors.push_back(std::make_pair(0, inputTensor));
361 quantizer->Refine(inputTensors);
364 std::vector<float> inputData2({0, -77, 0, -56, 65, 0, 0, 0});
367 inputTensors2.push_back(std::make_pair(0, inputTensor2));
369 quantizer->Refine(inputTensors2);
371 INetworkPtr quantizedNetwork = quantizer->ExportNetwork();
374 std::unique_ptr<IQuantizationScheme> quantizationScheme = std::make_unique<QAsymmU8QuantizationScheme>();
375 OffsetScalePair qParams = quantizationScheme->ComputeScheme(-77.0, 98.0);
381 m_OffsetScalePair(offsetScalePair), m_DataType(dataType) {}
385 const char* name =
nullptr)
override 389 BOOST_CHECK_MESSAGE(info.
GetDataType() == m_DataType,
395 BOOST_TEST(info.
GetQuantizationScale() == m_OffsetScalePair.first, boost::test_tools::tolerance(0.001));
404 quantizedNetwork->Accept(visitor);
411 descriptor.
m_A = 3.5f;
412 descriptor.
m_B = -10.0f;
419 TestActivationQuantization validatorQAsymmU8(shape, shape);
424 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
429 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
434 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
442 descriptor.
m_A = 3.5f;
443 descriptor.
m_B = -10.0f;
449 TestActivationQuantization validatorQAsymmU8(shape, shape);
454 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
459 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
464 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
472 descriptor.
m_A = 3.5f;
473 descriptor.
m_B = -10.0f;
479 TestActivationQuantization validatorQAsymmU8(shape, shape);
484 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
489 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
494 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
502 descriptor.
m_A = 3.5f;
503 descriptor.
m_B = -10.0f;
509 TestActivationQuantization validatorQAsymmU8(shape, shape);
514 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
519 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
524 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
530 class TestBoundedReluActivationQuantization :
public TestQuantization
534 : TestQuantization(inputShape, outputShape) {}
539 : TestQuantization(options, inputShape, outputShape) {}
543 const char* name =
nullptr)
override 558 descriptor.
m_A = 3.5f;
559 descriptor.
m_B = -10.0f;
565 TestBoundedReluActivationQuantization validatorQAsymmU8(shape, shape);
570 TestBoundedReluActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
575 TestBoundedReluActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
580 TestBoundedReluActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
586 class TestTanHActivationQuantization :
public TestQuantization
590 : TestQuantization(inputShape, outputShape) {}
595 : TestQuantization(options, inputShape, outputShape) {}
599 const char* name =
nullptr)
override 605 TestQuantizationParams(
615 descriptor.
m_A = 3.5f;
616 descriptor.
m_B = -10.0f;
622 TestTanHActivationQuantization validatorQAsymmU8(shape, shape);
627 TestTanHActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
632 TestTanHActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
637 TestTanHActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
641 class TestLeakyReLuActivationQuantization :
public TestQuantization
645 : TestQuantization(inputShape, outputShape) {}
650 : TestQuantization(options, inputShape, outputShape) {}
654 const char* name =
nullptr)
override 683 descriptor.
m_A = 3.5f;
684 descriptor.
m_B = -10.0f;
690 TestLeakyReLuActivationQuantization validatorQAsymmU8(shape, shape);
695 TestLeakyReLuActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
700 TestLeakyReLuActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
705 TestLeakyReLuActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
712 class TestEluActivationQuantization :
public TestQuantization
716 : TestQuantization(inputShape, outputShape) {}
721 : TestQuantization(options, inputShape, outputShape) {}
725 const char* name =
nullptr)
override 731 TestQuantizationParams(
746 TestEluActivationQuantization validatorQAsymmU8(shape, shape);
751 TestEluActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
756 TestEluActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
761 TestEluActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
766 class TestHardSwishActivationQuantization :
public TestQuantization
770 : TestQuantization(inputShape, outputShape) {}
775 : TestQuantization(options, inputShape, outputShape) {}
779 const char* name =
nullptr)
override 785 TestQuantizationParams(
800 TestHardSwishActivationQuantization validatorQAsymmU8(shape, shape);
805 TestHardSwishActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
810 TestHardSwishActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
815 TestHardSwishActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
822 class TestBatchNormalizationQuantization :
public TestQuantization
826 : TestQuantization(inputShape, outputShape) {}
831 : TestQuantization(options, inputShape, outputShape) {}
839 const char* name =
nullptr)
override 845 TestQuantizationParams(
864 std::vector<float> meanData{-1.0f, 1.5f, 2.0f};
865 std::vector<float> varData{-1.0f, 1.5f, 2.0f};
866 std::vector<float> betaData{-1.0f, 1.5f, 2.0f};
867 std::vector<float> gammaData{-1.0f, 1.5f, 2.0f};
878 IConnectableLayer* batchNorm = network->AddBatchNormalizationLayer(desc, mean, var, beta, gamma);
890 TestBatchNormalizationQuantization validatorQAsymmU8(shape, shape);
895 TestBatchNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
900 TestBatchNormalizationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
905 TestBatchNormalizationQuantization validatorQSymmS16(QQsymm16Options, shape, shape);
911 class TestDepthToSpaceQuantization :
public TestQuantization
915 : TestQuantization(inputShape, outputShape) {}
920 : TestQuantization(options, inputShape, outputShape) {}
924 const char* name =
nullptr)
934 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
948 IConnectableLayer* depthToSpaceLayer = network->AddDepthToSpaceLayer(descriptor);
959 TestDepthToSpaceQuantization validatorQAsymmU8(inputShape, outputShape);
965 TestDepthToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
971 TestDepthToSpaceQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
977 TestDepthToSpaceQuantization validatorQSymmS16(Qsymm16Options, inputShape, outputShape);
990 VisitLayers(inputLayers, overrideInputRangeVisitor);
1005 VisitLayers(inputLayers, overrideInputRangeVisitor);
1039 VisitLayers(inputLayers, overrideInputRangeVisitorLayer3);
1046 VisitLayers(inputLayers, overrideInputRangeVisitorLayer1);
1072 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1079 std::vector<float> biasData{10.0f, 20.0f, 30.0f};
1085 fullyConnected = network->AddFullyConnectedLayer(desc, weights, optionalBias);
1090 fullyConnected->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1094 fullyConnected->GetOutputSlot(0).SetTensorInfo(outputInfo);
1101 class TestFullyConnectedQuantization :
public TestQuantization
1105 : TestQuantization(inputShape, outputShape) {}
1110 : TestQuantization(options, inputShape, outputShape) {}
1116 const char* name =
nullptr)
override 1119 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1127 TestFullyConnectedQuantization validatorQAsymmU8(shape, shape);
1132 TestFullyConnectedQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1137 TestFullyConnectedQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1142 TestFullyConnectedQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1158 class TestConv2dQuantization :
public TestQuantization
1162 : TestQuantization(inputShape, outputShape) {}
1167 : TestQuantization(options, inputShape, outputShape) {}
1173 const char *name =
nullptr)
override 1176 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1185 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1195 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1201 conv2d = network->AddConvolution2dLayer(descriptor, weights, optionalBiases);
1206 conv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1210 conv2d->GetOutputSlot(0).SetTensorInfo(info);
1213 TestConv2dQuantization validatorQAsymmU8(shape, shape);
1218 TestConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1223 TestConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1228 TestConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1244 class TestDepthwiseConv2dQuantization :
public TestQuantization
1248 : TestQuantization(inputShape, outputShape) {}
1253 : TestQuantization(options, inputShape, outputShape) {}
1259 const char *name =
nullptr)
override 1262 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1271 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1281 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1287 depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases);
1292 depthwiseConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1296 depthwiseConv2d->GetOutputSlot(0).SetTensorInfo(info);
1299 TestDepthwiseConv2dQuantization validatorQAsymmU8(shape, shape);
1304 TestDepthwiseConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1309 TestDepthwiseConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1314 TestDepthwiseConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1330 class TestInstanceNormalizationQuantization :
public TestQuantization
1334 : TestQuantization(inputShape, outputShape) {}
1339 : TestQuantization(options, inputShape, outputShape) {}
1343 const char* name =
nullptr)
1353 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1374 TestInstanceNormalizationQuantization validatorQAsymmU8(tensorShape, tensorShape);
1380 TestInstanceNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1386 TestInstanceNormalizationQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1392 TestInstanceNormalizationQuantization validatorQSymmS16(qSymmS16Options, tensorShape, tensorShape);
1398 class TestLogSoftmaxQuantization :
public TestQuantization
1402 : TestQuantization(inputShape, outputShape) {}
1407 : TestQuantization(options, inputShape, outputShape) {}
1411 const char* name =
nullptr)
override 1421 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1431 descriptor.
m_Beta = 1.0f;
1445 TestLogSoftmaxQuantization validatorQAsymmU8(tensorShape, tensorShape);
1451 TestLogSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1457 TestLogSoftmaxQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1463 TestLogSoftmaxQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
1490 class TestSoftmaxQuantization :
public TestQuantization
1494 : TestQuantization(inputShape, outputShape) {}
1499 : TestQuantization(options, inputShape, outputShape) {}
1503 const char* name =
nullptr)
override 1517 descriptor.
m_Beta = 1.0f;
1523 TestSoftmaxQuantization validatorQAsymmU8(shape, shape);
1528 TestSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1534 TestSoftmaxQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1539 TestSoftmaxQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1588 activationDescriptor.
m_A = 3.5f;
1589 activationDescriptor.
m_B = -10.0f;
1623 class TestPermuteQuantization :
public TestLeakyReLuActivationQuantization
1627 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1632 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1636 const char* name =
nullptr)
override 1639 CheckForwardedQuantizationSettings(layer);
1657 TestPermuteQuantization validatorQAsymmU8(shape, shape);
1662 TestPermuteQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1667 TestPermuteQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1672 TestPermuteQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1678 class TestSpaceToBatchQuantization :
public TestLeakyReLuActivationQuantization
1682 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1687 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1691 const char* name =
nullptr)
override 1694 CheckForwardedQuantizationSettings(layer);
1712 TestSpaceToBatchQuantization validatorQAsymmU8(shape, shape);
1717 TestSpaceToBatchQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1722 TestSpaceToBatchQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1727 TestSpaceToBatchQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1733 class TestSpaceToDepthQuantization :
public TestLeakyReLuActivationQuantization
1737 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
1743 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
1748 const char* =
nullptr)
override 1751 TestQuantizationParams(info,
1770 TestSpaceToDepthQuantization validatorQAsymmU8(shape, shape);
1775 TestSpaceToDepthQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1780 TestSpaceToDepthQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1785 TestSpaceToDepthQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1791 class TestPooling2dQuantization :
public TestLeakyReLuActivationQuantization
1795 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1800 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1804 const char* name =
nullptr)
override 1807 CheckForwardedQuantizationSettings(layer);
1819 activationDescriptor.
m_A = 3.5f;
1820 activationDescriptor.
m_B = -10.0f;
1824 IConnectableLayer* activation = network->AddActivationLayer(activationDescriptor);
1839 TestPooling2dQuantization validatorQAsymmU8(shape, shape);
1844 TestPooling2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1849 TestPooling2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1854 TestPooling2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1860 class TestConstantQuantization :
public TestAdditionQuantization
1864 : TestAdditionQuantization(inputShape, outputShape) {}
1869 : TestAdditionQuantization(options, inputShape, outputShape) {}
1873 const char* name =
nullptr)
override 1889 std::vector<float> data = {-2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
1911 TestConstantQuantization validatorQAsymmU8(shape, shape);
1916 TestConstantQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1921 TestConstantQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1926 TestConstantQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1932 class TestArgMinMaxQuantization :
public TestQuantization
1936 TestQuantization(inputShape, outputShape) {}
1941 TestQuantization(options, inputShape, outputShape)
1946 const char* name =
nullptr)
override 1953 const char* name =
nullptr)
override 1959 const char* name =
nullptr)
override 1964 TestQuantizationParams(outputInfo,
1986 IConnectableLayer* argMinMaxLayer = network->AddArgMinMaxLayer(argMinMaxDescriptor);
2000 TestArgMinMaxQuantization validatorQAsymmU8(inputShape, outputShape);
2005 TestArgMinMaxQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
2010 TestArgMinMaxQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
2015 TestArgMinMaxQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
2021 class TestComparisonQuantization :
public TestQuantization
2025 : TestQuantization(inputShape, outputShape) {}
2030 : TestQuantization(options, inputShape, outputShape) {}
2034 const char* name =
nullptr)
override 2044 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
2069 TestComparisonQuantization validatorQAsymmU8(tensorShape, tensorShape);
2075 TestComparisonQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
2081 TestComparisonQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
2087 TestComparisonQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
2093 class TestConcatQuantization :
public TestQuantization
2097 : TestQuantization(inputShape, outputShape) {}
2102 : TestQuantization(options, inputShape, outputShape) {}
2106 const char* name =
nullptr)
override 2112 const char* name =
nullptr)
override 2118 const char* name =
nullptr)
override 2122 TestQuantizationParams(
2132 TestDifferentQuantizationScale(inputInfo0, inputInfo1);
2133 TestDifferentQuantizationScale(inputInfo0, inputInfo2);
2134 TestDifferentQuantizationScale(inputInfo1, inputInfo2);
2135 TestDifferentQuantizationScale(inputInfo0, outputInfo);
2174 quantizerPtrQAsymmU8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2175 quantizerPtrQAsymmU8->OverrideInputRange(1, (min + 6.7f), max);
2176 quantizerPtrQAsymmU8->OverrideInputRange(2, min, (max - 7.8f));
2178 quantizerPtrQSymmS8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2179 quantizerPtrQSymmS8->OverrideInputRange(1, (min + 6.7f), max);
2180 quantizerPtrQSymmS8->OverrideInputRange(2, min, (max - 7.8f));
2182 quantizerPtrQSymmS16->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2183 quantizerPtrQSymmS16->OverrideInputRange(1, (min + 6.7f), max);
2184 quantizerPtrQSymmS16->OverrideInputRange(2, min, (max - 7.8f));
2186 INetworkPtr quantizedNetworkQAsymmU8 = quantizerPtrQAsymmU8->ExportNetwork();
2187 TestConcatQuantization validatorQAsymmU8(shape, shape);
2190 INetworkPtr quantizedNetworkQSymmS8 = quantizerPtrQSymmS8->ExportNetwork();
2191 TestConcatQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2194 INetworkPtr quantizedNetworkQSymmS16 = quantizerPtrQSymmS16->ExportNetwork();
2195 TestConcatQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2201 class TestReshapeQuantization :
public TestLeakyReLuActivationQuantization
2205 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2210 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2214 const char* name =
nullptr)
override 2217 CheckForwardedQuantizationSettings(layer);
2235 TestReshapeQuantization validatorQAsymmU8(shape, shape);
2240 TestReshapeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2245 TestReshapeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2250 TestReshapeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2256 class TestSplitterQuantization :
public TestLeakyReLuActivationQuantization
2260 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2265 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2269 const char* name =
nullptr)
2272 CheckForwardedQuantizationSettings(layer);
2289 TestSplitterQuantization validatorQAsymmU8(shape, shape);
2294 TestSplitterQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2299 TestSplitterQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2304 TestSplitterQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2310 class TestResizeQuantization :
public TestLeakyReLuActivationQuantization
2314 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
2320 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
2325 const char* name =
nullptr)
override 2328 CheckForwardedQuantizationSettings(layer);
2342 descriptor.m_TargetWidth = 3;
2348 TestResizeQuantization validatorQAsymmU8(shape, shape);
2353 TestResizeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2358 TestResizeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2363 TestResizeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2369 class TestStridedSliceQuantization :
public TestLeakyReLuActivationQuantization
2373 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2378 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2382 const char* name =
nullptr)
2385 CheckForwardedQuantizationSettings(layer);
2398 IConnectableLayer* stridedSlice = network->AddStridedSliceLayer(stridedSliceDesc);
2403 TestStridedSliceQuantization validatorQAsymmU8(shape, shape);
2408 TestStridedSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2413 TestStridedSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2418 TestStridedSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2424 class TestBatchToSpaceQuantization :
public TestLeakyReLuActivationQuantization
2428 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2433 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2437 const char* name =
nullptr)
override 2440 CheckForwardedQuantizationSettings(layer);
2458 TestBatchToSpaceQuantization validatorQAsymmU8(shape, shape);
2463 TestBatchToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2468 TestBatchToSpaceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2473 TestBatchToSpaceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2479 class TestPreluQuantization :
public TestQuantization
2482 TestPreluQuantization(
const TensorShape& inputShape,
2485 : TestQuantization(inputShape, outputShape)
2486 , m_AlphaShape(alphaShape)
2493 : TestQuantization(options, inputShape, outputShape)
2494 , m_AlphaShape(alphaShape)
2499 const char* name =
nullptr)
override 2507 BOOST_TEST(m_InputShape == info.
GetShape());
2510 BOOST_TEST(m_AlphaShape == info.
GetShape());
2517 TestQuantizationParams(info,
2526 const char* name =
nullptr)
override 2530 BOOST_TEST(m_OutputShape == info.
GetShape());
2534 const char* name =
nullptr)
override 2538 TestQuantizationParams(info,
2579 TestPreluQuantization validatorQAsymmU8(inputShape, alphaShape, outputShape);
2584 TestPreluQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, alphaShape, outputShape);
2589 TestPreluQuantization validatorQSymmS8(qSymmS8Options, inputShape, alphaShape, outputShape);
2594 TestPreluQuantization validatorQSymmS16(qSymmS16options, inputShape, alphaShape, outputShape);
2600 class TestTransposeConvolution2dQuantization :
public TestQuantization
2604 TestQuantization(inputShape, outputShape)
2610 TestQuantization(options, inputShape, outputShape)
2617 const char *name =
nullptr)
override 2620 TestQuantizationOnLayersWithBiases(layer, weights, biases);
2629 std::initializer_list<float> floatData{ -1.0f, 1.5f, 2.0f };
2630 std::vector<float> weightsData(floatData);
2639 std::vector<float> biasesData(floatData);
2645 IConnectableLayer* transposeConv2d = network->AddTransposeConvolution2dLayer(descriptor, weights, optionalBiases);
2649 transposeConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
2652 transposeConv2d->GetOutputSlot(0).SetTensorInfo(info);
2656 TestTransposeConvolution2dQuantization validatorQAsymmU8(shape, shape);
2662 TestTransposeConvolution2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2668 TestTransposeConvolution2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2674 TestTransposeConvolution2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2690 class TestStackQuantization :
public TestQuantization
2693 TestStackQuantization(
const TensorShape& inputShape,
2695 : TestQuantization(inputShape, outputShape) {}
2700 : TestQuantization(options, inputShape, outputShape) {}
2704 const char* name =
nullptr)
override 2710 const char* name =
nullptr)
override 2717 const char* name =
nullptr)
override 2722 TestQuantizationParams(outputInfo,
2748 TestStackQuantization validatorQAsymmU8(inputShape, outputShape);
2753 TestStackQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, inputShape);
2758 TestStackQuantization validatorQSymmS8(qSymmS8Options, inputShape, inputShape);
2763 TestStackQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
2769 class TestSliceQuantization :
public TestQuantization
2773 : TestQuantization(inputShape, outputShape)
2779 : TestQuantization(options, inputShape, outputShape)
2784 const char* name =
nullptr)
2794 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
2815 TestSliceQuantization validatorQAsymmU8(shape, shape);
2821 TestSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2827 TestSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2833 TestSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2841 inputInfo.SetQuantizationOffset(1);
2842 std::vector<float> input({ value, 0.0f, 0.0f, 1.0f });
2843 const std::vector<float> &inputRef = input;
2845 auto output = armnnUtils::QuantizedVector<uint8_t>(inputRef,
2846 inputInfo.GetQuantizationScale(),
2847 inputInfo.GetQuantizationOffset());
2854 BOOST_CHECK_EQUAL(
SetupQuantize(std::numeric_limits<float>::infinity())[0], 255);
2859 BOOST_CHECK_EQUAL(
SetupQuantize(-1 * std::numeric_limits<float>::infinity())[0], 0);
2862 class TestPreserveType :
public TestAdditionQuantization
2869 : TestAdditionQuantization(options, inputShape, outputShape)
2870 , m_DataType(dataType)
2871 , m_VisitedQuantizeLayer(
false)
2872 , m_VisitedDequantizeLayer(
false) {}
2876 const char* name =
nullptr)
override 2881 BOOST_TEST(m_InputShape == info.
GetShape());
2886 const char* name =
nullptr)
override 2891 BOOST_TEST(m_OutputShape == info.
GetShape());
2895 const char* name =
nullptr)
override 2898 m_VisitedQuantizeLayer =
true;
2902 const char* name =
nullptr)
override 2905 m_VisitedDequantizeLayer =
true;
2908 void CheckQuantizeDequantizeLayerVisited(
bool expected)
2923 bool m_VisitedQuantizeLayer;
2924 bool m_VisitedDequantizeLayer;
2951 TestPreserveType validatorQAsymmU8(options, dataType, shape, shape);
2953 validatorQAsymmU8.CheckQuantizeDequantizeLayerVisited(
2979 class TestConnectionPreservation :
public LayerVisitorBase<VisitorNoThrowPolicy>
2982 TestConnectionPreservation(
const Graph& graph)
2993 void CheckLayerName(
LayerGuid guid, std::string expectedName)
2995 bool guidFound =
false;
2996 for (
Layer* layer : m_Graph)
3000 BOOST_CHECK_EQUAL(layer->
GetName(), expectedName.c_str());
3007 BOOST_FAIL(
"No layer matching the GUID was found");
3037 TestConnectionPreservation visitor1(PolymorphicDowncast<const Network*>(network.get())->GetGraph());
3044 std::vector<float> inputData({0, 2, 0, 4});
3048 inputTensors.push_back(std::make_pair(0, inputTensor));
3049 quantizer->Refine(inputTensors);
3051 INetworkPtr quantNetwork = quantizer->ExportNetwork();
3053 TestConnectionPreservation visitor2(PolymorphicDowncast<const Network*>(quantNetwork.get())->GetGraph());
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
const float g_AsymmU8QuantizationBase
bool m_BiasEnabled
Enable/disable bias.
std::pair< float, int > OffsetScalePair
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
bool m_BiasEnabled
Enable/disable bias.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
const TensorShape & GetShape() const
A ReshapeDescriptor for the ReshapeLayer.
INetworkPtr CreateNetworkWithActivationLayer(const ActivationDescriptor &descriptor, const TensorShape &shape)
A ComparisonDescriptor for the ComparisonLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
INetworkPtr CreateNetworkWithInputOutputLayers()
bool m_BiasEnabled
Enable/disable bias.
const Graph & GetGraph() const
float m_Beta
Exponentiation value.
virtual IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)=0
Adds an activation layer to the network.
const float g_SymmS8QuantizationBase
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
std::unique_ptr< class INetworkQuantizer, void(*)(INetworkQuantizer *quantizer)> INetworkQuantizerPtr
Main network class which provides the interface for building up a neural network. ...
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
std::vector< uint8_t > SetupQuantize(float value)
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
INetworkPtr CreateNetworkWithFullyConnectedLayer(const bool biasEnabled, const TensorShape &inputShape, const TensorShape &outputShape)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
void VisitLayers(const LayerContainer &layerContainer, ILayerVisitor &visitor)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::pair< float, float > MinMaxRange
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
uint32_t m_NumOutputs
Number of output tensors.
constexpr const char * GetDataTypeName(DataType dataType)
A ResizeDescriptor for the ResizeLayer.
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
A StackDescriptor for the StackLayer.
virtual IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)=0
Adds an output layer to the network.
void VisitLayersTopologically(const INetwork *inputNetwork, ILayerVisitor &visitor)
IConnectableLayer * CreateStartOfLeakyReluNetwork(INetwork *network, const TensorInfo &info)
#define ARMNN_ASSERT_MSG(COND, MSG)
int32_t GetQuantizationOffset() const
An ArgMinMaxDescriptor for ArgMinMaxLayer.
float GetQuantizationScale() const
DataType GetDataType() const
An OriginsDescriptor for the ConcatLayer.
bool has_value() const noexcept
std::unordered_map< LayerGuid, MinMaxRanges > MinMaxRangeMap
A FullyConnectedDescriptor for the FullyConnectedLayer.
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
bool HasRanges(LayerGuid guid) const
Query that there is an entry for a layer.
void TestQuantizeDepthwiseConvolution2d(bool useBiases)
std::vector< MinMaxRange > MinMaxRanges
void SetQuantizationScale(float scale)
A StandInDescriptor for the StandIn layer.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
An ActivationDescriptor for the ActivationLayer.
const TensorInfo & GetInfo() const
min(a, max(b, input)) ReLu1 & ReLu6.
uint32_t m_TargetHeight
Target height value.
A SliceDescriptor for the SliceLayer.
Visitor base class with empty implementations.
const float g_TestTolerance
void ValidateFullyConnectedLayer(const bool biasEnabled)
const float g_SymmS16QuantizationBase
Private implementation of INetwork.
bool IsEmpty() const
Query function to check that the RangeTracker is empty.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
BOOST_AUTO_TEST_SUITE_END()
std::pair< float, float > MinMaxRange
void QuantizeConstant(const srcType *src, uint8_t *dst, size_t numElements, float &scale, int &offset)
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
Adds an addition layer to the network.
uint32_t m_NumInputs
Number of input tensors.
void TestQuantizeConvolution2d(bool useBiases)
void CompleteLeakyReluNetwork(INetwork *network, IConnectableLayer *activation, IConnectableLayer *layerUnderTest, const TensorInfo &info)
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A StridedSliceDescriptor for the StridedSliceLayer.
virtual const TensorInfo & GetTensorInfo() const =0
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual const char * GetName() const =0
Returns the name of the layer.
InputLayersAccessor GetInputLayers() const
Returns a wrapper object with begin(), end() methods to iterate over the input layers in a range-base...
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
INetworkPtr CreateNetworkWithSoftmaxLayer(const SoftmaxDescriptor &descriptor, const TensorShape &shape)
virtual int Connect(IInputSlot &destination)=0
virtual LayerGuid GetOwningLayerGuid() const =0
void PreserveTypeTestImpl(const DataType &dataType)
A Pooling2dDescriptor for the Pooling2dLayer.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
virtual IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)=0
Adds an input layer to the network.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
A SoftmaxDescriptor for the SoftmaxLayer.
TensorInfo GetInputTensorInfo(const Network *network)
static INetworkPtr Create()
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
void TestQuantizeTransposeConvolution2d(bool useBiases)
const float g_AsymmS8QuantizationBase
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
static INetworkQuantizerPtr Create(INetwork *inputNetwork, const QuantizerOptions &options=QuantizerOptions())
Create Quantizer object wrapped in unique_ptr.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.