diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-02-11 13:24:38 +0000 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-02-14 17:53:55 +0000 |
commit | 5b2159e43a5e078053e706883e3af44ae733b5b9 (patch) | |
tree | 6486b631f32c5f903ba609907ef3aa25002e3daa /src/armnn/StaticRangeVisitor.cpp | |
parent | ec333914d5d38079083bcdb7fc88a54a19ebaa87 (diff) | |
download | armnn-5b2159e43a5e078053e706883e3af44ae733b5b9.tar.gz |
IVGCVSW-2620 Support static quantization of Constant
* Added VisitConstantLayer to QuantizerVisitor
* Added unit tests and refactored QuantizerTest.cpp
* Code cleanup
Change-Id: I118fd2be085fc98879c5cfaa09698a7c98ba13f0
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Diffstat (limited to 'src/armnn/StaticRangeVisitor.cpp')
-rw-r--r-- | src/armnn/StaticRangeVisitor.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/armnn/StaticRangeVisitor.cpp b/src/armnn/StaticRangeVisitor.cpp index b1cbb2d574..cc1255e56e 100644 --- a/src/armnn/StaticRangeVisitor.cpp +++ b/src/armnn/StaticRangeVisitor.cpp @@ -9,6 +9,8 @@ #include <armnn/Descriptors.hpp> #include <armnn/Types.hpp> +#include <limits> + namespace armnn { @@ -150,4 +152,33 @@ void StaticRangeVisitor::VisitSoftmaxLayer(const IConnectableLayer* layer, SetRange(layer, 0, 0.f, 1.f); } +void StaticRangeVisitor::VisitConstantLayer(const IConnectableLayer* layer, + const ConstTensor& input, + const char* name) +{ + boost::ignore_unused(name); + + if (input.GetDataType() != DataType::Float32) + { + throw InvalidArgumentException("Quantization is supported only for FP32 tensors"); + } + + // Work out the range based on the input constants + unsigned int inputNumElements = input.GetNumElements(); + const float* inputData = reinterpret_cast<const float*>(input.GetMemoryArea()); + + float min = std::numeric_limits<float>::max(); + float max = std::numeric_limits<float>::lowest(); + + for (unsigned int i = 0; i < inputNumElements; i++) + { + const float inputValue = inputData[i]; + + min = std::min(min, inputValue); + max = std::max(max, inputValue); + } + + SetRange(layer, 0, min, max); +} + } //namespace armnn |