diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-02-07 17:51:09 +0000 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-02-08 12:23:05 +0000 |
commit | a8d572dc48f47e66cd7abd6ad9b2d3a0f40ea94b (patch) | |
tree | 5de7809a8fbc19d6d2a940a51a982bd633156945 /src/armnn/NetworkQuantizer.cpp | |
parent | e0a4ad8a8e6ef271883e8029985eeab16d838972 (diff) | |
download | armnn-a8d572dc48f47e66cd7abd6ad9b2d3a0f40ea94b.tar.gz |
IVGCVSW-2607 Implement Input range override mechanism
* Added the OverrideInputRange method to the Quantizer API
* Created OverrideInputRangeVisitor to implement the override mechanism
* Moved the quantizer utility functions to the new NetworkQuantizerUtils files
* Moved the map of quantization ranges out of the StaticRangeVisitor
and into the NetworkQuantizer
* Added unit tests
* Code refactoring and cleanup
Change-Id: I9c1d006c1b6a35fbc04584a832fbe489f8f9276d
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Diffstat (limited to 'src/armnn/NetworkQuantizer.cpp')
-rw-r--r-- | src/armnn/NetworkQuantizer.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/armnn/NetworkQuantizer.cpp b/src/armnn/NetworkQuantizer.cpp index f8e5ed23a7..ccbc501618 100644 --- a/src/armnn/NetworkQuantizer.cpp +++ b/src/armnn/NetworkQuantizer.cpp @@ -12,11 +12,12 @@ #include "Layer.hpp" #include "Network.hpp" #include "NetworkQuantizer.hpp" +#include "NetworkQuantizerUtils.hpp" #include "StaticRangeVisitor.hpp" #include "QuantizerVisitor.hpp" +#include "OverrideInputRangeVisitor.hpp" -#include <map> #include <vector> #include <cmath> @@ -38,26 +39,29 @@ void INetworkQuantizer::Destroy(INetworkQuantizer *quantizer) delete boost::polymorphic_downcast<NetworkQuantizer*>(quantizer); } +void NetworkQuantizer::OverrideInputRange(LayerBindingId layerId, float min, float max) +{ + const Graph& graph = boost::polymorphic_downcast<const Network*>(m_InputNetwork)->GetGraph(); + auto inputLayers = graph.GetInputLayers(); + + // Walk the input layers of the graph and override the quantization parameters of the one with the given id + OverrideInputRangeVisitor overrideInputRangeVisitor(m_GuidToRangesMap, layerId, MinMaxRange{min, max}); + VisitLayers(inputLayers, overrideInputRangeVisitor); +} + INetworkPtr NetworkQuantizer::ExportNetwork() { const Graph& graph = boost::polymorphic_downcast<const Network*>(m_InputNetwork)->GetGraph().TopologicalSort(); - auto VisitLayers = [&graph](ILayerVisitor& visitor) - { - for (auto layer : graph) - { - layer->Accept(visitor); - } - }; // Step 1) Walk the graph and register min/max values for intermediate tensors - StaticRangeVisitor rangeVisitor; - VisitLayers(rangeVisitor); + StaticRangeVisitor rangeVisitor(m_GuidToRangesMap); + VisitLayers(graph, rangeVisitor); // Step 2) Convert input InputNetwork to Quantized InputNetwork QuantizerVisitor quantizerVisitor(&rangeVisitor); - VisitLayers(quantizerVisitor); + VisitLayers(graph, quantizerVisitor); return quantizerVisitor.RetrieveFinalNetwork(); } -} //namespace armn
\ No newline at end of file +} //namespace armn |