ie_cnn_network.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides wrapper for ICNNNetwork object
7  *
8  * @file ie_cnn_network.h
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 #include "ie_icnn_network.hpp"
19 #include "ie_blob.h"
20 #include "ie_common.h"
21 #include "ie_data.h"
23 #include "ie_extension.h"
24 
25 namespace ngraph {
26 
27 class Function;
28 
29 } // namespace ngraph
30 
31 namespace InferenceEngine {
32 
33 /**
34  * @brief This class contains all the information about the Neural Network and the related binary information
35  */
36 class INFERENCE_ENGINE_API_CLASS(CNNNetwork) {
37 public:
38  /**
39  * @brief A default constructor
40  */
42 
43  IE_SUPPRESS_DEPRECATED_START
44  /**
45  * @brief Allows helper class to manage lifetime of network object
46  *
47  * @param network Pointer to the network object
48  */
49  explicit CNNNetwork(std::shared_ptr<ICNNNetwork> network);
50  IE_SUPPRESS_DEPRECATED_END
51 
52  /**
53  * @brief A constructor from ngraph::Function object
54  * This constructor wraps existing ngraph::Function
55  * If you want to avoid modification of original Function, please create a copy
56  * @param network Pointer to the ngraph::Function object
57  * @param exts Vector of pointers to IE extension objects
58  */
59  explicit CNNNetwork(const std::shared_ptr<ngraph::Function>& network,
60  const std::vector<IExtensionPtr>& exts = {});
61 
62  /**
63  * @copybrief ICNNNetwork::getOutputsInfo
64  *
65  * Wraps ICNNNetwork::getOutputsInfo
66  *
67  * @return outputs Reference to the OutputsDataMap object
68  */
70 
71  /**
72  * @copybrief ICNNNetwork::getInputsInfo
73  *
74  * Wraps ICNNNetwork::getInputsInfo
75  *
76  * @return inputs Reference to InputsDataMap object
77  */
79 
80  /**
81  * @copybrief ICNNNetwork::layerCount
82  *
83  * Wraps ICNNNetwork::layerCount
84  *
85  * @return The number of layers as an integer value
86  */
87  size_t layerCount() const;
88 
89  /**
90  * @copybrief ICNNNetwork::getName
91  *
92  * Wraps ICNNNetwork::getName
93  *
94  * @return Network name
95  */
96  const std::string& getName() const;
97 
98  /**
99  * @copybrief ICNNNetwork::setBatchSize
100  *
101  * Wraps ICNNNetwork::setBatchSize
102  *
103  * @param size Size of batch to set
104  */
105  void setBatchSize(const size_t size);
106 
107  /**
108  * @copybrief ICNNNetwork::getBatchSize
109  *
110  * Wraps ICNNNetwork::getBatchSize
111  *
112  * @return The size of batch as a size_t value
113  */
114  size_t getBatchSize() const;
115 
116  IE_SUPPRESS_DEPRECATED_START
117  /**
118  * @deprecated InferenceEngine::ICNNNetwork interface is deprecated
119  * @brief An overloaded operator cast to get pointer on current network
120  *
121  * @return A shared pointer of the current network
122  */
123  // INFERENCE_ENGINE_DEPRECATED("InferenceEngine::ICNNNetwork interface is deprecated")
124  operator ICNNNetwork::Ptr();
125 
126  /**
127  * @deprecated InferenceEngine::ICNNNetwork interface is deprecated
128  * @brief An overloaded operator & to get current network
129  *
130  * @return An instance of the current network
131  */
132  // INFERENCE_ENGINE_DEPRECATED("InferenceEngine::ICNNNetwork interface is deprecated")
133  operator ICNNNetwork&();
134 
135  /**
136  * @deprecated InferenceEngine::ICNNNetwork interface is deprecated
137  * @brief An overloaded operator & to get current network
138  *
139  * @return A const reference of the current network
140  */
141  // INFERENCE_ENGINE_DEPRECATED("InferenceEngine::ICNNNetwork interface is deprecated")
142  operator const ICNNNetwork&() const;
143  IE_SUPPRESS_DEPRECATED_END
144 
145  /**
146  * @brief Returns constant nGraph function
147  *
148  * @return constant nGraph function
149  */
150  std::shared_ptr<ngraph::Function> getFunction();
151 
152  /**
153  * @brief Returns constant nGraph function
154  *
155  * @return constant nGraph function
156  */
157  std::shared_ptr<const ngraph::Function> getFunction() const;
158 
159  /**
160  * @copybrief ICNNNetwork::addOutput
161  *
162  * Wraps ICNNNetwork::addOutput
163  *
164  * @param layerName Name of the layer
165  * @param outputIndex Index of the output
166  */
167  void addOutput(const std::string& layerName, size_t outputIndex = 0);
168 
169  /**
170  * @brief Helper method to get collect all input shapes with names of corresponding Data objects
171  *
172  * @return Map of pairs: input name and its dimension.
173  */
175 
176  /**
177  * @brief Run shape inference with new input shapes for the network
178  *
179  * @param inputShapes - map of pairs: name of corresponding data and its dimension.
180  */
181  void reshape(const ICNNNetwork::InputShapes& inputShapes);
182 
183  /**
184  * @brief Serialize network to IR and weights files.
185  *
186  * @param xmlPath Path to output IR file.
187  * @param binPath Path to output weights file. The parameter is skipped in case
188  * of executable graph info serialization.
189  */
190  void serialize(const std::string& xmlPath, const std::string& binPath = {}) const;
191 
192  /**
193  * @brief Method maps framework tensor name to OpenVINO name
194  *
195  * @param orig_name Framework tensor name
196  *
197  * @return OpenVINO name
198  */
199  std::string getOVNameForTensor(const std::string& orig_name) const {
200  std::string ov_name;
201  CALL_STATUS_FNC(getOVNameForTensor, ov_name, orig_name);
202  return ov_name;
203  }
204 
205 protected:
206  IE_SUPPRESS_DEPRECATED_START
207  /**
208  * @brief Network extra interface, might be nullptr
209  */
210  std::shared_ptr<ICNNNetwork> network;
211 
212  /**
213  * @brief A pointer to the current network
214  */
215  ICNNNetwork* actual = nullptr;
216  IE_SUPPRESS_DEPRECATED_END
217 
218  /**
219  * @brief A pointer to output data
220  */
222 };
223 
224 } // namespace InferenceEngine
std::shared_ptr< ICNNNetwork > network
Network extra interface, might be nullptr.
Definition: ie_cnn_network.h:210
CNNNetwork()
A default constructor.
void serialize(const std::string &xmlPath, const std::string &binPath={}) const
Serialize network to IR and weights files.
CNNNetwork(const std::shared_ptr< ngraph::Function > &network, const std::vector< IExtensionPtr > &exts={})
A constructor from ngraph::Function object This constructor wraps existing ngraph::Function If you wa...
std::shared_ptr< const ngraph::Function > getFunction() const
Returns constant nGraph function.
std::string getOVNameForTensor(const std::string &orig_name) const
Method maps framework tensor name to OpenVINO name.
Definition: ie_cnn_network.h:199
size_t layerCount() const
Returns the number of layers in the network as an integer value.
size_t getBatchSize() const
Gets the inference batch size.
CNNNetwork(std::shared_ptr< ICNNNetwork > network)
Allows helper class to manage lifetime of network object.
std::shared_ptr< ngraph::Function > getFunction()
Returns constant nGraph function.
InputsDataMap getInputsInfo() const
Gets the network input Data node information. The received info is stored in the given InputsDataMap ...
DataPtr output
A pointer to output data.
Definition: ie_cnn_network.h:221
ICNNNetwork::InputShapes getInputShapes() const
Helper method to get collect all input shapes with names of corresponding Data objects.
void addOutput(const std::string &layerName, size_t outputIndex=0)
Adds output to the layer.
void setBatchSize(const size_t size)
Changes the inference batch size.
const std::string & getName() const
Returns the network name.
void reshape(const ICNNNetwork::InputShapes &inputShapes)
Run shape inference with new input shapes for the network.
OutputsDataMap getOutputsInfo() const
Gets the network output Data node information. The received info is stored in the given Data node.
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:48
std::shared_ptr< ICNNNetwork > Ptr
A shared pointer to a ICNNNetwork interface.
Definition: ie_icnn_network.hpp:53
std::map< std::string, SizeVector > InputShapes
Map of pairs: name of corresponding data and its dimension.
Definition: ie_icnn_network.hpp:161
A header file for Blob and generic TBlob<>
This is a header file with common inference engine definitions.
This header file defines the main Data representation node.
A header file that provides macros to handle no exception methods.
A header file that defines a wrapper class for handling extension instantiation and releasing resourc...
This is a header file for the ICNNNetwork class.
Inference Engine C++ API.
Definition: cldnn_config.hpp:15
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:165
std::map< std::string, DataPtr > OutputsDataMap
A collection that contains string as key, and Data smart pointer as value.
Definition: ie_icnn_network.hpp:41
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:37