ArmNN
 21.02
OverrideInputRangeVisitor.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 "NetworkQuantizer.hpp"
10 #include "RangeTracker.hpp"
11 
12 #include <unordered_map>
13 
14 namespace armnn
15 {
17 {
18 private:
19  using MinMaxRange = RangeTracker::MinMaxRange;
20 public :
22  LayerBindingId layerId,
23  const MinMaxRange& minMaxRange)
24  : m_Ranges(ranges)
25  , m_LayerId(layerId)
26  , m_MinMaxRange(minMaxRange){}
27 
28  ~OverrideInputRangeStrategy() = default;
29 
31  const BaseDescriptor& descriptor,
32  const std::vector<armnn::ConstTensor>& constants,
33  const char* name,
34  const armnn::LayerBindingId id) override
35  {
36  IgnoreUnused(name, constants, id, descriptor);
37 
38  switch (layer->GetType())
39  {
41  {
42  if (m_LayerId == id)
43  {
44  m_Ranges.SetRange(layer, 0, m_MinMaxRange.first, m_MinMaxRange.second);
45  }
46  break;
47  }
48  default:
49  {
50  std::cout << "dont know this one" << std::endl;
51  }
52  }
53  }
54 
55 private:
56  /// Mapping from a layer Guid to an array of ranges for outputs
57  RangeTracker& m_Ranges;
58 
59  /// The id of the input layer of which to override the input range
60  LayerBindingId m_LayerId;
61 
62  /// The new input range to be applied to the input layer
63  MinMaxRange m_MinMaxRange;
64 };
65 
66 
67 
68 /// Visitor object for overriding the input range of the quantized input layers in a network
69 class OverrideInputRangeVisitor : public LayerVisitorBase<VisitorNoThrowPolicy>
70 {
71 private:
72  using MinMaxRange = RangeTracker::MinMaxRange;
73 
74 public:
76  LayerBindingId layerId,
77  const MinMaxRange& minMaxRange);
78  ~OverrideInputRangeVisitor() = default;
79 
80  void VisitInputLayer(const IConnectableLayer* layer, LayerBindingId id, const char* name = nullptr) override;
81 
82 private:
83  /// Mapping from a layer Guid to an array of ranges for outputs
84  RangeTracker& m_Ranges;
85 
86  /// The id of the input layer of which to override the input range
87  LayerBindingId m_LayerId;
88 
89  /// The new input range to be applied to the input layer
90  MinMaxRange m_MinMaxRange;
91 };
92 
93 } // namespace armnn
void ExecuteStrategy(const armnn::IConnectableLayer *layer, const BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id) override
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
Visitor object for overriding the input range of the quantized input layers in a network.
OverrideInputRangeStrategy(RangeTracker &ranges, LayerBindingId layerId, const MinMaxRange &minMaxRange)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
std::pair< float, float > MinMaxRange
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:210
Base class for all descriptors.
Definition: Descriptors.hpp:22
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
Visitor base class with empty implementations.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.