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