15 #include "../Graph.hpp" 16 #include "../Network.hpp" 17 #include "../NetworkQuantizerUtils.hpp" 18 #include "../OverrideInputRangeVisitor.hpp" 19 #include "../RangeTracker.hpp" 20 #include "../../armnnQuantizer/CommandLineProcessor.hpp" 22 #include <boost/core/ignore_unused.hpp> 23 #include <boost/test/unit_test.hpp> 25 #include <unordered_map> 47 , m_InputShape(inputShape)
48 , m_OutputShape(outputShape)
53 , m_InputShape(inputShape)
54 , m_OutputShape(outputShape)
55 , m_QuantizerOptions(options) {}
59 const char* name =
nullptr)
override 61 boost::ignore_unused(
id, name);
63 BOOST_TEST(m_InputShape == info.
GetShape());
73 const char* name =
nullptr)
override 75 boost::ignore_unused(
id, name);
77 BOOST_TEST(m_OutputShape == info.
GetShape());
87 switch (m_QuantizerOptions.m_ActivationFormat)
90 TestQuantizationParamsImpl(
94 TestQuantizationParamsImpl(
98 TestQuantizationParamsImpl(
102 TestQuantizationParamsImpl(
115 void TestConstantQuantizationParams(
const TensorInfo& info,
119 boost::ignore_unused(dataType);
120 TestQuantizationParamsImpl(info, dataType, params.first, params.second);
123 void TestBiasQuantizationParams(
const TensorInfo& info,
130 switch (m_QuantizerOptions.m_ActivationFormat)
133 TestQuantizationParamsImpl(info, dataType, qAsymmU8Params.first, qAsymmU8Params.second);
136 TestQuantizationParamsImpl(info, dataType, qAsymmS8Params.first, qAsymmS8Params.second);
139 TestQuantizationParamsImpl(info, dataType, qSymmS8Params.first, qSymmS8Params.second);
142 TestQuantizationParamsImpl(info, dataType, qSymmS16Params.first, qSymmS16Params.second);
161 TestQuantizationParams(info, {inputScaleQAsymmU8, 128},
162 {inputScaleQAsymmS8, 0},
163 {inputScaleQSymmS8, 0},
164 {inputScaleQSymmS16, 0});
166 TestConstantQuantizationParams(weights.
GetInfo(), {weightsScale, 85});
170 TestBiasQuantizationParams(biases.
value().GetInfo(),
171 {inputScaleQAsymmU8 * weightsScale, 0},
172 {inputScaleQAsymmS8 * weightsScale, 0},
173 {inputScaleQSymmS8 * weightsScale, 0},
174 {inputScaleQSymmS16 * weightsScale, 0},
183 void TestQuantizationParamsImpl(
const TensorInfo& info,
DataType dataType,
float scale, int32_t offset)
195 auto network = boost::polymorphic_downcast<const Network*>(inputNetwork);
196 auto graph = network->GetGraph().TopologicalSort();
201 class TestAdditionQuantization :
public TestQuantization
205 : TestQuantization(inputShape, outputShape) {}
210 : TestQuantization(options, inputShape, outputShape) {}
213 const char* name =
nullptr)
override 215 boost::ignore_unused(name);
251 TestAdditionQuantization validatorQAsymmU8(shape, shape);
256 TestAdditionQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
261 TestAdditionQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
266 TestAdditionQuantization validatorQSymmS16(qSymmS16options, shape, shape);
270 class TestActivationQuantization :
public TestQuantization
274 : TestQuantization(inputShape, outputShape) {}
279 : TestQuantization(options, inputShape, outputShape) {}
283 const char* name =
nullptr)
override 285 boost::ignore_unused(descriptor, name);
341 BOOST_ASSERT_MSG(inputLayer->GetNumOutputSlots() == 1,
"Input layer should have exactly 1 output slot");
342 return inputLayer->GetOutputSlot(0).GetTensorInfo();
354 std::vector<float> inputData({0, 0, 0, -56, 98, 0, 0, 0});
358 inputTensors.push_back(std::make_pair(0, inputTensor));
362 quantizer->Refine(inputTensors);
365 std::vector<float> inputData2({0, -77, 0, -56, 65, 0, 0, 0});
368 inputTensors2.push_back(std::make_pair(0, inputTensor2));
370 quantizer->Refine(inputTensors2);
372 INetworkPtr quantizedNetwork = quantizer->ExportNetwork();
375 std::unique_ptr<IQuantizationScheme> quantizationScheme = std::make_unique<QAsymmU8QuantizationScheme>();
376 OffsetScalePair qParams = quantizationScheme->ComputeScheme(-77.0, 98.0);
382 m_OffsetScalePair(offsetScalePair), m_DataType(dataType) {}
386 const char* name =
nullptr)
override 388 boost::ignore_unused(
id, name);
390 BOOST_CHECK_MESSAGE(info.
GetDataType() == m_DataType,
396 BOOST_TEST(info.
GetQuantizationScale() == m_OffsetScalePair.first, boost::test_tools::tolerance(0.001));
405 quantizedNetwork->Accept(visitor);
412 descriptor.
m_A = 3.5f;
413 descriptor.
m_B = -10.0f;
420 TestActivationQuantization validatorQAsymmU8(shape, shape);
425 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
430 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
435 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
443 descriptor.
m_A = 3.5f;
444 descriptor.
m_B = -10.0f;
450 TestActivationQuantization validatorQAsymmU8(shape, shape);
455 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
460 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
465 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
473 descriptor.
m_A = 3.5f;
474 descriptor.
m_B = -10.0f;
480 TestActivationQuantization validatorQAsymmU8(shape, shape);
485 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
490 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
495 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
503 descriptor.
m_A = 3.5f;
504 descriptor.
m_B = -10.0f;
510 TestActivationQuantization validatorQAsymmU8(shape, shape);
515 TestActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
520 TestActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
525 TestActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
531 class TestBoundedReluActivationQuantization :
public TestQuantization
535 : TestQuantization(inputShape, outputShape) {}
540 : TestQuantization(options, inputShape, outputShape) {}
544 const char* name =
nullptr)
override 546 boost::ignore_unused(descriptor, name);
559 descriptor.
m_A = 3.5f;
560 descriptor.
m_B = -10.0f;
566 TestBoundedReluActivationQuantization validatorQAsymmU8(shape, shape);
571 TestBoundedReluActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
576 TestBoundedReluActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
581 TestBoundedReluActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
587 class TestTanHActivationQuantization :
public TestQuantization
591 : TestQuantization(inputShape, outputShape) {}
596 : TestQuantization(options, inputShape, outputShape) {}
600 const char* name =
nullptr)
override 602 boost::ignore_unused(descriptor, name);
606 TestQuantizationParams(
616 descriptor.
m_A = 3.5f;
617 descriptor.
m_B = -10.0f;
623 TestTanHActivationQuantization validatorQAsymmU8(shape, shape);
628 TestTanHActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
633 TestTanHActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
638 TestTanHActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
642 class TestLeakyReLuActivationQuantization :
public TestQuantization
646 : TestQuantization(inputShape, outputShape) {}
651 : TestQuantization(options, inputShape, outputShape) {}
655 const char* name =
nullptr)
override 657 boost::ignore_unused(descriptor, name);
684 descriptor.
m_A = 3.5f;
685 descriptor.
m_B = -10.0f;
691 TestLeakyReLuActivationQuantization validatorQAsymmU8(shape, shape);
696 TestLeakyReLuActivationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
701 TestLeakyReLuActivationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
706 TestLeakyReLuActivationQuantization validatorQSymmS16(qSymmS16options, shape, shape);
712 class TestBatchNormalizationQuantization :
public TestQuantization
716 : TestQuantization(inputShape, outputShape) {}
721 : TestQuantization(options, inputShape, outputShape) {}
729 const char* name =
nullptr)
override 731 boost::ignore_unused(desc, name);
735 TestQuantizationParams(
754 std::vector<float> meanData{-1.0f, 1.5f, 2.0f};
755 std::vector<float> varData{-1.0f, 1.5f, 2.0f};
756 std::vector<float> betaData{-1.0f, 1.5f, 2.0f};
757 std::vector<float> gammaData{-1.0f, 1.5f, 2.0f};
768 IConnectableLayer* batchNorm = network->AddBatchNormalizationLayer(desc, mean, var, beta, gamma);
780 TestBatchNormalizationQuantization validatorQAsymmU8(shape, shape);
785 TestBatchNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
790 TestBatchNormalizationQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
795 TestBatchNormalizationQuantization validatorQSymmS16(QQsymm16Options, shape, shape);
801 class TestDepthToSpaceQuantization :
public TestQuantization
805 : TestQuantization(inputShape, outputShape) {}
810 : TestQuantization(options, inputShape, outputShape) {}
814 const char* name =
nullptr)
816 boost::ignore_unused(desc, name);
824 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
838 IConnectableLayer* depthToSpaceLayer = network->AddDepthToSpaceLayer(descriptor);
849 TestDepthToSpaceQuantization validatorQAsymmU8(inputShape, outputShape);
855 TestDepthToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
861 TestDepthToSpaceQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
867 TestDepthToSpaceQuantization validatorQSymmS16(Qsymm16Options, inputShape, outputShape);
880 VisitLayers(inputLayers, overrideInputRangeVisitor);
895 VisitLayers(inputLayers, overrideInputRangeVisitor);
929 VisitLayers(inputLayers, overrideInputRangeVisitorLayer3);
936 VisitLayers(inputLayers, overrideInputRangeVisitorLayer1);
962 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
969 std::vector<float> biasData{10.0f, 20.0f, 30.0f};
975 fullyConnected = network->AddFullyConnectedLayer(desc, weights, optionalBias);
980 fullyConnected->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
984 fullyConnected->GetOutputSlot(0).SetTensorInfo(outputInfo);
991 class TestFullyConnectedQuantization :
public TestQuantization
995 : TestQuantization(inputShape, outputShape) {}
1000 : TestQuantization(options, inputShape, outputShape) {}
1006 const char* name =
nullptr)
override 1008 boost::ignore_unused(desc, name);
1009 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1017 TestFullyConnectedQuantization validatorQAsymmU8(shape, shape);
1022 TestFullyConnectedQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1027 TestFullyConnectedQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1032 TestFullyConnectedQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1048 class TestConv2dQuantization :
public TestQuantization
1052 : TestQuantization(inputShape, outputShape) {}
1057 : TestQuantization(options, inputShape, outputShape) {}
1063 const char *name =
nullptr)
override 1065 boost::ignore_unused(convolution2dDescriptor, name);
1066 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1075 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1085 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1091 conv2d = network->AddConvolution2dLayer(descriptor, weights, optionalBiases);
1096 conv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1100 conv2d->GetOutputSlot(0).SetTensorInfo(info);
1103 TestConv2dQuantization validatorQAsymmU8(shape, shape);
1108 TestConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1113 TestConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1118 TestConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1134 class TestDepthwiseConv2dQuantization :
public TestQuantization
1138 : TestQuantization(inputShape, outputShape) {}
1143 : TestQuantization(options, inputShape, outputShape) {}
1149 const char *name =
nullptr)
override 1151 boost::ignore_unused(convolution2dDescriptor, name);
1152 TestQuantizationOnLayersWithBiases(layer, weights, biases);
1161 std::vector<float> weightsData{-1.0f, 1.5f, 2.0f};
1171 std::vector<float> biasesData{-1.0f, 1.5f, 2.0f};
1177 depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases);
1182 depthwiseConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
1186 depthwiseConv2d->GetOutputSlot(0).SetTensorInfo(info);
1189 TestDepthwiseConv2dQuantization validatorQAsymmU8(shape, shape);
1194 TestDepthwiseConv2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1199 TestDepthwiseConv2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1204 TestDepthwiseConv2dQuantization validatorQSymmS16(Qsymm16Options, shape, shape);
1220 class TestInstanceNormalizationQuantization :
public TestQuantization
1224 : TestQuantization(inputShape, outputShape) {}
1229 : TestQuantization(options, inputShape, outputShape) {}
1233 const char* name =
nullptr)
1235 boost::ignore_unused(descriptor, name);
1243 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1264 TestInstanceNormalizationQuantization validatorQAsymmU8(tensorShape, tensorShape);
1270 TestInstanceNormalizationQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1276 TestInstanceNormalizationQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1282 TestInstanceNormalizationQuantization validatorQSymmS16(qSymmS16Options, tensorShape, tensorShape);
1288 class TestLogSoftmaxQuantization :
public TestQuantization
1292 : TestQuantization(inputShape, outputShape) {}
1297 : TestQuantization(options, inputShape, outputShape) {}
1301 const char* name =
nullptr)
override 1303 boost::ignore_unused(descriptor, name);
1311 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1321 descriptor.
m_Beta = 1.0f;
1335 TestLogSoftmaxQuantization validatorQAsymmU8(tensorShape, tensorShape);
1341 TestLogSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1347 TestLogSoftmaxQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1353 TestLogSoftmaxQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
1380 class TestSoftmaxQuantization :
public TestQuantization
1384 : TestQuantization(inputShape, outputShape) {}
1389 : TestQuantization(options, inputShape, outputShape) {}
1393 const char* name =
nullptr)
override 1395 boost::ignore_unused(descriptor, name);
1407 descriptor.
m_Beta = 1.0f;
1413 TestSoftmaxQuantization validatorQAsymmU8(shape, shape);
1418 TestSoftmaxQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1424 TestSoftmaxQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1429 TestSoftmaxQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1478 activationDescriptor.
m_A = 3.5f;
1479 activationDescriptor.
m_B = -10.0f;
1513 class TestPermuteQuantization :
public TestLeakyReLuActivationQuantization
1517 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1522 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1526 const char* name =
nullptr)
override 1528 boost::ignore_unused(desc, name);
1529 CheckForwardedQuantizationSettings(layer);
1547 TestPermuteQuantization validatorQAsymmU8(shape, shape);
1552 TestPermuteQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1557 TestPermuteQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1562 TestPermuteQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1568 class TestSpaceToBatchQuantization :
public TestLeakyReLuActivationQuantization
1572 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1577 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1581 const char* name =
nullptr)
override 1583 boost::ignore_unused(spaceToBatchNdDescriptor, name);
1584 CheckForwardedQuantizationSettings(layer);
1602 TestSpaceToBatchQuantization validatorQAsymmU8(shape, shape);
1607 TestSpaceToBatchQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1612 TestSpaceToBatchQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1617 TestSpaceToBatchQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1623 class TestSpaceToDepthQuantization :
public TestLeakyReLuActivationQuantization
1627 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
1633 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
1638 const char* =
nullptr)
override 1641 TestQuantizationParams(info,
1660 TestSpaceToDepthQuantization validatorQAsymmU8(shape, shape);
1665 TestSpaceToDepthQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1670 TestSpaceToDepthQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1675 TestSpaceToDepthQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1681 class TestPooling2dQuantization :
public TestLeakyReLuActivationQuantization
1685 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
1690 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
1694 const char* name =
nullptr)
override 1696 boost::ignore_unused(desc, name);
1697 CheckForwardedQuantizationSettings(layer);
1709 activationDescriptor.
m_A = 3.5f;
1710 activationDescriptor.
m_B = -10.0f;
1714 IConnectableLayer* activation = network->AddActivationLayer(activationDescriptor);
1729 TestPooling2dQuantization validatorQAsymmU8(shape, shape);
1734 TestPooling2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1739 TestPooling2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1744 TestPooling2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1750 class TestConstantQuantization :
public TestAdditionQuantization
1754 : TestAdditionQuantization(inputShape, outputShape) {}
1759 : TestAdditionQuantization(options, inputShape, outputShape) {}
1763 const char* name =
nullptr)
override 1765 boost::ignore_unused(input, name);
1779 std::vector<float> data = {-2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
1801 TestConstantQuantization validatorQAsymmU8(shape, shape);
1806 TestConstantQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
1811 TestConstantQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
1816 TestConstantQuantization validatorQSymmS16(qSymmS16options, shape, shape);
1822 class TestArgMinMaxQuantization :
public TestQuantization
1826 TestQuantization(inputShape, outputShape) {}
1831 TestQuantization(options, inputShape, outputShape)
1836 const char* name =
nullptr)
override 1838 boost::ignore_unused(layer,
id, name);
1843 const char* name =
nullptr)
override 1845 boost::ignore_unused(layer,
id, name);
1849 const char* name =
nullptr)
override 1851 boost::ignore_unused(argMinMaxDescriptor, name);
1854 TestQuantizationParams(outputInfo,
1876 IConnectableLayer* argMinMaxLayer = network->AddArgMinMaxLayer(argMinMaxDescriptor);
1890 TestArgMinMaxQuantization validatorQAsymmU8(inputShape, outputShape);
1895 TestArgMinMaxQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, outputShape);
1900 TestArgMinMaxQuantization validatorQSymmS8(qSymmS8Options, inputShape, outputShape);
1905 TestArgMinMaxQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
1911 class TestComparisonQuantization :
public TestQuantization
1915 : TestQuantization(inputShape, outputShape) {}
1920 : TestQuantization(options, inputShape, outputShape) {}
1924 const char* name =
nullptr)
override 1926 boost::ignore_unused(descriptor, name);
1934 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
1959 TestComparisonQuantization validatorQAsymmU8(tensorShape, tensorShape);
1965 TestComparisonQuantization validatorQAsymmS8(qAsymmS8Options, tensorShape, tensorShape);
1971 TestComparisonQuantization validatorQSymmS8(qSymmS8Options, tensorShape, tensorShape);
1977 TestComparisonQuantization validatorQSymmS16(qSymmS16options, tensorShape, tensorShape);
1983 class TestConcatQuantization :
public TestQuantization
1987 : TestQuantization(inputShape, outputShape) {}
1992 : TestQuantization(options, inputShape, outputShape) {}
1996 const char* name =
nullptr)
override 1998 boost::ignore_unused(layer,
id, name);
2002 const char* name =
nullptr)
override 2004 boost::ignore_unused(layer,
id, name);
2008 const char* name =
nullptr)
override 2010 boost::ignore_unused(originsDescriptor, name);
2012 TestQuantizationParams(
2022 TestDifferentQuantizationScale(inputInfo0, inputInfo1);
2023 TestDifferentQuantizationScale(inputInfo0, inputInfo2);
2024 TestDifferentQuantizationScale(inputInfo1, inputInfo2);
2025 TestDifferentQuantizationScale(inputInfo0, outputInfo);
2064 quantizerPtrQAsymmU8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2065 quantizerPtrQAsymmU8->OverrideInputRange(1, (min + 6.7f), max);
2066 quantizerPtrQAsymmU8->OverrideInputRange(2, min, (max - 7.8f));
2068 quantizerPtrQSymmS8->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2069 quantizerPtrQSymmS8->OverrideInputRange(1, (min + 6.7f), max);
2070 quantizerPtrQSymmS8->OverrideInputRange(2, min, (max - 7.8f));
2072 quantizerPtrQSymmS16->OverrideInputRange(0, (min + 2.1f), (max - 3.2f));
2073 quantizerPtrQSymmS16->OverrideInputRange(1, (min + 6.7f), max);
2074 quantizerPtrQSymmS16->OverrideInputRange(2, min, (max - 7.8f));
2076 INetworkPtr quantizedNetworkQAsymmU8 = quantizerPtrQAsymmU8->ExportNetwork();
2077 TestConcatQuantization validatorQAsymmU8(shape, shape);
2080 INetworkPtr quantizedNetworkQSymmS8 = quantizerPtrQSymmS8->ExportNetwork();
2081 TestConcatQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2084 INetworkPtr quantizedNetworkQSymmS16 = quantizerPtrQSymmS16->ExportNetwork();
2085 TestConcatQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2091 class TestReshapeQuantization :
public TestLeakyReLuActivationQuantization
2095 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2100 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2104 const char* name =
nullptr)
override 2106 boost::ignore_unused(reshapeDescriptor, name);
2107 CheckForwardedQuantizationSettings(layer);
2125 TestReshapeQuantization validatorQAsymmU8(shape, shape);
2130 TestReshapeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2135 TestReshapeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2140 TestReshapeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2146 class TestSplitterQuantization :
public TestLeakyReLuActivationQuantization
2150 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2155 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2159 const char* name =
nullptr)
2161 boost::ignore_unused(desc, name);
2162 CheckForwardedQuantizationSettings(layer);
2179 TestSplitterQuantization validatorQAsymmU8(shape, shape);
2184 TestSplitterQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2189 TestSplitterQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2194 TestSplitterQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2200 class TestResizeQuantization :
public TestLeakyReLuActivationQuantization
2204 : TestLeakyReLuActivationQuantization(inputShape, outputShape)
2210 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
2215 const char* name =
nullptr)
override 2217 boost::ignore_unused(resizeDescriptor, name);
2218 CheckForwardedQuantizationSettings(layer);
2232 descriptor.m_TargetWidth = 3;
2238 TestResizeQuantization validatorQAsymmU8(shape, shape);
2243 TestResizeQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2248 TestResizeQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2253 TestResizeQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2259 class TestStridedSliceQuantization :
public TestLeakyReLuActivationQuantization
2263 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2268 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2272 const char* name =
nullptr)
2274 boost::ignore_unused(desc, name);
2275 CheckForwardedQuantizationSettings(layer);
2288 IConnectableLayer* stridedSlice = network->AddStridedSliceLayer(stridedSliceDesc);
2293 TestStridedSliceQuantization validatorQAsymmU8(shape, shape);
2298 TestStridedSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2303 TestStridedSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2308 TestStridedSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2314 class TestBatchToSpaceQuantization :
public TestLeakyReLuActivationQuantization
2318 : TestLeakyReLuActivationQuantization(inputShape, outputShape) {}
2323 : TestLeakyReLuActivationQuantization(options, inputShape, outputShape) {}
2327 const char* name =
nullptr)
override 2329 boost::ignore_unused(batchToSpaceNdDescriptor, name);
2330 CheckForwardedQuantizationSettings(layer);
2348 TestBatchToSpaceQuantization validatorQAsymmU8(shape, shape);
2353 TestBatchToSpaceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2358 TestBatchToSpaceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2363 TestBatchToSpaceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2369 class TestPreluQuantization :
public TestQuantization
2372 TestPreluQuantization(
const TensorShape& inputShape,
2375 : TestQuantization(inputShape, outputShape)
2376 , m_AlphaShape(alphaShape)
2383 : TestQuantization(options, inputShape, outputShape)
2384 , m_AlphaShape(alphaShape)
2389 const char* name =
nullptr)
override 2391 boost::ignore_unused(
id, name);
2397 BOOST_TEST(m_InputShape == info.
GetShape());
2400 BOOST_TEST(m_AlphaShape == info.
GetShape());
2407 TestQuantizationParams(info,
2416 const char* name =
nullptr)
override 2418 boost::ignore_unused(
id, name);
2420 BOOST_TEST(m_OutputShape == info.
GetShape());
2424 const char* name =
nullptr)
override 2426 boost::ignore_unused(name);
2428 TestQuantizationParams(info,
2469 TestPreluQuantization validatorQAsymmU8(inputShape, alphaShape, outputShape);
2474 TestPreluQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, alphaShape, outputShape);
2479 TestPreluQuantization validatorQSymmS8(qSymmS8Options, inputShape, alphaShape, outputShape);
2484 TestPreluQuantization validatorQSymmS16(qSymmS16options, inputShape, alphaShape, outputShape);
2490 class TestTransposeConvolution2dQuantization :
public TestQuantization
2494 TestQuantization(inputShape, outputShape)
2500 TestQuantization(options, inputShape, outputShape)
2507 const char *name =
nullptr)
override 2509 boost::ignore_unused(descriptor, name);
2510 TestQuantizationOnLayersWithBiases(layer, weights, biases);
2519 std::initializer_list<float> floatData{ -1.0f, 1.5f, 2.0f };
2520 std::vector<float> weightsData(floatData);
2529 std::vector<float> biasesData(floatData);
2535 IConnectableLayer* transposeConv2d = network->AddTransposeConvolution2dLayer(descriptor, weights, optionalBiases);
2539 transposeConv2d->GetOutputSlot(0).Connect(output->
GetInputSlot(0));
2542 transposeConv2d->GetOutputSlot(0).SetTensorInfo(info);
2546 TestTransposeConvolution2dQuantization validatorQAsymmU8(shape, shape);
2552 TestTransposeConvolution2dQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2558 TestTransposeConvolution2dQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2564 TestTransposeConvolution2dQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2580 class TestStackQuantization :
public TestQuantization
2583 TestStackQuantization(
const TensorShape& inputShape,
2585 : TestQuantization(inputShape, outputShape) {}
2590 : TestQuantization(options, inputShape, outputShape) {}
2594 const char* name =
nullptr)
override 2596 boost::ignore_unused(layer,
id, name);
2600 const char* name =
nullptr)
override 2602 boost::ignore_unused(layer,
id, name);
2607 const char* name =
nullptr)
override 2609 boost::ignore_unused(descriptor, name);
2612 TestQuantizationParams(outputInfo,
2638 TestStackQuantization validatorQAsymmU8(inputShape, outputShape);
2643 TestStackQuantization validatorQAsymmS8(qAsymmS8Options, inputShape, inputShape);
2648 TestStackQuantization validatorQSymmS8(qSymmS8Options, inputShape, inputShape);
2653 TestStackQuantization validatorQSymmS16(qSymmS16options, inputShape, outputShape);
2659 class TestSliceQuantization :
public TestQuantization
2663 : TestQuantization(inputShape, outputShape)
2669 : TestQuantization(options, inputShape, outputShape)
2674 const char* name =
nullptr)
2676 boost::ignore_unused(desc, name);
2684 TestQuantizationParams(info, qAsymmU8Params, qAsymmS8Params, qSymmS8Params, qSymmS16Params);
2705 TestSliceQuantization validatorQAsymmU8(shape, shape);
2711 TestSliceQuantization validatorQAsymmS8(qAsymmS8Options, shape, shape);
2717 TestSliceQuantization validatorQSymmS8(qSymmS8Options, shape, shape);
2723 TestSliceQuantization validatorQSymmS16(qSymmS16options, shape, shape);
2731 inputInfo.SetQuantizationOffset(1);
2732 std::vector<float> input({ value, 0.0f, 0.0f, 1.0f });
2733 const std::vector<float> &inputRef = input;
2735 auto output = armnnUtils::QuantizedVector<uint8_t>(inputRef,
2736 inputInfo.GetQuantizationScale(),
2737 inputInfo.GetQuantizationOffset());
2744 BOOST_CHECK_EQUAL(
SetupQuantize(std::numeric_limits<float>::infinity())[0], 255);
2749 BOOST_CHECK_EQUAL(
SetupQuantize(-1 * std::numeric_limits<float>::infinity())[0], 0);
2752 class TestPreserveType :
public TestAdditionQuantization
2759 : TestAdditionQuantization(options, inputShape, outputShape)
2760 , m_DataType(dataType)
2761 , m_VisitedQuantizeLayer(
false)
2762 , m_VisitedDequantizeLayer(
false) {}
2766 const char* name =
nullptr)
override 2768 boost::ignore_unused(
id, name);
2771 BOOST_TEST(m_InputShape == info.
GetShape());
2776 const char* name =
nullptr)
override 2778 boost::ignore_unused(
id, name);
2781 BOOST_TEST(m_OutputShape == info.
GetShape());
2785 const char* name =
nullptr)
override 2787 boost::ignore_unused(layer, name);
2788 m_VisitedQuantizeLayer =
true;
2792 const char* name =
nullptr)
override 2794 boost::ignore_unused(layer, name);
2795 m_VisitedDequantizeLayer =
true;
2798 void CheckQuantizeDequantizeLayerVisited(
bool expected)
2813 bool m_VisitedQuantizeLayer;
2814 bool m_VisitedDequantizeLayer;
2841 TestPreserveType validatorQAsymmU8(options, dataType, shape, shape);
2843 validatorQAsymmU8.CheckQuantizeDequantizeLayerVisited(
2869 class TestConnectionPreservation :
public LayerVisitorBase<VisitorNoThrowPolicy>
2872 TestConnectionPreservation(
const Graph& graph)
2883 void CheckLayerName(
LayerGuid guid, std::string expectedName)
2885 bool guidFound =
false;
2886 for (
Layer* layer : m_Graph)
2890 BOOST_CHECK_EQUAL(layer->
GetName(), expectedName.c_str());
2897 BOOST_FAIL(
"No layer matching the GUID was found");
2927 TestConnectionPreservation visitor1(boost::polymorphic_downcast<const Network*>(network.get())->GetGraph());
2934 std::vector<float> inputData({0, 2, 0, 4});
2938 inputTensors.push_back(std::make_pair(0, inputTensor));
2939 quantizer->Refine(inputTensors);
2941 INetworkPtr quantNetwork = quantizer->ExportNetwork();
2943 TestConnectionPreservation visitor2(boost::polymorphic_downcast<const Network*>(quantNetwork.get())->GetGraph());
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH).
INetworkPtr CreateNetworkWithFullyConnectedLayer(const bool biasEnabled, const TensorShape &inputShape, const TensorShape &outputShape)
const float g_SymmS16QuantizationBase
virtual LayerGuid GetGuid() const =0
const float g_SymmS8QuantizationBase
void ValidateFullyConnectedLayer(const bool biasEnabled)
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
int32_t GetQuantizationOffset() const
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
virtual const TensorInfo & GetTensorInfo() const =0
void PreserveTypeTestImpl(const DataType &dataType)
uint32_t m_NumOutputs
Number of output tensors.
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
void VisitLayers(const LayerContainer &layerContainer, ILayerVisitor &visitor)
std::vector< MinMaxRange > MinMaxRanges
uint32_t m_TargetHeight
Target height value.
TensorInfo GetInputTensorInfo(const Network *network)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
An ActivationDescriptor for the ActivationLayer.
const float g_TestTolerance
std::pair< float, float > MinMaxRange
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
void QuantizeConstant(const srcType *src, uint8_t *dst, size_t numElements, float &scale, int &offset)
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
bool IsEmpty() const
Query function to check that the RangeTracker is empty.
bool m_BiasEnabled
Enable/disable bias.
A ViewsDescriptor for the SplitterLayer. Descriptor to configure the splitting process. Number of Views must be equal to the number of outputs, and their order must match - e.g. first view corresponds to the first output, second view to the second output, etc.
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
IConnectableLayer * CreateStartOfLeakyReluNetwork(INetwork *network, const TensorInfo &info)
virtual LayerGuid GetOwningLayerGuid() const =0
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
virtual const char * GetName() const =0
void TestQuantizeDepthwiseConvolution2d(bool useBiases)
float m_Beta
Exponentiation value.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
A ReshapeDescriptor for the ReshapeLayer.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
std::pair< float, float > MinMaxRange
virtual IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)=0
bool HasRanges(LayerGuid guid) const
Query that there is an entry for a layer.
Private implementation of INetwork.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
std::unique_ptr< class INetworkQuantizer, void(*)(INetworkQuantizer *quantizer)> INetworkQuantizerPtr
INetworkPtr CreateNetworkWithActivationLayer(const ActivationDescriptor &descriptor, const TensorShape &shape)
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
void VisitLayersTopologically(const INetwork *inputNetwork, ILayerVisitor &visitor)
void SetQuantizationScale(float scale)
INetworkPtr CreateNetworkWithInputOutputLayers()
static INetworkPtr Create()
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
A FullyConnectedDescriptor for the FullyConnectedLayer.
InputLayersAccessor GetInputLayers() const
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
bool m_BiasEnabled
Enable/disable bias.
const Graph & GetGraph() const
std::unordered_map< LayerGuid, MinMaxRanges > MinMaxRangeMap
const TensorInfo & GetInfo() const
A StackDescriptor for the StackLayer.
BOOST_AUTO_TEST_SUITE_END()
uint32_t m_NumInputs
Number of input tensors.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square).
A SoftmaxDescriptor for the SoftmaxLayer.
const float g_AsymmS8QuantizationBase
bool m_BiasEnabled
Enable/disable bias.
static INetworkQuantizerPtr Create(INetwork *inputNetwork, const QuantizerOptions &options=QuantizerOptions())
Create Quantizer object wrapped in unique_ptr.
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
DataType GetDataType() const
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
void TestQuantizeConvolution2d(bool useBiases)
const float g_AsymmU8QuantizationBase
A Pooling2dDescriptor for the Pooling2dLayer.
A StandInDescriptor for the StandIn layer.
A SliceDescriptor for the SliceLayer.
bool m_BiasEnabled
Enable/disable bias.
virtual IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)=0
virtual IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)=0
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
std::pair< float, int > OffsetScalePair
A PermuteDescriptor for the PermuteLayer.
INetworkPtr CreateNetworkWithSoftmaxLayer(const SoftmaxDescriptor &descriptor, const TensorShape &shape)
A Convolution2dDescriptor for the Convolution2dLayer.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
void CompleteLeakyReluNetwork(INetwork *network, IConnectableLayer *activation, IConnectableLayer *layerUnderTest, const TensorInfo &info)
virtual int Connect(IInputSlot &destination)=0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
std::vector< uint8_t > SetupQuantize(float value)
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
void TestQuantizeTransposeConvolution2d(bool useBiases)
const TensorShape & GetShape() const
An ArgMinMaxDescriptor for ArgMinMaxLayer.
bool has_value() const noexcept
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
constexpr const char * GetDataTypeName(DataType dataType)
A ResizeDescriptor for the ResizeLayer.
A ComparisonDescriptor for the ComparisonLayer.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
float GetQuantizationScale() const
An OriginsDescriptor for the ConcatLayer. Descriptor to configure the concatenation process...
A StridedSliceDescriptor for the StridedSliceLayer.