diff options
author | Francis Murtagh <francis.murtagh@arm.com> | 2019-02-22 16:35:13 +0000 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2019-02-25 09:46:01 +0000 |
commit | 0d0a78ebd60e058746ea161914b45709245d4e1b (patch) | |
tree | 0220a0e885a81dd33e3e770f9dc7c02091eb4159 /src/armnn/test/QuantizerTest.cpp | |
parent | d1ae3a632af09cd065d983a51c40916e2202121d (diff) | |
download | armnn-0d0a78ebd60e058746ea161914b45709245d4e1b.tar.gz |
IVGCVSW-2721 Quantize and Dequantize aren't quite right
* Add check for infinity and negative infinity in quantize()
* Add assert for NaN value in quantize and dequantize()
* Add unit tests for infinity and negative infinity
Change-Id: Ie60e1e15b289ccbf99df4a3281f067b82cc9f9bf
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Diffstat (limited to 'src/armnn/test/QuantizerTest.cpp')
-rw-r--r-- | src/armnn/test/QuantizerTest.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/armnn/test/QuantizerTest.cpp b/src/armnn/test/QuantizerTest.cpp index 548203a6a9..fcce208c59 100644 --- a/src/armnn/test/QuantizerTest.cpp +++ b/src/armnn/test/QuantizerTest.cpp @@ -14,6 +14,7 @@ #include "../NetworkQuantizerUtils.hpp" #include "../OverrideInputRangeVisitor.hpp" #include "../RangeTracker.hpp" +#include "../backends/backendsCommon/test/QuantizeHelper.hpp" #include <boost/test/unit_test.hpp> @@ -1215,5 +1216,33 @@ BOOST_AUTO_TEST_CASE(QuantizeBatchToSpace) VisitLayersTopologically(quantizedNetwork.get(), validator); } +std::vector<uint8_t> SetupQuantize(float value) +{ + armnn::TensorInfo inputInfo({ 1, 2, 2 }, armnn::DataType::Float32); + inputInfo.SetQuantizationScale(1.0f); + inputInfo.SetQuantizationOffset(1); + std::vector<float> input({ + value, 0.0f, + 0.0f, 1.0f + }); + const std::vector<float> &inputRef = input; + + auto output = QuantizedVector<uint8_t>(inputInfo.GetQuantizationScale(), + inputInfo.GetQuantizationOffset(), + inputRef); + + return output; +} + +BOOST_AUTO_TEST_CASE(QuantizeInf) +{ + BOOST_CHECK_EQUAL(SetupQuantize(std::numeric_limits<float>::infinity())[0], 255); +} + +BOOST_AUTO_TEST_CASE(QuantizeNegativeInf) +{ + BOOST_CHECK_EQUAL(SetupQuantize(-1 * std::numeric_limits<float>::infinity())[0], 0); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace armnn |