ie_icnn_network.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This is a header file for the ICNNNetwork class
7  * @file ie_icnn_network.hpp
8  */
9 #pragma once
10 
11 #include "ie_common.h"
12 #include "ie_layers.h"
13 #include "ie_data.h"
14 #include "ie_device.hpp"
15 #include "ie_blob.h"
16 #include "details/ie_irelease.hpp"
17 #include "ie_preprocess.hpp"
18 #include "ie_input_info.hpp"
19 #include "ie_icnn_network_stats.hpp"
20 #include "ie_iextension.h"
21 #include <memory>
22 #include <map>
23 #include <string>
24 
25 namespace InferenceEngine {
26 
27 /**
28  * @brief A collection that contains string as key, and Data smart pointer as value
29  */
30 using OutputsDataMap = std::map<std::string, DataPtr>;
31 
32 /**
33  * @brief This is the main interface to describe the NN topology
34  */
35 class ICNNNetwork : public details::IRelease {
36 public:
37  /**
38  * @brief Returns the main network operating precision.
39  * This may be MIXED if not homogeneous.
40  * @return A precision type
41  */
42  virtual Precision getPrecision() const noexcept = 0;
43 
44  /**
45  * @brief Gets the network output Data node information. The received info is stored in the given Data node.
46  * For single and multiple outputs networks.
47  * @param out Reference to the OutputsDataMap object
48  */
49  virtual void getOutputsInfo(OutputsDataMap& out) const noexcept = 0;
50 
51  /**
52  * @brief Gets the network input Data node information. The received info is stored in the given InputsDataMap object.
53  * For single and multiple inputs networks.
54  * This method must be called to find out input names for using them later during filling of a map
55  * of blobs passed later to InferenceEngine::IInferencePlugin::Infer()
56  * @param inputs Reference to InputsDataMap object.
57  */
58  virtual void getInputsInfo(InputsDataMap& inputs) const noexcept = 0;
59 
60 
61  /**
62  * @brief Returns information on certain input pointed by inputName
63  * @param inputName Name of input layer to get info on
64  * @return A smart pointer to the input information
65  */
66  virtual InputInfo::Ptr getInput(const std::string& inputName) const noexcept = 0;
67 
68  /**
69  * @brief Gets the network name. The name is stored in the given pName string.
70  * @param pName - will receive actual network name, specified in IR file,
71  * pName should point to valid memory address before invoking this function
72  * @param len - size in bytes of pName buffer, actual name is trimmed by this size
73  */
74  virtual void getName(char* pName, size_t len) const noexcept = 0;
75 
76  /**
77  * @brief Returns the network name.
78  * @return Network name
79  */
80  virtual const std::string& getName() const noexcept = 0;
81 
82  /**
83  * @brief Returns the number of layers in the network as an integer value
84  * @return The number of layers as an integer value
85  */
86  virtual size_t layerCount() const noexcept = 0;
87 
88  /**
89  * @brief Returns a smart pointer reference to a Data node given its name.
90  * If the Data node is missing, returns reference to a default initialized new empty data pointer with given name.
91  * @param dname Name of the Data node
92  * @return Data node smart pointer
93  */
94  virtual DataPtr& getData(const char* dname) noexcept = 0;
95 
96  /**
97  * @brief Insert a layer into the network. A user is responsible to connect it to other data elements.
98  * @param layer Const reference to a layer smart pointer
99  */
100  virtual void addLayer(const CNNLayerPtr& layer) noexcept = 0;
101 
102  /**
103  * @brief Adds output to the layer
104  * @param layerName Name of the layer
105  * @param outputIndex Index of the output
106  * @param resp Response message
107  * @return Status code of the operation
108  */
109  virtual StatusCode
110  addOutput(const std::string& layerName, size_t outputIndex = 0, ResponseDesc* resp = nullptr) noexcept = 0;
111 
112  /**
113  * @brief Gets network layer with the given name
114  * @param layerName Given name of the layer
115  * @param out Pointer to the found CNNLayer object with the given name
116  * @param resp Pointer to the response message that holds a description of an error if any occurred
117  * @return Status code of the operation. OK if succeeded
118  */
119  virtual StatusCode getLayerByName(const char* layerName, CNNLayerPtr& out, ResponseDesc* resp) const noexcept = 0;
120 
121  /**
122  * @brief Sets a desirable device to perform all work on.
123  * Some plug-ins might not support some target devices and may abort execution with an appropriate error message.
124  * @param device Device to set as a target
125  */
126  virtual void setTargetDevice(TargetDevice device) noexcept = 0;
127 
128  /**
129  * @brief Gets the target device.
130  * If setTargetDevice() was not called before, returns eDefault
131  * @return A TargetDevice instance
132  */
133  virtual TargetDevice getTargetDevice() const noexcept = 0;
134 
135  /**
136  * @deprecated use setBatchSize with ResponseDesc to get error message
137  * @brief Changes the inference batch size
138  */
139  virtual StatusCode setBatchSize(const size_t size) noexcept = 0;
140 
141  /**
142  * @brief Changes the inference batch size.
143  * @note There are several limitations and it's not recommended to use it. Set batch to the input shape and call @reshape.
144  * @param size Size of batch to set
145  * @return Status code of the operation
146  * @note: Current implementation of the function sets batch size to the first dimension of all layers in the networks.
147  * Before calling it make sure that all your layers have batch in the first dimension, otherwise the method works incorrectly.
148  * This limitation is resolved via shape inference feature
149  * by using InferenceEngine::ICNNNetwork::reshape method.
150  * To read more refer to the Shape Inference section in documentation
151  */
152  virtual StatusCode setBatchSize(size_t size, ResponseDesc* responseDesc) noexcept = 0;
153 
154  /**
155  * @brief Gets the inference batch size
156  * @return The size of batch as a size_t value
157  */
158  virtual size_t getBatchSize() const noexcept = 0;
159 
160  /**
161  * @brief Map of pairs: name of corresponding data and its dimension.
162  */
163  using InputShapes = std::map<std::string, SizeVector>;
164 
165  /**
166  * @brief Run shape inference with new input shapes for the network
167  * @param inputShapes - map of pairs: name of corresponding data and its dimension.
168  * @param resp Pointer to the response message that holds a description of an error if any occurred
169  * @return Status code of the operation
170  */
171  virtual StatusCode reshape(const InputShapes& /*inputShapes*/, ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; };
172 
173  /**
174  * @brief Registers extension within the plugin
175  * @param extension Pointer to already loaded reader extension with shape propagation implementations
176  * @param resp Pointer to the response message that holds a description of an error if any occurred
177  * @return Status code of the operation. OK if succeeded
178  */
179  virtual StatusCode
180  AddExtension(const IShapeInferExtensionPtr& /*extension*/, ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; };
181 
182  virtual StatusCode getStats(ICNNNetworkStats** /*stats*/, ResponseDesc* /*resp*/) const noexcept { return NOT_IMPLEMENTED; };
183 
184  /**
185  * @brief Serialize network to IR and weights files.
186  * @param xmlPath Path to output IR file.
187  * @param binPath Path to output weights file.
188  * @return Status code of the operation
189  */
190  virtual StatusCode serialize(const std::string &xmlPath, const std::string &binPath, ResponseDesc* resp) const noexcept = 0;
191 };
192 } // namespace InferenceEngine
TargetDevice
Describes known device types.
Definition: ie_device.hpp:23
virtual const std::string & getName() const noexcept=0
Returns the network name.
Definition: ie_argmax_layer.hpp:11
std::shared_ptr< CNNLayer > CNNLayerPtr
A smart pointer to the CNNLayer.
Definition: ie_common.h:36
virtual DataPtr & getData(const char *dname) noexcept=0
Returns a smart pointer reference to a Data node given its name. If the Data node is missing...
virtual void getInputsInfo(InputsDataMap &inputs) const noexcept=0
Gets the network input Data node information. The received info is stored in the given InputsDataMap ...
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:172
virtual StatusCode reshape(const InputShapes &, ResponseDesc *) noexcept
Run shape inference with new input shapes for the network.
Definition: ie_icnn_network.hpp:171
A header file for Blob and generic TBlob<>
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
virtual InputInfo::Ptr getInput(const std::string &inputName) const noexcept=0
Returns information on certain input pointed by inputName.
virtual StatusCode getLayerByName(const char *layerName, CNNLayerPtr &out, ResponseDesc *resp) const noexcept=0
Gets network layer with the given name.
This header file provides structures to store info about pre-processing of network inputs (scale...
virtual size_t getBatchSize() const noexcept=0
Gets the inference batch size.
Represents detailed information for an error.
Definition: ie_common.h:195
a header file for internal Layers structure to describe layers information
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:35
This header file defines the main Data representation node.
This is a header file for the ICNNNetworkStats class.
virtual void setTargetDevice(TargetDevice device) noexcept=0
Sets a desirable device to perform all work on. Some plug-ins might not support some target devices a...
virtual size_t layerCount() const noexcept=0
Returns the number of layers in the network as an integer value.
virtual void addLayer(const CNNLayerPtr &layer) noexcept=0
Insert a layer into the network. A user is responsible to connect it to other data elements...
virtual StatusCode setBatchSize(const size_t size) noexcept=0
Changes the inference batch size.
virtual StatusCode addOutput(const std::string &layerName, size_t outputIndex=0, ResponseDesc *resp=nullptr) noexcept=0
Adds output to the layer.
virtual TargetDevice getTargetDevice() const noexcept=0
Gets the target device. If setTargetDevice() was not called before, returns eDefault.
This is a header file for Inference Engine Extension Interface.
This header file contains aspects of working on different devices like CPU, GEN, FPGA, etc.
std::shared_ptr< InputInfo > Ptr
A smart pointer to the InputInfo instance.
Definition: ie_input_info.hpp:28
A header file for the Inference Engine plugins destruction mechanism.
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
This is the interface to describe the NN topology scoring statistics.
Definition: ie_icnn_network_stats.hpp:29
virtual StatusCode AddExtension(const IShapeInferExtensionPtr &, ResponseDesc *) noexcept
Registers extension within the plugin.
Definition: ie_icnn_network.hpp:180
std::map< std::string, DataPtr > OutputsDataMap
A collection that contains string as key, and Data smart pointer as value.
Definition: ie_icnn_network.hpp:30
std::map< std::string, SizeVector > InputShapes
Map of pairs: name of corresponding data and its dimension.
Definition: ie_icnn_network.hpp:163
virtual Precision getPrecision() const noexcept=0
Returns the main network operating precision. This may be MIXED if not homogeneous.
virtual void getOutputsInfo(OutputsDataMap &out) const noexcept=0
Gets the network output Data node information. The received info is stored in the given Data node...
a header file for InputInfo class
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
virtual StatusCode serialize(const std::string &xmlPath, const std::string &binPath, ResponseDesc *resp) const noexcept=0
Serialize network to IR and weights files.