diff options
author | Derek Lamberti <derek.lamberti@arm.com> | 2019-02-05 16:00:08 +0000 |
---|---|---|
committer | Derek Lamberti <derek.lamberti@arm.com> | 2019-02-06 10:38:09 +0000 |
commit | 27d830720ed706f187f2a40e2c5055e424aa8b91 (patch) | |
tree | 7aac5ae83c79bf53e69f5951871f5cafd232d0a3 /src/armnn/NetworkQuantizer.cpp | |
parent | f08876fce2b472a8c31f09d976fbcfeaaa94d228 (diff) | |
download | armnn-27d830720ed706f187f2a40e2c5055e424aa8b91.tar.gz |
IVGCVSW-2606 Produce quantized InputNetwork from simple FP32 InputNetwork
Change-Id: I2140a7af5961ddf8267fbb127202de3900ea79e3
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'src/armnn/NetworkQuantizer.cpp')
-rw-r--r-- | src/armnn/NetworkQuantizer.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/armnn/NetworkQuantizer.cpp b/src/armnn/NetworkQuantizer.cpp new file mode 100644 index 0000000000..f8e5ed23a7 --- /dev/null +++ b/src/armnn/NetworkQuantizer.cpp @@ -0,0 +1,63 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <armnn/ILayerVisitor.hpp> +#include <armnn/INetwork.hpp> +#include <armnn/Tensor.hpp> +#include <armnn/Types.hpp> + +#include "Graph.hpp" +#include "Layer.hpp" +#include "Network.hpp" +#include "NetworkQuantizer.hpp" + +#include "StaticRangeVisitor.hpp" +#include "QuantizerVisitor.hpp" + +#include <map> +#include <vector> +#include <cmath> + +namespace armnn +{ + +INetworkQuantizer* INetworkQuantizer::CreateRaw(INetwork *inputNetwork) +{ + return new NetworkQuantizer(inputNetwork); +} + +INetworkQuantizerPtr INetworkQuantizer::Create(INetwork* inputNetwork) +{ + return INetworkQuantizerPtr(CreateRaw(inputNetwork), &INetworkQuantizer::Destroy); +} + +void INetworkQuantizer::Destroy(INetworkQuantizer *quantizer) +{ + delete boost::polymorphic_downcast<NetworkQuantizer*>(quantizer); +} + +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); + + // Step 2) Convert input InputNetwork to Quantized InputNetwork + QuantizerVisitor quantizerVisitor(&rangeVisitor); + VisitLayers(quantizerVisitor); + + return quantizerVisitor.RetrieveFinalNetwork(); +} + +} //namespace armn
\ No newline at end of file |