Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / ie_input_info.hpp
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      */
48     Precision getInputPrecision() const {
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      */
58     void setInputPrecision(Precision p) {
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      */
77     Precision getPrecision() const {
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      */
89     void setPrecision(Precision p) {
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      */
106     Layout getLayout() {
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      */
135     DataPtr getInputData() {
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      */
176     PreProcessInfo &getPreProcess() { return _preProcessInfo; }
177
178 protected:
179     /**
180      * @brief Pre-process info for the input
181      */
182     PreProcessInfo _preProcessInfo;
183
184     /**
185      * @brief A smart pointer to the input data
186      */
187     DataPtr _inputData;
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