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 ieContext constant reference to Context object
95  * @param network constant reference to ICNNNetwork object
96  */
97  Network(const Context& ieContext, const ICNNNetwork& network);
98  /**
99  * @brief The constructor creates a empty builder with network name and custom Context
100  *
101  * @param ieContext constant reference to Context object
102  * @param name Network name
103  */
104  Network(const Context& ieContext, const std::string& name);
105  /**
106  * @brief The constructor creates a builder based on INetwork with custom Context
107  *
108  * @param ieContext constant reference to Context object
109  * @param network constant reference to INetwork object
110  */
111  Network(const Context& ieContext, const INetwork& network);
112 
113  /**
114  * @brief Adds new layer and connects it with previous layers
115  *
116  * @param inputs Vector with PortInfo objects from previous layers
117  * @param layer Layer builder for new layer
118  *
119  * @return Id of new builder for the current network
120  */
121  idx_t addLayer(const std::vector<PortInfo>& inputs, const Layer& layer);
122  /**
123  * @brief Adds new layer
124  *
125  * @param layer Layer builder for new layer
126  *
127  * @return Id of new builder for the current network
128  */
129  idx_t addLayer(const Layer& layer);
130  /**
131  * @brief Removes a layer by ID
132  *
133  * @param layerId Layer ID
134  */
135  void removeLayer(idx_t layerId);
136 
137  /**
138  * @brief Connects two layers
139  *
140  * @param input PortInfo object from previous layer
141  * @param output PortInfo object from next layer
142  */
143  void connect(const PortInfo& input, const PortInfo& output);
144  /**
145  * @brief Removes connection from the network
146  *
147  * @param connection Connection
148  */
149  void disconnect(const Connection& connection);
150 
151  /**
152  * @brief Returns vector of layer builders
153  *
154  * @return Vector of layer builders
155  */
156  std::vector<Layer::Ptr>& getLayers();
157  /**
158  * @brief Returns constant vector of layer builders
159  *
160  * @return constant vector of layer builders
161  */
162  const std::vector<Layer::Ptr>& getLayers() const;
163 
164  /**
165  * @brief Returns a constant smart pointer to a Layer interface.
166  * If the layer is missing, returns nullptr.
167  * @param id Id of the Layer
168  * @return Layer interface smart pointer
169  */
170  const ILayer::CPtr getLayer(idx_t id) const noexcept override;
171  Layer::Ptr getLayer(idx_t layerId);
172 
173  /**
174  * @brief Returns a constant vector of input layers.
175  * @return Vector of input layers
176  */
177  const std::vector<ILayer::CPtr> getInputs() const noexcept override;
178  /**
179  * @brief Returns a vector of input layers.
180  * @return Vector of input layers
181  */
182  std::vector<Layer::Ptr> getInputs();
183 
184  /**
185  * @brief Returns a constant vector of output layers.
186  * @return Vector of output layers
187  */
188  const std::vector<ILayer::CPtr> getOutputs() const noexcept override;
189  /**
190  * @brief Returns a vector of input layers.
191  * @return Vector of input layers
192  */
193  std::vector<Layer::Ptr> getOutputs();
194 
195  /**
196  * @brief Returns a constant vector of connections for specific layer.
197  * If the layer is missing, returns empty vector.
198  * @param layerId layer index
199  * @return Vector of connections
200  */
201  const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept override;
202 
203  /**
204  * @brief Returns a constant vector of all connections.
205  * @return Vector of connections
206  */
207  const std::vector<Connection>& getConnections() const;
208 
209  /**
210  * @brief Returns a network name.
211  * @return Network name
212  */
213  const std::string& getName() const noexcept override;
214 
215  /**
216  * @brief Returns a network context
217  * @return const reference to Context
218  */
219  const Context& getContext() const noexcept override;
220  /**
221  * @brief Returns a network context
222  * @return reference to Context
223  */
224  Context& getContext() noexcept;
225 
226  /**
227  * @brief Builds and validate network
228  *
229  * @return const shared pointer to INetwork
230  */
231  const INetwork::CPtr build();
232 
233  /**
234  * @brief Validates network
235  *
236  */
237  void validate();
238 
239  /**
240  * @brief The operator builds network
241  *
242  * @return const shared pointer to INetwork
243  */
244  explicit operator const INetwork::CPtr();
245 
246 private:
247  std::map<std::string, Parameter> parameters;
248 };
249 
250 /**
251  * @deprecated Use ngraph API instead.
252  * @brief This function converts INetwork to ICNNNetwork
253  *
254  * @param network constant shared pointer to INetwork object
255  * @return constant shared pointer to ICNNNetwork
256  */
257 INFERENCE_ENGINE_NN_BUILDER_DEPRECATED
258 INFERENCE_ENGINE_API_CPP(const std::shared_ptr<ICNNNetwork>) convertToICNNNetwork(const INetwork::CPtr& network);
259 
260 IE_SUPPRESS_DEPRECATED_END
261 
262 } // namespace Builder
263 
264 } // namespace InferenceEngine
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
std::string name
Layer name.
Definition: ie_layers.h:42
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:43
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:37
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