ArmNN
 20.02
NetworkQuantizer.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/INetwork.hpp>
10 #include <armnn/IRuntime.hpp>
11 #include <armnn/Types.hpp>
12 #include <armnn/Optional.hpp>
13 
15 #include "RangeTracker.hpp"
16 
17 namespace armnn
18 {
19 
21 {
22 public:
24  : m_InputNetwork(inputNetwork),
25  m_NetworkId(0),
26  m_Runtime(nullptr, &IRuntime::Destroy),
27  m_RefineCount(0),
28  m_Options(options) {}
29 
30  void OverrideInputRange(LayerBindingId layerId, float min, float max) override;
31  void Refine(const InputTensors& inputTensors) override;
32 
33  // Required for testing? Need some way to get min/max in RangeTracker (m_Ranges)
34  std::pair<float, float> GetMinMaxRange(LayerGuid guid, unsigned int idx) { return m_Ranges.GetRange(guid, idx); }
35  INetworkPtr ExportNetwork() override;
36 
37 private:
38  /// Original input network to quantize
39  INetwork* m_InputNetwork;
40 
41  NetworkId m_NetworkId;
42 
43  // if we are run in dynamic mode this unique pointer will hold
44  // the runtime between invocations of the Refine method.
45  IRuntimePtr m_Runtime;
46 
47  Optional<DynamicQuantizationVisitor> m_DynamicQuantizationVisitor;
48 
49  // counts the number of times refine is called
50  unsigned int m_RefineCount;
51 
52  /// Mapping from Guid to an array of ranges for outputs
53  RangeTracker m_Ranges;
54 
55  /// Options for the NetworkQuantizer
56  QuantizerOptions m_Options;
57 
58  std::pair<float, float> FindMinMax(ITensorHandle* tensorHandle);
59 };
60 
61 } //namespace armnn
NetworkQuantizer(INetwork *inputNetwork, const QuantizerOptions &options)
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:225
int NetworkId
Definition: IRuntime.hpp:19
Copyright (c) 2020 ARM Limited.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:171
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
static void Destroy(INetworkQuantizer *quantizer)
Destroy Quantizer object.
std::pair< float, float > GetMinMaxRange(LayerGuid guid, unsigned int idx)
void Refine(const InputTensors &inputTensors) override
Refine input network with a set of refinement data for specified LayerBindingId.
void OverrideInputRange(LayerBindingId layerId, float min, float max) override
Overrides the default quantization values for the input layer with the given id.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
Quantizer class Quantizes a float32 InputNetwork.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
INetworkPtr ExportNetwork() override
Extract final quantized network.