ie_input_info.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief a header file for InputInfo class
7  * @file ie_input_info.hpp
8  */
9 #pragma once
10 
11 #include <string>
12 #include <memory>
13 #include <map>
14 #include "ie_common.h"
15 #include "ie_data.h"
16 #include "ie_preprocess.hpp"
17 #include "ie_blob.h"
18 #include "ie_precision.hpp"
19 
20 namespace InferenceEngine {
21 
22 /**
23  * @brief This class contains information about each input of the network
24  */
25 class InputInfo {
26 public:
27  /** @brief A smart pointer to the InputInfo instance */
28  using Ptr = std::shared_ptr<InputInfo>;
29  /** @brief A smart pointer to the constant InputInfo instance */
30  using CPtr = std::shared_ptr<const InputInfo>;
31 
32  /**
33  * @deprecated Use InputInfo::getPrecision
34  * @brief Gets a precision of the input data provided by user
35  *
36  * By default it matches the layers precision, but there are exceptions of this rule
37  * For Q78 precision networks the input is expected in I16 by default
38  * For FP16 precision networks the input is expected in FP32 by default
39  *
40  * @details By default it matches the layers precision, but there are exceptions of this rule.
41  * For Q78 precision networks the input is expected in I16 by default.
42  * For FP16 precision networks the input is expected in FP32 by default.
43  * The default input precision might be changed preferred one using InputInfo::setPrecision
44  * function.
45  * For example, for a Q78 precision network you can pass FP32 input data
46  * @return The precision used for input blob creation
47  */
48  INFERENCE_ENGINE_DEPRECATED
50  return getPrecision();
51  }
52 
53  /**
54  * @deprecated Use InputInfo::setPrecision
55  * @brief Changes the precision of the input data provided by the user.
56  * This function should be called before loading the network to the plugin
57  * @param p A new precision of the input data to set
58  */
59  INFERENCE_ENGINE_DEPRECATED
61  setPrecision(p);
62  }
63 
64  /**
65  * @brief Gets a precision of the input data provided by user
66  *
67  * By default it matches the layers precision, but there are exceptions of this rule
68  * For Q78 precision networks the input is expected in I16 by default
69  * For FP16 precision networks the input is expected in FP32 by default
70  *
71  * @details By default it matches the layers precision, but there are exceptions of this rule.
72  * For Q78 precision networks the input is expected in I16 by default.
73  * For FP16 precision networks the input is expected in FP32 by default.
74  * The default input precision might be changed preferred one using InputInfo::setPrecision()
75  * function.
76  * For example, for a Q78 precision network you can pass FP32 input data
77  * @return The precision used for input blob creation
78  */
80  if (!_inputData) {
81  THROW_IE_EXCEPTION << "Data is empty!";
82  }
83  return _inputData->getPrecision();
84  }
85 
86  /**
87  * @brief Changes the precision of the input data provided by the user.
88  * This function should be called before loading the network to the plugin
89  * @param p A new precision of the input data to set
90  */
92  if (!_inputData) {
93  THROW_IE_EXCEPTION << "Data is empty!";
94  }
95  _inputData->setPrecision(p);
96  }
97 
98  /**
99  * @brief Gets a layout of the input data provided by user
100  * @details By default it matches the layers precision and depends on number of its dimensions:
101  * C - for 1-dimensional,
102  * NC - for 2-dimensional,
103  * CHW - for 3-dimensional,
104  * NCHW - for 4-dimensional
105  * The default input layout might be changed preferred one using setLayout() function.
106  * @return The precision used for input blob creation
107  */
109  if (!_inputData) {
110  THROW_IE_EXCEPTION << "Data is empty!";
111  }
112  return _inputData->getLayout();
113  }
114 
115  /**
116  * @brief Changes the layout of the input data provided by the user.
117  * This function should be called before loading the network to the plugin
118  * @param p A new layout of the input data to set
119  */
120  void setLayout(Layout l) {
121  if (!_inputData) {
122  THROW_IE_EXCEPTION << "Data is empty!";
123  }
124  _inputData->setLayout(l);
125  }
126 
127  /**
128  * @brief Gets the name of the input
129  * @return A string - the name of the input
130  */
131  const std::string &name() const { return _inputData->getName(); }
132 
133  /**
134  * @brief Gets the input data
135  * @return A smart pointer to the input data
136  */
138  return _inputData;
139  }
140 
141  /**
142  * @brief Initializes the pointer to the input data that stores the main input parameters like dims, etc.
143  * This method initializes the precision with the information from the inputPtr if it was not set
144  * explicitly through InputInfo::setPrecision. If InputInfo::setPrecision is called, this method does not overwrite the precision.
145  * @param inputPtr Pointer to the input data to set
146  */
147  void setInputData(DataPtr inputPtr) {
148  _inputData = inputPtr;
149  }
150 
151  /**
152  * @deprecated Please use InputInfo::getTensorDesc for working with layouts and dimensions
153  * @brief Gets dimensions/shape of the input data with reversed order
154  * @return A SizeVector object that contains dimensions of the input data. If the data is not set, the method returns an empty SizeVector object.
155  */
156  INFERENCE_ENGINE_DEPRECATED
157  SizeVector getDims() const {
158  if (_inputData) {
159  auto dims = _inputData->getTensorDesc().getDims();
160  std::reverse(dims.begin(), dims.end());
161  return dims;
162  } else {
163  return SizeVector();
164  }
165  }
166 
167  /**
168  * @brief Returns the tensor descriptor
169  */
170  const TensorDesc &getTensorDesc() const {
171  if (!_inputData) {
172  THROW_IE_EXCEPTION << "Data is empty!";
173  }
174  return _inputData->getTensorDesc();
175  }
176 
177  /**
178  * @brief Gets pre-process info for the input
179  * @return A reference to the PreProcessInfo instance that contains pre-process info for this input
180  */
182 
183 protected:
184  /**
185  * @brief Pre-process info for the input
186  */
188 
189  /**
190  * @brief A smart pointer to the input data
191  */
193 };
194 
195 /**
196  * @brief A collection that contains string as key, and InputInfo smart pointer as value
197  */
198 using InputsDataMap = std::map<std::string, InputInfo::Ptr>;
199 
200 /**
201  * @brief A collection that contains string as key, and const InputInfo smart pointer as value
202  */
203 using ConstInputsDataMap = std::map<std::string, InputInfo::CPtr>;
204 
205 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
PreProcessInfo & getPreProcess()
Gets pre-process info for the input.
Definition: ie_input_info.hpp:181
void setInputPrecision(Precision p)
Changes the precision of the input data provided by the user. This function should be called before l...
Definition: ie_input_info.hpp:60
std::vector< size_t > SizeVector
Represents tensor size. The order is opposite to the order in Caffe*: (w,h,n,b) where the most freque...
Definition: ie_common.h:26
Definition: ie_argmax_layer.hpp:11
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:76
This class contains information about each input of the network.
Definition: ie_input_info.hpp:25
const std::string & name() const
Gets the name of the input.
Definition: ie_input_info.hpp:131
PreProcessInfo _preProcessInfo
Pre-process info for the input.
Definition: ie_input_info.hpp:187
A header file for Blob and generic TBlob<>
This class stores pre-process information for the input.
Definition: ie_preprocess.hpp:56
std::map< std::string, InputInfo::Ptr > InputsDataMap
A collection that contains string as key, and InputInfo smart pointer as value.
Definition: ie_input_info.hpp:198
void setInputData(DataPtr inputPtr)
Initializes the pointer to the input data that stores the main input parameters like dims...
Definition: ie_input_info.hpp:147
This header file provides structures to store info about pre-processing of network inputs (scale...
This class defines Tensor description.
Definition: ie_layouts.h:143
SizeVector getDims() const
Gets dimensions/shape of the input data with reversed order.
Definition: ie_input_info.hpp:157
A header file that provides class for describing precision of data.
std::map< std::string, InputInfo::CPtr > ConstInputsDataMap
A collection that contains string as key, and const InputInfo smart pointer as value.
Definition: ie_input_info.hpp:203
Precision getInputPrecision() const
Gets a precision of the input data provided by user.
Definition: ie_input_info.hpp:49
Precision getPrecision() const
Gets a precision of the input data provided by user.
Definition: ie_input_info.hpp:79
This header file defines the main Data representation node.
DataPtr _inputData
A smart pointer to the input data.
Definition: ie_input_info.hpp:192
void setPrecision(Precision p)
Changes the precision of the input data provided by the user. This function should be called before l...
Definition: ie_input_info.hpp:91
const TensorDesc & getTensorDesc() const
Returns the tensor descriptor.
Definition: ie_input_info.hpp:170
std::shared_ptr< InputInfo > Ptr
A smart pointer to the InputInfo instance.
Definition: ie_input_info.hpp:28
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
DataPtr getInputData()
Gets the input data.
Definition: ie_input_info.hpp:137
std::shared_ptr< const InputInfo > CPtr
A smart pointer to the constant InputInfo instance.
Definition: ie_input_info.hpp:30
Layout getLayout()
Gets a layout of the input data provided by user.
Definition: ie_input_info.hpp:108
void setLayout(Layout l)
Changes the layout of the input data provided by the user. This function should be called before load...
Definition: ie_input_info.hpp:120
This is a header file with common inference engine definitions.
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:19