ie_network_builder.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @file
7  */
8 
9 #pragma once
10 
11 #include <cpp/ie_cnn_network.h>
12 #include <ie_blob.h>
13 #include <ie_common.h>
14 
16 #include <ie_context.hpp>
17 #include <ie_icnn_network.hpp>
18 #include <ie_network.hpp>
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 namespace InferenceEngine {
26 namespace Builder {
27 
28 /**
29  * @deprecated Use ngraph API instead.
30  * @brief This class implements a builder for IE Network
31  */
32 IE_SUPPRESS_DEPRECATED_START
33 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(Network): public INetwork {
34 public:
35  /**
36  * @brief A shared pointer to the Network builder
37  */
38  using Ptr = std::shared_ptr<Network>;
39  /**
40  * @brief An iterator for Network builder definition
41  */
42  using iterator = details::INetworkIterator<Network, Layer>;
43 
44  /**
45  * @brief Begin network iterator
46  * @return Network iterator
47  */
48  iterator begin();
49  /**
50  * @brief Begin network iterator
51  * @return const INetwork iterator
52  */
53  const_iterator begin() const noexcept override;
54 
55  /**
56  * @brief End network iterator
57  * @return Network iterator
58  */
59  iterator end();
60  /**
61  * @brief End network iterator
62  * @return const INetwork iterator
63  */
64  const_iterator end() const noexcept override;
65 
66  /**
67  * @brief Returns a number of layers in the network.
68  * @return Layers count
69  */
70  size_t size() const noexcept override;
71 
72  /**
73  * @brief The constructor creates a builder based on ICNNNetwork
74  *
75  * @param network constant reference to ICNNNetwork object
76  */
77  explicit Network(const ICNNNetwork& network);
78  /**
79  * @brief The constructor creates a empty builder with network name
80  *
81  * @param name Network name
82  */
83  explicit Network(const std::string& name);
84  /**
85  * @brief The constructor creates a builder based on INetwork
86  *
87  * @param network constant reference to INetwork object
88  */
89  explicit Network(const INetwork& network);
90 
91  /**
92  * @brief The constructor creates a builder based on ICNNNetwork with custom Context
93  *
94  * @param network constant reference to ICNNNetwork object
95  */
96  Network(const Context& ieContext, const ICNNNetwork& network);
97  /**
98  * @brief The constructor creates a empty builder with network name and custom Context
99  *
100  * @param name Network name
101  */
102  Network(const Context& ieContext, const std::string& name);
103  /**
104  * @brief The constructor creates a builder based on INetwork with custom Context
105  *
106  * @param network constant reference to INetwork object
107  */
108  Network(const Context& ieContext, const INetwork& network);
109 
110  /**
111  * @brief Adds new layer and connects it with previous layers
112  *
113  * @param inputs Vector with PortInfo objects from previous layers
114  * @param layer Layer builder for new layer
115  *
116  * @return Id of new builder for the current network
117  */
118  idx_t addLayer(const std::vector<PortInfo>& inputs, const Layer& layer);
119  /**
120  * @brief Adds new layer
121  *
122  * @param layer Layer builder for new layer
123  *
124  * @return Id of new builder for the current network
125  */
126  idx_t addLayer(const Layer& layer);
127  /**
128  * @brief Removes a layer by ID
129  *
130  * @param layerId Layer ID
131  */
132  void removeLayer(idx_t layerId);
133 
134  /**
135  * @brief Connects two layers
136  *
137  * @param input PortInfo object from previous layer
138  * @param output PortInfo object from next layer
139  */
140  void connect(const PortInfo& input, const PortInfo& output);
141  /**
142  * @brief Removes connection from the network
143  *
144  * @param connection Connection
145  */
146  void disconnect(const Connection& connection);
147 
148  /**
149  * @brief Returns vector of layer builders
150  *
151  * @return Vector of layer builders
152  */
153  std::vector<Layer::Ptr>& getLayers();
154  /**
155  * @brief Returns constant vector of layer builders
156  *
157  * @return constant vector of layer builders
158  */
159  const std::vector<Layer::Ptr>& getLayers() const;
160 
161  /**
162  * @brief Returns a constant smart pointer to a Layer interface.
163  * If the layer is missing, returns nullptr.
164  * @param id Id of the Layer
165  * @return Layer interface smart pointer
166  */
167  const ILayer::CPtr getLayer(idx_t id) const noexcept override;
168  Layer::Ptr getLayer(idx_t layerId);
169 
170  /**
171  * @brief Returns a constant vector of input layers.
172  * @return Vector of input layers
173  */
174  const std::vector<ILayer::CPtr> getInputs() const noexcept override;
175  /**
176  * @brief Returns a vector of input layers.
177  * @return Vector of input layers
178  */
179  std::vector<Layer::Ptr> getInputs();
180 
181  /**
182  * @brief Returns a constant vector of output layers.
183  * @return Vector of output layers
184  */
185  const std::vector<ILayer::CPtr> getOutputs() const noexcept override;
186  /**
187  * @brief Returns a vector of input layers.
188  * @return Vector of input layers
189  */
190  std::vector<Layer::Ptr> getOutputs();
191 
192  /**
193  * @brief Returns a constant vector of connections for specific layer.
194  * If the layer is missing, returns empty vector.
195  * @param layerId layer index
196  * @return Vector of connections
197  */
198  const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept override;
199 
200  /**
201  * @brief Returns a constant vector of all connections.
202  * @return Vector of connections
203  */
204  const std::vector<Connection>& getConnections() const;
205 
206  /**
207  * @brief Returns a network name.
208  * @return Network name
209  */
210  const std::string& getName() const noexcept override;
211 
212  /**
213  * @brief Returns a network context
214  * @return const reference to Context
215  */
216  const Context& getContext() const noexcept override;
217  /**
218  * @brief Returns a network context
219  * @return reference to Context
220  */
221  Context& getContext() noexcept;
222 
223  /**
224  * @brief Builds and validate network
225  *
226  * @return const shared pointer to INetwork
227  */
228  const INetwork::CPtr build();
229 
230  /**
231  * @brief Validates network
232  *
233  */
234  void validate();
235 
236  /**
237  * @brief The operator builds network
238  *
239  * @return const shared pointer to INetwork
240  */
241  explicit operator const INetwork::CPtr();
242 
243 private:
244  std::map<std::string, Parameter> parameters;
245 };
246 
247 /**
248  * @deprecated Use ngraph API instead.
249  * @brief This function converts INetwork to ICNNNetwork
250  *
251  * @param network constant shared pointer to INetwork object
252  * @return constant shared pointer to ICNNNetwork
253  */
254 INFERENCE_ENGINE_NN_BUILDER_DEPRECATED
255 INFERENCE_ENGINE_API_CPP(const std::shared_ptr<ICNNNetwork>) convertToICNNNetwork(const INetwork::CPtr& network);
256 
257 IE_SUPPRESS_DEPRECATED_END
258 
259 } // namespace Builder
260 
261 } // namespace InferenceEngine
const std::shared_ptr< ICNNNetwork > convertToICNNNetwork(const INetwork::CPtr &network)
This function converts INetwork to ICNNNetwork.
A header file that provides wrapper for ICNNNetwork object.
This class implements a builder for IE Layer.
Definition: ie_layer_builder.hpp:43
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
This class implements object.
Definition: ie_context.hpp:25
A header file for Blob and generic TBlob<>
details::INetworkIterator< Network, Layer > iterator
An iterator for Network builder definition.
Definition: ie_network_builder.hpp:42
This is a header file for the ICNNNetwork class.
std::shared_ptr< const INetwork > CPtr
A shared pointer to the constant INetwork object.
Definition: ie_network.hpp:428
This class implements a builder for IE Network.
Definition: ie_network_builder.hpp:33
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:42
size_t idx_t
A type of network objects indexes.
Definition: ie_network.hpp:29
This class is the main interface to describe the Inference Engine network.
Definition: ie_network.hpp:421
details::INetworkIterator< const INetwork, const ILayer > const_iterator
A constant iterator for INetwork definition.
Definition: ie_network.hpp:432
This class is the main interface to describe the Inference Engine layer.
Definition: ie_network.hpp:346
a header file for the Inference Engine Network interface
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:38
This is a header file for the IE Context class.
This class is the main object to describe the Inference Engine connection.
Definition: ie_network.hpp:103
This class contains a pair from layerId and port index.
Definition: ie_network.hpp:35
This is a header file with common inference engine definitions.
std::shared_ptr< Network > Ptr
A shared pointer to the Network builder.
Definition: ie_network_builder.hpp:38