aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/QuantizerVisitor.hpp
diff options
context:
space:
mode:
authorDerek Lamberti <derek.lamberti@arm.com>2019-02-05 16:00:08 +0000
committerDerek Lamberti <derek.lamberti@arm.com>2019-02-06 10:38:09 +0000
commit27d830720ed706f187f2a40e2c5055e424aa8b91 (patch)
tree7aac5ae83c79bf53e69f5951871f5cafd232d0a3 /src/armnn/QuantizerVisitor.hpp
parentf08876fce2b472a8c31f09d976fbcfeaaa94d228 (diff)
downloadarmnn-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/QuantizerVisitor.hpp')
-rw-r--r--src/armnn/QuantizerVisitor.hpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/armnn/QuantizerVisitor.hpp b/src/armnn/QuantizerVisitor.hpp
new file mode 100644
index 0000000000..bf017d7205
--- /dev/null
+++ b/src/armnn/QuantizerVisitor.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "LayerVisitorBase.hpp"
+#include <armnn/INetwork.hpp>
+#include <armnn/Types.hpp>
+
+#include <map>
+
+namespace armnn
+{
+
+// Forward declarations
+class StaticRangeVisitor;
+
+/// Visitor object for quantizing layers in a network
+class QuantizerVisitor : public LayerVisitorBase
+{
+public:
+ QuantizerVisitor(StaticRangeVisitor* ranges);
+ ~QuantizerVisitor() = default;
+
+ // Functions to quantize the individual layers, overridden from ILayerVisitor
+ void VisitInputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name = nullptr) override;
+ void VisitAdditionLayer(const IConnectableLayer *layer, const char *name = nullptr) override;
+ void VisitOutputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name = nullptr) override;
+
+ // Extract the quantized network
+ INetworkPtr RetrieveFinalNetwork() { return std::move(m_QuantizedNetwork); }
+private:
+
+ /// Connects the layer to preceeding layers and sets the quantization parameters based on recorded ranges
+ void SetQuantizedInputConnections(const IConnectableLayer *srcLayer, IConnectableLayer *quantizedLayer);
+
+ /// Record the guid so we can easily find it later
+ void RecordLayer(IConnectableLayer* layer);
+
+
+ StaticRangeVisitor* m_Ranges; ///< Previously recorded min/max ranges per intermediate tensor
+ INetworkPtr m_QuantizedNetwork; ///< Quantized version of the model we are building up
+
+ std::map<LayerGuid, LayerGuid> m_OldToNewGuidMap; ///< Mapping from input network guids to quantized network guids
+ std::map<LayerGuid, IConnectableLayer*> m_GuidToLayerMap; ///< Mapping from guid to layer in quantized network
+};
+
+} //namespace armnn \ No newline at end of file