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" 21 #include <boost/test/unit_test.hpp> 23 #include <unordered_map> 45 , m_InputShape(inputShape)
46 , m_OutputShape(outputShape)
51 , m_InputShape(inputShape)
52 , m_OutputShape(outputShape)
53 , m_QuantizerOptions(options) {}
57 const char* name =
nullptr)
override 61 BOOST_TEST(m_InputShape == info.
GetShape());
71 const char* name =
nullptr)
override 75 BOOST_TEST(m_OutputShape == info.
GetShape());
85 switch (m_QuantizerOptions.m_ActivationFormat)
88 TestQuantizationParamsImpl(
92 TestQuantizationParamsImpl(
96 TestQuantizationParamsImpl(
100 TestQuantizationParamsImpl(
113 void TestConstantQuantizationParams(
const TensorInfo& info,
118 TestQuantizationParamsImpl(info, dataType, params.first, params.second);
121 void TestBiasQuantizationParams(
const TensorInfo& info,
128 switch (m_QuantizerOptions.m_ActivationFormat)
131 TestQuantizationParamsImpl(info, dataType, qAsymmU8Params.first, qAsymmU8Params.second);
134 TestQuantizationParamsImpl(info, dataType, qAsymmS8Params.first, qAsymmS8Params.second);
137 TestQuantizationParamsImpl(info, dataType, qSymmS8Params.first, qSymmS8Params.second);
140 TestQuantizationParamsImpl(info, dataType, qSymmS16Params.first, qSymmS16Params.second);
159 TestQuantizationParams(info, {inputScaleQAsymmU8, 128},
160 {inputScaleQAsymmS8, 0},
161 {inputScaleQSymmS8, 0},
162 {inputScaleQSymmS16, 0});
164 TestConstantQuantizationParams(weights.
GetInfo(), {weightsScale, 85});
168 TestBiasQuantizationParams(biases.
value().GetInfo(),
169 {inputScaleQAsymmU8 * weightsScale, 0},
170 {inputScaleQAsymmS8 * weightsScale, 0},
171 {inputScaleQSymmS8 * weightsScale, 0},
172 {inputScaleQSymmS16 * weightsScale, 0},
181 void TestQuantizationParamsImpl(
const TensorInfo& info,
DataType dataType,
float scale, int32_t offset)
193 auto network = boost::polymorphic_downcast<const Network*>(inputNetwork);
194 auto graph = network->GetGraph().TopologicalSort();
199 class TestAdditionQuantization :
public TestQuantization
203 : TestQuantization(inputShape, outputShape) {}
208 : TestQuantization(options, inputShape, outputShape) {}
211 const char* name =
nullptr)
override 249 TestAdditionQuantization validatorQAsymmU8(shape, shape);
254 TestAdditionQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
259 TestAdditionQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
264 TestAdditionQuantization validatorQSymmS16(qSymmS16options, shape, shape);
268 class TestActivationQuantization :
public TestQuantization
272 : TestQuantization(inputShape, outputShape) {}
277 : TestQuantization(options, inputShape, outputShape) {}
281 const char* name =
nullptr)
override 339 BOOST_ASSERT_MSG(inputLayer->GetNumOutputSlots() == 1,
"Input layer should have exactly 1 output slot");
340 return inputLayer->GetOutputSlot(0).GetTensorInfo();
352 std::vector<float> inputData({0, 0, 0, -56, 98, 0, 0, 0});
356 inputTensors.push_back(std::make_pair(0, inputTensor));
360 quantizer->Refine(inputTensors);
363 std::vector<float> inputData2({0, -77, 0, -56, 65, 0, 0, 0});
366 inputTensors2.push_back(std::make_pair(0, inputTensor2));
368 quantizer->Refine(inputTensors2);
370 INetworkPtr quantizedNetwork = quantizer->ExportNetwork();
373 std::unique_ptr<IQuantizationScheme> quantizationScheme = std::make_unique<QAsymmU8QuantizationScheme>();
374 OffsetScalePair qParams = quantizationScheme->ComputeScheme(-77.0, 98.0);
380 m_OffsetScalePair(offsetScalePair), m_DataType(dataType) {}
384 const char* name =
nullptr)
override 388 BOOST_CHECK_MESSAGE(info.
GetDataType() == m_DataType,
394 BOOST_TEST(info.
GetQuantizationScale() == m_OffsetScalePair.first, boost::test_tools::tolerance(0.001));
403 quantizedNetwork->Accept(visitor);
410 descriptor.
m_A = 3.5f;
411 descriptor.
m_B = -10.0f;
418 TestActivationQuantization validatorQAsymmU8(shape, shape);
423 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
428 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
433 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
441 descriptor.
m_A = 3.5f;
442 descriptor.
m_B = -10.0f;
448 TestActivationQuantization validatorQAsymmU8(shape, shape);
453 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
458 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
463 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
471 descriptor.
m_A = 3.5f;
472 descriptor.
m_B = -10.0f;
478 TestActivationQuantization validatorQAsymmU8(shape, shape);
483 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
488 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
493 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
501 descriptor.
m_A = 3.5f;
502 descriptor.
m_B = -10.0f;
508 TestActivationQuantization validatorQAsymmU8(shape, shape);
513 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
518 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
523 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
529 class TestBoundedReluActivationQuantization :
public TestQuantization
533 : TestQuantization(inputShape, outputShape) {}
538 : TestQuantization(options, inputShape, outputShape) {}
542 const char* name =
nullptr)
override 557 descriptor.
m_A = 3.5f;
558 descriptor.
m_B = -10.0f;
564 TestBoundedReluActivationQuantization validatorQAsymmU8(shape, shape);
569 TestBoundedReluActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
574 TestBoundedReluActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
579 TestBoundedReluActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
585 class TestTanHActivationQuantization :
public TestQuantization
589 : TestQuantization(inputShape, outputShape) {}
594 : TestQuantization(options, inputShape, outputShape) {}
598 const char* name =
nullptr)
override 604 TestQuantizationParams(
614 descriptor.
m_A = 3.5f;
615 descriptor.
m_B = -10.0f;
621 TestTanHActivationQuantization validatorQAsymmU8(shape, shape);
626 TestTanHActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
631 TestTanHActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
636 TestTanHActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
640 class TestLeakyReLuActivationQuantization :
public TestQuantization
644 : TestQuantization(inputShape, outputShape) {}
649 : TestQuantization(options, inputShape, outputShape) {}
653 const char* name =
nullptr)
override 682 descriptor.
m_A = 3.5f;
683 descriptor.
m_B = -10.0f;
689 TestLeakyReLuActivationQuantization validatorQAsymmU8(shape, shape);
694 TestLeakyReLuActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
699 TestLeakyReLuActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
704 TestLeakyReLuActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
711 class TestEluActivationQuantization :
public TestQuantization
715 : TestQuantization(inputShape, outputShape) {}
720 : TestQuantization(options, inputShape, outputShape) {}
724 const char* name =
nullptr)
override 730 TestQuantizationParams(
745 TestEluActivationQuantization validatorQAsymmU8(shape, shape);
750 TestEluActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
755 TestEluActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
760 TestEluActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
765 class TestHardSwishActivationQuantization :
public TestQuantization
769 : TestQuantization(inputShape, outputShape) {}
774 : TestQuantization(options, inputShape, outputShape) {}
778 const char* name =
nullptr)
override 784 TestQuantizationParams(
799 TestHardSwishActivationQuantization validatorQAsymmU8(shape, shape);
804 TestHardSwishActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
809 TestHardSwishActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
814 TestHardSwishActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
821 class TestBatchNormalizationQuantization :
public TestQuantization
825 : TestQuantization(inputShape, outputShape) {}
830 : TestQuantization(options, inputShape, outputShape) {}
838 const char* name =
nullptr)
override 844 TestQuantizationParams(
863 std::vector<float> meanData{-1.0f, 1.5f, 2.0f};
864 std::vector<float> varData{-1.0f, 1.5f, 2.0f};
865 std::vector<float> betaData{-1.0f, 1.5f, 2.0f};
866 std::vector<float> gammaData{-1.0f, 1.5f, 2.0f};
877 IConnectableLayer* batchNorm = network->AddBatchNormalizationLayer(desc, mean, var, beta, gamma);
889 TestBatchNormalizationQuantization validatorQAsymmU8(shape, shape);
894 TestBatchNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
899 TestBatchNormalizationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
904 TestBatchNormalizationQuantization validatorQSymmS16(QQsymm16Options, shape, shape);
910 class TestDepthToSpaceQuantization :
public TestQuantization
914 : TestQuantization(inputShape, outputShape) {}
919 : TestQuantization(options, inputShape, outputShape) {}
923 const char* name =
nullptr)
933 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
947 IConnectableLayer* depthToSpaceLayer = network->AddDepthToSpaceLayer(descriptor);
958 TestDepthToSpaceQuantization validatorQAsymmU8(inputShape, outputShape);
964 TestDepthToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
970 TestDepthToSpaceQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
976 TestDepthToSpaceQuantization validatorQSymmS16(Qsymm16Options, inputShape, outputShape);
989 VisitLayers(inputLayers, overrideInputRangeVisitor);
1004 VisitLayers(inputLayers, overrideInputRangeVisitor);
1038 VisitLayers(inputLayers, overrideInputRangeVisitorLayer3);
1045 VisitLayers(inputLayers, overrideInputRangeVisitorLayer1);
1071 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1078 std::vector<float> biasData{10.0f, 20.0f, 30.0f};
1084 fullyConnected = network->AddFullyConnectedLayer(desc, weights, optionalBias);
1089 fullyConnected->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1093 fullyConnected->GetOutputSlot(0).SetTensorInfo(outputInfo);
1100 class TestFullyConnectedQuantization :
public TestQuantization
1104 : TestQuantization(inputShape, outputShape) {}
1109 : TestQuantization(options, inputShape, outputShape) {}
1115 const char* name =
nullptr)
override 1118 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1126 TestFullyConnectedQuantization validatorQAsymmU8(shape, shape);
1131 TestFullyConnectedQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1136 TestFullyConnectedQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1141 TestFullyConnectedQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1157 class TestConv2dQuantization :
public TestQuantization
1161 : TestQuantization(inputShape, outputShape) {}
1166 : TestQuantization(options, inputShape, outputShape) {}
1172 const char *name =
nullptr)
override 1175 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1184 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1194 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1200 conv2d = network->AddConvolution2dLayer(descriptor, weights, optionalBiases);
1205 conv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1209 conv2d->GetOutputSlot(0).SetTensorInfo(info);
1212 TestConv2dQuantization validatorQAsymmU8(shape, shape);
1217 TestConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1222 TestConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1227 TestConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1243 class TestDepthwiseConv2dQuantization :
public TestQuantization
1247 : TestQuantization(inputShape, outputShape) {}
1252 : TestQuantization(options, inputShape, outputShape) {}
1258 const char *name =
nullptr)
override 1261 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1270 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1280 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1286 depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases);
1291 depthwiseConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1295 depthwiseConv2d->GetOutputSlot(0).SetTensorInfo(info);
1298 TestDepthwiseConv2dQuantization validatorQAsymmU8(shape, shape);
1303 TestDepthwiseConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1308 TestDepthwiseConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1313 TestDepthwiseConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1329 class TestInstanceNormalizationQuantization :
public TestQuantization
1333 : TestQuantization(inputShape, outputShape) {}
1338 : TestQuantization(options, inputShape, outputShape) {}
1342 const char* name =
nullptr)
1352 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1373 TestInstanceNormalizationQuantization validatorQAsymmU8(tensorShape, tensorShape);
1379 TestInstanceNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1385 TestInstanceNormalizationQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1391 TestInstanceNormalizationQuantization validatorQSymmS16(qSymmS16Options, tensorShape, tensorShape);
1397 class TestLogSoftmaxQuantization :
public TestQuantization
1401 : TestQuantization(inputShape, outputShape) {}
1406 : TestQuantization(options, inputShape, outputShape) {}
1410 const char* name =
nullptr)
override 1420 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1430 descriptor.
m_Beta = 1.0f;
1444 TestLogSoftmaxQuantization validatorQAsymmU8(tensorShape, tensorShape);
1450 TestLogSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1456 TestLogSoftmaxQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1462 TestLogSoftmaxQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
1489 class TestSoftmaxQuantization :
public TestQuantization
1493 : TestQuantization(inputShape, outputShape) {}
1498 : TestQuantization(options, inputShape, outputShape) {}
1502 const char* name =
nullptr)
override 1516 descriptor.
m_Beta = 1.0f;
1522 TestSoftmaxQuantization validatorQAsymmU8(shape, shape);
1527 TestSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1533 TestSoftmaxQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1538 TestSoftmaxQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1587 activationDescriptor.
m_A = 3.5f;
1588 activationDescriptor.
m_B = -10.0f;
1622 class TestPermuteQuantization :
public TestLeakyReLuActivationQuantization
1626 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1631 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1635 const char* name =
nullptr)
override 1638 CheckForwardedQuantizationSettings(layer);
1656 TestPermuteQuantization validatorQAsymmU8(shape, shape);
1661 TestPermuteQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1666 TestPermuteQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1671 TestPermuteQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1677 class TestSpaceToBatchQuantization :
public TestLeakyReLuActivationQuantization
1681 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1686 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1690 const char* name =
nullptr)
override 1693 CheckForwardedQuantizationSettings(layer);
1711 TestSpaceToBatchQuantization validatorQAsymmU8(shape, shape);
1716 TestSpaceToBatchQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1721 TestSpaceToBatchQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1726 TestSpaceToBatchQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1732 class TestSpaceToDepthQuantization :
public TestLeakyReLuActivationQuantization
1736 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
1742 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
1747 const char* =
nullptr)
override 1750 TestQuantizationParams(info,
1769 TestSpaceToDepthQuantization validatorQAsymmU8(shape, shape);
1774 TestSpaceToDepthQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1779 TestSpaceToDepthQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1784 TestSpaceToDepthQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1790 class TestPooling2dQuantization :
public TestLeakyReLuActivationQuantization
1794 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1799 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1803 const char* name =
nullptr)
override 1806 CheckForwardedQuantizationSettings(layer);
1818 activationDescriptor.
m_A = 3.5f;
1819 activationDescriptor.
m_B = -10.0f;
1823 IConnectableLayer* activation = network->AddActivationLayer(activationDescriptor);
1838 TestPooling2dQuantization validatorQAsymmU8(shape, shape);
1843 TestPooling2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1848 TestPooling2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1853 TestPooling2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1859 class TestConstantQuantization :
public TestAdditionQuantization
1863 : TestAdditionQuantization(inputShape, outputShape) {}
1868 : TestAdditionQuantization(options, inputShape, outputShape) {}
1872 const char* name =
nullptr)
override 1888 std::vector<float> data = {-2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
1910 TestConstantQuantization validatorQAsymmU8(shape, shape);
1915 TestConstantQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1920 TestConstantQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1925 TestConstantQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1931 class TestArgMinMaxQuantization :
public TestQuantization
1935 TestQuantization(inputShape, outputShape) {}
1940 TestQuantization(options, inputShape, outputShape)
1945 const char* name =
nullptr)
override 1952 const char* name =
nullptr)
override 1958 const char* name =
nullptr)
override 1963 TestQuantizationParams(outputInfo,
1985 IConnectableLayer* argMinMaxLayer = network->AddArgMinMaxLayer(argMinMaxDescriptor);
1999 TestArgMinMaxQuantization validatorQAsymmU8(inputShape, outputShape);
2004 TestArgMinMaxQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
2009 TestArgMinMaxQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
2014 TestArgMinMaxQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
2020 class TestComparisonQuantization :
public TestQuantization
2024 : TestQuantization(inputShape, outputShape) {}
2029 : TestQuantization(options, inputShape, outputShape) {}
2033 const char* name =
nullptr)
override 2043 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
2068 TestComparisonQuantization validatorQAsymmU8(tensorShape, tensorShape);
2074 TestComparisonQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
2080 TestComparisonQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
2086 TestComparisonQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
2092 class TestConcatQuantization :
public TestQuantization
2096 : TestQuantization(inputShape, outputShape) {}
2101 : TestQuantization(options, inputShape, outputShape) {}
2105 const char* name =
nullptr)
override 2111 const char* name =
nullptr)
override 2117 const char* name =
nullptr)
override 2121 TestQuantizationParams(
2131 TestDifferentQuantizationScale(inputInfo0, inputInfo1);
2132 TestDifferentQuantizationScale(inputInfo0, inputInfo2);
2133 TestDifferentQuantizationScale(inputInfo1, inputInfo2);
2134 TestDifferentQuantizationScale(inputInfo0, outputInfo);
2173 quantizerPtrQAsymmU8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2174 quantizerPtrQAsymmU8->OverrideInputRange(1, (min + 6.7f), max);
2175 quantizerPtrQAsymmU8->OverrideInputRange(2, min, (max - 7.8f));
2177 quantizerPtrQSymmS8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2178 quantizerPtrQSymmS8->OverrideInputRange(1, (min + 6.7f), max);
2179 quantizerPtrQSymmS8->OverrideInputRange(2, min, (max - 7.8f));
2181 quantizerPtrQSymmS16->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2182 quantizerPtrQSymmS16->OverrideInputRange(1, (min + 6.7f), max);
2183 quantizerPtrQSymmS16->OverrideInputRange(2, min, (max - 7.8f));
2185 INetworkPtr quantizedNetworkQAsymmU8 = quantizerPtrQAsymmU8->ExportNetwork();
2186 TestConcatQuantization validatorQAsymmU8(shape, shape);
2189 INetworkPtr quantizedNetworkQSymmS8 = quantizerPtrQSymmS8->ExportNetwork();
2190 TestConcatQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2193 INetworkPtr quantizedNetworkQSymmS16 = quantizerPtrQSymmS16->ExportNetwork();
2194 TestConcatQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2200 class TestReshapeQuantization :
public TestLeakyReLuActivationQuantization
2204 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2209 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2213 const char* name =
nullptr)
override 2216 CheckForwardedQuantizationSettings(layer);
2234 TestReshapeQuantization validatorQAsymmU8(shape, shape);
2239 TestReshapeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2244 TestReshapeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2249 TestReshapeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2255 class TestSplitterQuantization :
public TestLeakyReLuActivationQuantization
2259 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2264 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2268 const char* name =
nullptr)
2271 CheckForwardedQuantizationSettings(layer);
2288 TestSplitterQuantization validatorQAsymmU8(shape, shape);
2293 TestSplitterQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2298 TestSplitterQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2303 TestSplitterQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2309 class TestResizeQuantization :
public TestLeakyReLuActivationQuantization
2313 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
2319 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
2324 const char* name =
nullptr)
override 2327 CheckForwardedQuantizationSettings(layer);
2341 descriptor.m_TargetWidth = 3;
2347 TestResizeQuantization validatorQAsymmU8(shape, shape);
2352 TestResizeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2357 TestResizeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2362 TestResizeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2368 class TestStridedSliceQuantization :
public TestLeakyReLuActivationQuantization
2372 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2377 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2381 const char* name =
nullptr)
2384 CheckForwardedQuantizationSettings(layer);
2397 IConnectableLayer* stridedSlice = network->AddStridedSliceLayer(stridedSliceDesc);
2402 TestStridedSliceQuantization validatorQAsymmU8(shape, shape);
2407 TestStridedSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2412 TestStridedSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2417 TestStridedSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2423 class TestBatchToSpaceQuantization :
public TestLeakyReLuActivationQuantization
2427 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2432 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2436 const char* name =
nullptr)
override 2439 CheckForwardedQuantizationSettings(layer);
2457 TestBatchToSpaceQuantization validatorQAsymmU8(shape, shape);
2462 TestBatchToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2467 TestBatchToSpaceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2472 TestBatchToSpaceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2478 class TestPreluQuantization :
public TestQuantization
2481 TestPreluQuantization(
const TensorShape& inputShape,
2484 : TestQuantization(inputShape, outputShape)
2485 , m_AlphaShape(alphaShape)
2492 : TestQuantization(options, inputShape, outputShape)
2493 , m_AlphaShape(alphaShape)
2498 const char* name =
nullptr)
override 2506 BOOST_TEST(m_InputShape == info.
GetShape());
2509 BOOST_TEST(m_AlphaShape == info.
GetShape());
2516 TestQuantizationParams(info,
2525 const char* name =
nullptr)
override 2529 BOOST_TEST(m_OutputShape == info.
GetShape());
2533 const char* name =
nullptr)
override 2537 TestQuantizationParams(info,
2578 TestPreluQuantization validatorQAsymmU8(inputShape, alphaShape, outputShape);
2583 TestPreluQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, alphaShape, outputShape);
2588 TestPreluQuantization validatorQSymmS8(qSymmS8Options, inputShape, alphaShape, outputShape);
2593 TestPreluQuantization validatorQSymmS16(qSymmS16options, inputShape, alphaShape, outputShape);
2599 class TestTransposeConvolution2dQuantization :
public TestQuantization
2603 TestQuantization(inputShape, outputShape)
2609 TestQuantization(options, inputShape, outputShape)
2616 const char *name =
nullptr)
override 2619 TestQuantizationOnLayersWithBiases(layer, weights, biases);
2628 std::initializer_list<float> floatData{ -1.0f, 1.5f, 2.0f };
2629 std::vector<float> weightsData(floatData);
2638 std::vector<float> biasesData(floatData);
2644 IConnectableLayer* transposeConv2d = network->AddTransposeConvolution2dLayer(descriptor, weights, optionalBiases);
2648 transposeConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
2651 transposeConv2d->GetOutputSlot(0).SetTensorInfo(info);
2655 TestTransposeConvolution2dQuantization validatorQAsymmU8(shape, shape);
2661 TestTransposeConvolution2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2667 TestTransposeConvolution2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2673 TestTransposeConvolution2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2689 class TestStackQuantization :
public TestQuantization
2692 TestStackQuantization(
const TensorShape& inputShape,
2694 : TestQuantization(inputShape, outputShape) {}
2699 : TestQuantization(options, inputShape, outputShape) {}
2703 const char* name =
nullptr)
override 2709 const char* name =
nullptr)
override 2716 const char* name =
nullptr)
override 2721 TestQuantizationParams(outputInfo,
2747 TestStackQuantization validatorQAsymmU8(inputShape, outputShape);
2752 TestStackQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, inputShape);
2757 TestStackQuantization validatorQSymmS8(qSymmS8Options, inputShape, inputShape);
2762 TestStackQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
2768 class TestSliceQuantization :
public TestQuantization
2772 : TestQuantization(inputShape, outputShape)
2778 : TestQuantization(options, inputShape, outputShape)
2783 const char* name =
nullptr)
2793 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
2814 TestSliceQuantization validatorQAsymmU8(shape, shape);
2820 TestSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2826 TestSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2832 TestSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2840 inputInfo.SetQuantizationOffset(1);
2841 std::vector<float> input({ value, 0.0f, 0.0f, 1.0f });
2842 const std::vector<float> &inputRef = input;
2844 auto output = armnnUtils::QuantizedVector<uint8_t>(inputRef,
2845 inputInfo.GetQuantizationScale(),
2846 inputInfo.GetQuantizationOffset());
2853 BOOST_CHECK_EQUAL(
SetupQuantize(std::numeric_limits<float>::infinity())[0], 255);
2858 BOOST_CHECK_EQUAL(
SetupQuantize(-1 * std::numeric_limits<float>::infinity())[0], 0);
2861 class TestPreserveType :
public TestAdditionQuantization
2868 : TestAdditionQuantization(options, inputShape, outputShape)
2869 , m_DataType(dataType)
2870 , m_VisitedQuantizeLayer(
false)
2871 , m_VisitedDequantizeLayer(
false) {}
2875 const char* name =
nullptr)
override 2880 BOOST_TEST(m_InputShape == info.
GetShape());
2885 const char* name =
nullptr)
override 2890 BOOST_TEST(m_OutputShape == info.
GetShape());
2894 const char* name =
nullptr)
override 2897 m_VisitedQuantizeLayer =
true;
2901 const char* name =
nullptr)
override 2904 m_VisitedDequantizeLayer =
true;
2907 void CheckQuantizeDequantizeLayerVisited(
bool expected)
2922 bool m_VisitedQuantizeLayer;
2923 bool m_VisitedDequantizeLayer;
2950 TestPreserveType validatorQAsymmU8(options, dataType, shape, shape);
2952 validatorQAsymmU8.CheckQuantizeDequantizeLayerVisited(
2978 class TestConnectionPreservation :
public LayerVisitorBase<VisitorNoThrowPolicy>
2981 TestConnectionPreservation(
const Graph& graph)
2992 void CheckLayerName(
LayerGuid guid, std::string expectedName)
2994 bool guidFound =
false;
2995 for (
Layer* layer : m_Graph)
2999 BOOST_CHECK_EQUAL(layer->
GetName(), expectedName.c_str());
3006 BOOST_FAIL(
"No layer matching the GUID was found");
3036 TestConnectionPreservation visitor1(boost::polymorphic_downcast<const Network*>(network.get())->GetGraph());
3043 std::vector<float> inputData({0, 2, 0, 4});
3047 inputTensors.push_back(std::make_pair(0, inputTensor));
3048 quantizer->Refine(inputTensors);
3050 INetworkPtr quantNetwork = quantizer->ExportNetwork();
3052 TestConnectionPreservation visitor2(boost::polymorphic_downcast<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)
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).
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).
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.