aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/QuantizerVisitor.hpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-02-07 17:51:09 +0000
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-02-08 12:23:05 +0000
commita8d572dc48f47e66cd7abd6ad9b2d3a0f40ea94b (patch)
tree5de7809a8fbc19d6d2a940a51a982bd633156945 /src/armnn/QuantizerVisitor.hpp
parente0a4ad8a8e6ef271883e8029985eeab16d838972 (diff)
downloadarmnn-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/QuantizerVisitor.hpp')
-rw-r--r--src/armnn/QuantizerVisitor.hpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/armnn/QuantizerVisitor.hpp b/src/armnn/QuantizerVisitor.hpp
index 0dc45822b4..dcaccd4ac7 100644
--- a/src/armnn/QuantizerVisitor.hpp
+++ b/src/armnn/QuantizerVisitor.hpp
@@ -6,31 +6,34 @@
#pragma once
#include "LayerVisitorBase.hpp"
+#include "StaticRangeVisitor.hpp"
+
#include <armnn/INetwork.hpp>
#include <armnn/Types.hpp>
+#include <armnn/INetworkQuantizer.hpp>
-#include <map>
+#include <unordered_map>
namespace armnn
{
-// Forward declarations
+// Forward declaration
class StaticRangeVisitor;
/// Visitor object for quantizing layers in a network
class QuantizerVisitor : public LayerVisitorBase<VisitorNoThrowPolicy>
{
public:
- QuantizerVisitor(StaticRangeVisitor* ranges);
+ QuantizerVisitor(const StaticRangeVisitor* staticRangeVisitor);
~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 VisitActivationLayer(const IConnectableLayer *layer,
+ /// 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 VisitActivationLayer(const IConnectableLayer* layer,
const ActivationDescriptor& activationDescriptor,
- const char *name = nullptr) override;
- void VisitOutputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name = nullptr) override;
+ const char* name = nullptr) override;
+ void VisitOutputLayer(const IConnectableLayer* layer, LayerBindingId id, const char* name = nullptr) override;
void VisitBatchNormalizationLayer(const IConnectableLayer* layer,
const BatchNormalizationDescriptor& desc,
const ConstTensor& mean,
@@ -39,22 +42,27 @@ public:
const ConstTensor& gamma,
const char* name = nullptr) override;
- // Extract the quantized network
+ /// Extract the quantized network
INetworkPtr RetrieveFinalNetwork() { return std::move(m_QuantizedNetwork); }
-private:
+private:
/// Connects the layer to preceeding layers and sets the quantization parameters based on recorded ranges
- void SetQuantizedInputConnections(const IConnectableLayer *srcLayer, IConnectableLayer *quantizedLayer);
+ void SetQuantizedInputConnections(const IConnectableLayer* srcLayer, IConnectableLayer* quantizedLayer);
/// Record the guids so we can easily find the layers later
void RecordLayer(const IConnectableLayer* srcLayer, IConnectableLayer* qLayer);
+ /// Reference to the static range visitor used to retrieve the quantization ranges
+ const StaticRangeVisitor* m_StaticRangeVisitor;
+
+ /// Quantized version of the model we are building up
+ INetworkPtr m_QuantizedNetwork;
- StaticRangeVisitor* m_Ranges; ///< Previously recorded min/max ranges per intermediate tensor
- INetworkPtr m_QuantizedNetwork; ///< Quantized version of the model we are building up
+ /// Mapping from input network guids to quantized network guids
+ std::unordered_map<LayerGuid, LayerGuid> m_OriginalToQuantizedGuidMap;
- 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
+ /// Mapping from guid to layer in quantized network
+ std::unordered_map<LayerGuid, IConnectableLayer*> m_QuantizedGuidToLayerMap;
};
-} //namespace armnn \ No newline at end of file
+} //namespace armnn