ie_network_builder.hpp
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <builders/ie_layer_builder.hpp>
8 #include <ie_icnn_network.hpp>
9 #include <cpp/ie_cnn_network.h>
10 #include <ie_inetwork.hpp>
11 #include <ie_context.hpp>
12 #include <ie_common.h>
13 #include <ie_blob.h>
14 #include <utility>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 #include <map>
19 
20 namespace InferenceEngine {
21 namespace Builder {
22 
23 /**
24  * @brief This class implements a builder for IE Network
25  */
26 class INFERENCE_ENGINE_API_CLASS(Network) {
27 public:
28  /**
29  * @brief A shared pointer to the Network builder
30  */
31  using Ptr = std::shared_ptr<Network>;
32 
33  /**
34  * @brief The constructor creates a builder based on ICNNNetwork
35  *
36  * @param network constant reference to ICNNNetwork object
37  */
38  explicit Network(const ICNNNetwork& network);
39  /**
40  * @brief The constructor creates a empty builder with network name
41  *
42  * @param name Network name
43  */
44  explicit Network(const std::string& name);
45  /**
46  * @brief The constructor creates a builder based on INetwork
47  *
48  * @param network constant reference to INetwork object
49  */
50  explicit Network(const INetwork& network);
51 
52  /**
53  * @brief The constructor creates a builder based on ICNNNetwork with custom Context
54  *
55  * @param network constant reference to ICNNNetwork object
56  */
57  Network(const Context& ieContext, const ICNNNetwork& network);
58  /**
59  * @brief The constructor creates a empty builder with network name and custom Context
60  *
61  * @param name Network name
62  */
63  Network(const Context& ieContext, const std::string& name);
64  /**
65  * @brief The constructor creates a builder based on INetwork with custom Context
66  *
67  * @param network constant reference to INetwork object
68  */
69  Network(const Context& ieContext, const INetwork& network);
70 
71  /**
72  * @brief Virtual destructor
73  */
74  virtual ~Network() = default;
75 
76  /**
77  * @brief Adds new layer and connects it with previous layers
78  *
79  * @param inputs Vector with PortInfo objects from previous layers
80  * @param layer Layer builder for new layer
81  *
82  * @return Id of new builder for the current network
83  */
84  idx_t addLayer(const std::vector<PortInfo>& inputs, const Layer& layer);
85  /**
86  * @brief Adds new layer
87  *
88  * @param layer Layer builder for new layer
89  *
90  * @return Id of new builder for the current network
91  */
92  idx_t addLayer(const Layer& layer);
93  /**
94  * @brief Removes a layer by ID
95  *
96  * @param layerId Layer ID
97  */
98  void removeLayer(idx_t layerId);
99 
100  /**
101  * @brief Connects two layers
102  *
103  * @param input PortInfo object from previous layer
104  * @param output PortInfo object from next layer
105  */
106  void connect(const PortInfo& input, const PortInfo& output);
107  /**
108  * @brief Removes connection from the network
109  *
110  * @param connection Connection
111  */
112  void disconnect(const Connection& connection);
113 
114  /**
115  * @brief Returns layer builder by ID
116  *
117  * @param layerId Layer ID
118  *
119  * @return Layer buider
120  */
121  Layer& getLayer(idx_t layerId);
122  /**
123  * @brief Returns constant layer builder by ID
124  *
125  * @param layerId Layer ID
126  *
127  * @return constant layer builder
128  */
129  const Layer& getLayer(idx_t layerId) const;
130 
131  /**
132  * @brief Returns vector of layer builders
133  *
134  * @return Vector of layer builders
135  */
136  std::vector<Layer>& getLayers();
137  /**
138  * @brief Returns constant vector of layer builders
139  *
140  * @return constant vector of layer builders
141  */
142  const std::vector<Layer>& getLayers() const;
143 
144  /**
145  * @brief Returns all connections for layer
146  *
147  * @param layerId Layer ID
148  *
149  * @return Vector of connections for the current layer
150  */
151  const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept;
152 
153  /**
154  * @brief Builds and validate networks
155  *
156  * @return const shared pointer to INetwork
157  */
158  const INetwork::Ptr build() const;
159 
160  /**
161  * @brief The operator builds network
162  *
163  * @return const shared pointer to INetwork
164  */
165  explicit operator const INetwork::Ptr() const;
166 
167 private:
168  const Context ctx;
169  const size_t version;
170  std::string name;
171  std::vector<Layer> layers;
172  std::vector<Connection> connections;
173 };
174 
175 /**
176  * @brief This function converts INetwork to ICNNNetwork
177  *
178  * @param network constant shared pointer to INetwork object
179  * @return constant shared pointer to ICNNNetwork
180  */
181 INFERENCE_ENGINE_API_CPP(const std::shared_ptr<ICNNNetwork>) convertToICNNNetwork(const INetwork::Ptr& network);
182 
183 } // namespace Builder
184 
185 } // namespace InferenceEngine
A header file that provides wrapper for ICNNNetwork object.
Definition: ie_argmax_layer.hpp:11
a header file for the Inference Engine Network interface
A header file for Blob and generic TBlob<>
This is a header file for the ICNNNetwork class.
size_t idx_t
A type of network objects indexes.
Definition: ie_inetwork.hpp:26
This is a header file for the IE Context class.
This is a header file with common inference engine definitions.
std::shared_ptr< INetwork > Ptr
A shared pointer to the INetwork object.
Definition: ie_inetwork.hpp:294