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 it will be removed from public API. Please use 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 setInputPrecision()
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  */
49  return getPrecision();
50  }
51 
52  /**
53  * @deprecated it will be removed from public API. Please use setPrecision()
54  * @brief Changes the precision of the input data provided by the user.
55  * This function should be called before loading the network to the plugin
56  * @param p A new precision of the input data to set
57  */
59  setPrecision(p);
60  }
61 
62  /**
63  * @brief Gets a precision of the input data provided by user
64  *
65  * By default it matches the layers precision, but there are exceptions of this rule
66  * For Q78 precision networks the input is expected in I16 by default
67  * For FP16 precision networks the input is expected in FP32 by default
68  *
69  * @details By default it matches the layers precision, but there are exceptions of this rule.
70  * For Q78 precision networks the input is expected in I16 by default.
71  * For FP16 precision networks the input is expected in FP32 by default.
72  * The default input precision might be changed preferred one using setInputPrecision()
73  * function.
74  * For example, for a Q78 precision network you can pass FP32 input data
75  * @return The precision used for input blob creation
76  */
78  if (!_inputData) {
79  THROW_IE_EXCEPTION << "Data is empty!";
80  }
81  return _inputData->getPrecision();
82  }
83 
84  /**
85  * @brief Changes the precision of the input data provided by the user.
86  * This function should be called before loading the network to the plugin
87  * @param p A new precision of the input data to set
88  */
90  if (!_inputData) {
91  THROW_IE_EXCEPTION << "Data is empty!";
92  }
93  _inputData->setPrecision(p);
94  }
95 
96  /**
97  * @brief Gets a layout of the input data provided by user
98  * @details By default it matches the layers precision and depends on number of its dimensions:
99  * C - for 1-dimensional,
100  * NC - for 2-dimensional,
101  * CHW - for 3-dimensional,
102  * NCHW - for 4-dimensional
103  * The default input layout might be changed preferred one using setLayout() function.
104  * @return The precision used for input blob creation
105  */
107  if (!_inputData) {
108  THROW_IE_EXCEPTION << "Data is empty!";
109  }
110  return _inputData->getLayout();
111  }
112 
113  /**
114  * @brief Changes the layout of the input data provided by the user.
115  * This function should be called before loading the network to the plugin
116  * @param p A new layout of the input data to set
117  */
118  void setLayout(Layout l) {
119  if (!_inputData) {
120  THROW_IE_EXCEPTION << "Data is empty!";
121  }
122  _inputData->setLayout(l);
123  }
124 
125  /**
126  * @brief Gets the name of the input
127  * @return A string - the name of the input
128  */
129  const std::string &name() const { return _inputData->getName(); }
130 
131  /**
132  * @brief Gets the input data
133  * @return A smart pointer to the input data
134  */
136  return _inputData;
137  }
138 
139  /**
140  * @brief Initializes the pointer to the input data that stores the main input parameters like dims, etc.
141  * This method initializes the precision with the information from the inputPtr if it was not set
142  * explicitly through setInputPrecision(). If setInputPrecision() was called, this method does not overwrite the precision.
143  * @param inputPtr Pointer to the input data to set
144  */
145  void setInputData(DataPtr inputPtr) {
146  _inputData = inputPtr;
147  }
148 
149  /**
150  * @deprecated Please use getTensorDesc for working with layouts and dimensions
151  * @brief Gets dimensions/shape of the input data with reversed order
152  * @return A SizeVector object that contains dimensions of the input data. If the data is not set, the method returns an empty SizeVector object.
153  */
154  SizeVector getDims() const {
155  if (_inputData) {
156  return _inputData->dims;
157  } else {
158  return SizeVector();
159  }
160  }
161 
162  /**
163  * @brief Returns the tensor descriptor
164  */
165  const TensorDesc &getTensorDesc() const {
166  if (!_inputData) {
167  THROW_IE_EXCEPTION << "Data is empty!";
168  }
169  return _inputData->getTensorDesc();
170  }
171 
172  /**
173  * @brief Gets pre-process info for the input
174  * @return A reference to the PreProcessInfo instance that contains pre-process info for this input
175  */
177 
178 protected:
179  /**
180  * @brief Pre-process info for the input
181  */
183 
184  /**
185  * @brief A smart pointer to the input data
186  */
188 };
189 
190 /**
191  * @brief A collection that contains string as key, and InputInfo smart pointer as value
192  */
193 using InputsDataMap = std::map<std::string, InputInfo::Ptr>;
194 
195 /**
196  * @brief A collection that contains string as key, and const InputInfo smart pointer as value
197  */
198 using ConstInputsDataMap = std::map<std::string, InputInfo::CPtr>;
199 
200 } // 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:176
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:58
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:129
PreProcessInfo _preProcessInfo
Pre-process info for the input.
Definition: ie_input_info.hpp:182
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:193
void setInputData(DataPtr inputPtr)
Initializes the pointer to the input data that stores the main input parameters like dims...
Definition: ie_input_info.hpp:145
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:154
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:198
Precision getInputPrecision() const
Gets a precision of the input data provided by user.
Definition: ie_input_info.hpp:48
Precision getPrecision() const
Gets a precision of the input data provided by user.
Definition: ie_input_info.hpp:77
This header file defines the main Data representation node.
DataPtr _inputData
A smart pointer to the input data.
Definition: ie_input_info.hpp:187
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:89
const TensorDesc & getTensorDesc() const
Returns the tensor descriptor.
Definition: ie_input_info.hpp:165
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:135
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:106
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:118
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