1
// Copyright (C) 2018-2019 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
6
* @brief This is a header file for the ICNNNetwork class
7
* @file ie_icnn_network.hpp
11
#include "ie_common.h"
12
#include "ie_layers.h"
14
#include "ie_device.hpp"
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"
25
namespace InferenceEngine {
28
* @brief A collection that contains string as key, and Data smart pointer as value
30
using OutputsDataMap = std::map<std::string, DataPtr>;
33
* @brief This is the main interface to describe the NN topology
35
class ICNNNetwork : public details::IRelease {
37
using Ptr = std::shared_ptr<ICNNNetwork>;
40
* @brief Returns the main network operating precision.
41
* This may be MIXED if not homogeneous.
42
* @return A precision type
44
virtual Precision getPrecision() const noexcept = 0;
47
* @brief Gets the network output Data node information. The received info is stored in the given Data node.
48
* For single and multiple outputs networks.
49
* @param out Reference to the OutputsDataMap object
51
virtual void getOutputsInfo(OutputsDataMap& out) const noexcept = 0;
54
* @brief Gets the network input Data node information. The received info is stored in the given InputsDataMap object.
55
* For single and multiple inputs networks.
56
* This method must be called to find out input names for using them later during filling of a map
57
* of blobs passed later to InferenceEngine::IInferencePlugin::Infer()
58
* @param inputs Reference to InputsDataMap object.
60
virtual void getInputsInfo(InputsDataMap& inputs) const noexcept = 0;
64
* @brief Returns information on certain input pointed by inputName
65
* @param inputName Name of input layer to get info on
66
* @return A smart pointer to the input information
68
virtual InputInfo::Ptr getInput(const std::string& inputName) const noexcept = 0;
71
* @brief Gets the network name. The name is stored in the given pName string.
72
* @param pName - will receive actual network name, specified in IR file,
73
* pName should point to valid memory address before invoking this function
74
* @param len - size in bytes of pName buffer, actual name is trimmed by this size
76
virtual void getName(char* pName, size_t len) const noexcept = 0;
79
* @brief Returns the network name.
80
* @return Network name
82
virtual const std::string& getName() const noexcept = 0;
85
* @brief Returns the number of layers in the network as an integer value
86
* @return The number of layers as an integer value
88
virtual size_t layerCount() const noexcept = 0;
91
* @brief Returns a smart pointer reference to a Data node given its name.
92
* If the Data node is missing, returns reference to a default initialized new empty data pointer with given name.
93
* @param dname Name of the Data node
94
* @return Data node smart pointer
96
virtual DataPtr& getData(const char* dname) noexcept = 0;
99
* @brief Insert a layer into the network. A user is responsible to connect it to other data elements.
100
* @param layer Const reference to a layer smart pointer
102
virtual void addLayer(const CNNLayerPtr& layer) noexcept = 0;
105
* @brief Adds output to the layer
106
* @param layerName Name of the layer
107
* @param outputIndex Index of the output
108
* @param resp Response message
109
* @return Status code of the operation
112
addOutput(const std::string& layerName, size_t outputIndex = 0, ResponseDesc* resp = nullptr) noexcept = 0;
115
* @brief Gets network layer with the given name
116
* @param layerName Given name of the layer
117
* @param out Pointer to the found CNNLayer object with the given name
118
* @param resp Pointer to the response message that holds a description of an error if any occurred
119
* @return Status code of the operation. OK if succeeded
121
virtual StatusCode getLayerByName(const char* layerName, CNNLayerPtr& out, ResponseDesc* resp) const noexcept = 0;
124
* @deprecated Deprecated since TargetDevice is deprecated. Specify target device in InferenceEngine::Core directly.
125
* @brief Sets a desirable device to perform all work on.
126
* Some plug-ins might not support some target devices and may abort execution with an appropriate error message.
127
* @param device Device to set as a target
130
INFERENCE_ENGINE_DEPRECATED
132
virtual void setTargetDevice(TargetDevice device) noexcept = 0;
135
* @deprecated Deprecated since TargetDevice is deprecated
136
* @brief Gets the target device.
137
* If setTargetDevice() was not called before, returns eDefault
138
* @return A TargetDevice instance
141
INFERENCE_ENGINE_DEPRECATED
143
virtual TargetDevice getTargetDevice() const noexcept = 0;
146
* @deprecated Use ICNNNetwork::setBatchSize(size_t, ResponseDesc*)
147
* @brief Changes the inference batch size
149
INFERENCE_ENGINE_DEPRECATED
150
virtual StatusCode setBatchSize(const size_t size) noexcept {
152
return setBatchSize(size, &resp);
156
* @brief Changes the inference batch size.
157
* @note There are several limitations and it's not recommended to use it. Set batch to the input shape and call ICNNNetwork::reshape.
158
* @param size Size of batch to set
159
* @return Status code of the operation
160
* @note: Current implementation of the function sets batch size to the first dimension of all layers in the networks.
161
* Before calling it make sure that all your layers have batch in the first dimension, otherwise the method works incorrectly.
162
* This limitation is resolved via shape inference feature
163
* by using InferenceEngine::ICNNNetwork::reshape method.
164
* To read more refer to the Shape Inference section in documentation
166
virtual StatusCode setBatchSize(size_t size, ResponseDesc* responseDesc) noexcept = 0;
169
* @brief Gets the inference batch size
170
* @return The size of batch as a size_t value
172
virtual size_t getBatchSize() const noexcept = 0;
175
* @brief Map of pairs: name of corresponding data and its dimension.
177
using InputShapes = std::map<std::string, SizeVector>;
180
* @brief Run shape inference with new input shapes for the network
181
* @param inputShapes - map of pairs: name of corresponding data and its dimension.
182
* @param resp Pointer to the response message that holds a description of an error if any occurred
183
* @return Status code of the operation
185
virtual StatusCode reshape(const InputShapes& /*inputShapes*/, ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; };
188
* @brief Registers extension within the plugin
189
* @param extension Pointer to already loaded reader extension with shape propagation implementations
190
* @param resp Pointer to the response message that holds a description of an error if any occurred
191
* @return Status code of the operation. OK if succeeded
194
AddExtension(const IShapeInferExtensionPtr& /*extension*/, ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; };
196
virtual StatusCode getStats(ICNNNetworkStats** /*stats*/, ResponseDesc* /*resp*/) const noexcept { return NOT_IMPLEMENTED; };
199
* @brief Serialize network to IR and weights files.
200
* @param xmlPath Path to output IR file.
201
* @param binPath Path to output weights file.
202
* @return Status code of the operation
204
virtual StatusCode serialize(const std::string &xmlPath, const std::string &binPath, ResponseDesc* resp) const noexcept = 0;
206
} // namespace InferenceEngine