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