ie_network.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  * @brief A header file for the Inference Engine Network interface
7  *
8  * @file ie_network.hpp
9  */
10 #pragma once
11 
12 #include <ie_blob.h>
13 #include <ie_layouts.h>
14 
15 #include <ie_context.hpp>
16 #include <ie_parameter.hpp>
17 #include <map>
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 namespace InferenceEngine {
24 
25 /**
26  * @deprecated Use ngraph API instead.
27  * @brief A type of network objects indexes.
28  */
29 using idx_t = size_t;
30 
31 /**
32  * @deprecated Use ngraph API instead.
33  * @brief This class contains a pair from layerId and port index
34  */
35 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(PortInfo) {
36 public:
37  /**
38  * @brief The constructor creates a PortInfo object for port 0
39  *
40  * @param layerID Layer id
41  */
42  PortInfo(idx_t layerID): layer(layerID), port(0) {} // NOLINT
43 
44  /**
45  * @brief The constructor creates a PortInfo object
46  *
47  * @param layerID Layer id
48  * @param portID Port id
49  */
50  PortInfo(idx_t layerID, idx_t portID): layer(layerID), port(portID) {}
51 
52  /**
53  * @brief Get layer id
54  *
55  * @return Layer id
56  */
57  idx_t layerId() const {
58  return layer;
59  }
60 
61  /**
62  * @brief Get port id
63  *
64  * @return Port id
65  */
66  idx_t portId() const {
67  return port;
68  }
69 
70  IE_SUPPRESS_DEPRECATED_START
71 
72  /**
73  * @brief Compares the given PortInfo object with the current one
74  *
75  * @param portInfo PortInfo object to compare with
76  * @return true if the given PortInfo object is equal to the current one, false - otherwise
77  */
78  bool operator==(const PortInfo& portInfo) const {
79  return layer == portInfo.layerId() && port == portInfo.portId();
80  }
81 
82  /**
83  * @brief Checks if the given PortInfo object is not equal to the current one
84  *
85  * @param portInfo PortInfo object to compare with
86  * @return true if the given PortInfo object is not equal to the current one, false - otherwise
87  */
88  bool operator!=(const PortInfo& portInfo) const {
89  return !(*this == portInfo);
90  }
91 
92  IE_SUPPRESS_DEPRECATED_END
93 
94 private:
95  idx_t layer;
96  idx_t port;
97 };
98 
99 /**
100  * @deprecated Use ngraph API instead.
101  * @brief This class is the main object to describe the Inference Engine connection.
102  */
103 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED Connection {
104 public:
105  IE_SUPPRESS_DEPRECATED_START
106 
107  /**
108  * @brief Constructor of a connection object.
109  *
110  * @param input pair of the index of input layer and the index of output port
111  * @param output pair of the index of output layer and the index of input port
112  */
113  Connection(const PortInfo& input, const PortInfo& output): input(input), output(output) {}
114 
115  /**
116  * @brief Compares the given Connection with the current one
117  *
118  * @param connection Connection to compare with
119  * @return true if the given Connection is equal to the current one, false - otherwise
120  */
121  bool operator==(const Connection& connection) const {
122  return input == connection.from() && output == connection.to();
123  }
124 
125  /**
126  * @brief Checks if the given Connection is not equal to the current one
127  *
128  * @param connection Connection to compare with
129  * @return true if the given Connection is not equal to the current one, false - otherwise
130  */
131  bool operator!=(const Connection& connection) const {
132  return !(*this == connection);
133  }
134 
135  /**
136  * Returns a constant reference to a pair of input layer index and output port index.
137  * @return pair of the index of input layer and the index of output port
138  */
139  const PortInfo& from() const {
140  return input;
141  }
142 
143  /**
144  * Returns a constant reference to a pair of output layer index and input port index.
145  * @return pair of the index of output layer and the index of input port
146  */
147  const PortInfo& to() const {
148  return output;
149  }
150 
151 private:
152  PortInfo input;
153  PortInfo output;
154 
155  IE_SUPPRESS_DEPRECATED_END
156 };
157 
158 /**
159  * @deprecated Use ngraph API instead.
160  * This class describes port data
161  */
162 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(PortData) {
163 public:
164  IE_SUPPRESS_DEPRECATED_START
165 
166  /**
167  * @brief A shared pointer to the PortData object
168  */
169  using Ptr = std::shared_ptr<PortData>;
170 
171  IE_SUPPRESS_DEPRECATED_END
172 
173  /**
174  * @brief Default constructor
175  */
176  PortData();
177 
178  /**
179  * @brief Creates port data with precision and shape
180  *
181  * @param shape Dimensions
182  * @param precision Precision
183  */
184  PortData(const SizeVector& shape, const Precision& precision);
185 
186  /**
187  * @brief Virtual destructor
188  */
189  virtual ~PortData() = default;
190 
191  /**
192  * @brief Returns data
193  *
194  * @return Blob with data
195  */
196  const Blob::Ptr& getData() const;
197 
198  /**
199  * @brief Sets data
200  *
201  * @param data Blob with data
202  */
203  void setData(const Blob::Ptr& data);
204 
205  /**
206  * @brief Returns data parameters
207  *
208  * @return Map of parameters
209  */
210  const std::map<std::string, Parameter>& getParameters() const noexcept;
211 
212  /**
213  * @brief Sets new shapes for data
214  *
215  * @param shape New shapes
216  */
217  void setShape(const SizeVector& shape);
218 
219 private:
220  Blob::Ptr data;
221  std::map<std::string, Parameter> parameters;
222 
223  void createData(const TensorDesc& desc);
224 };
225 
226 /**
227  * @deprecated Use ngraph API instead.
228  * @brief This class is the main object to describe the Inference Engine port.
229  */
230 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(Port) {
231 public:
232  /**
233  * @brief Default constructor of a port object
234  */
235  Port();
236 
237  /**
238  * @brief Constructor of a port object with shapes
239  *
240  * @param shapes port shapes
241  * @param precision Port precision
242  */
243  Port(const SizeVector& shapes, const Precision& precision = Precision::UNSPECIFIED);
244 
245  /**
246  * @brief Virtual destructor
247  */
248  virtual ~Port() = default;
249 
250  IE_SUPPRESS_DEPRECATED_START
251 
252  /**
253  * @brief Copy constructor.
254  * @param port object to copy
255  */
256  Port(const Port& port);
257 
258  /**
259  * @brief Compares the given Port with the current one
260  *
261  * @param rhs Port to compare with
262  * @return true if the given Port is equal to the current one, false - otherwise
263  */
264  bool operator==(const Port& rhs) const;
265 
266  /**
267  * @brief Compares the given Port with the current one
268  *
269  * @param rhs Port to compare with
270  * @return true if the given Port is NOT equal to the current one, false - otherwise
271  */
272  bool operator!=(const Port& rhs) const;
273 
274  IE_SUPPRESS_DEPRECATED_END
275 
276  /**
277  * @brief Returns a constant reference to a vector with shapes
278  *
279  * Shapes should be initialized if shape is empty.
280  * @return constant reference to shapes
281  */
282  const SizeVector& shape() const noexcept;
283 
284  /**
285  * @brief Sets new shapes for current port
286  *
287  * @param shape New shapes
288  */
289  void setShape(const SizeVector& shape);
290 
291  /**
292  * @brief Returns a constant reference to parameters
293  *
294  * @return Map with parameters
295  */
296  const std::map<std::string, Parameter>& getParameters() const noexcept;
297 
298  /**
299  * @brief Sets new parameters for current port
300  *
301  * @param params New parameters
302  */
303  void setParameters(const std::map<std::string, Parameter>& params) noexcept;
304 
305  /**
306  * @brief Sets the new parameter for current port
307  *
308  * @param name Name of parameter
309  * @param param New value
310  */
311  void setParameter(const std::string& name, const Parameter& param);
312 
313  IE_SUPPRESS_DEPRECATED_START
314 
315  /**
316  * @brief Returns port data
317  *
318  * @return Port data
319  */
320  const PortData::Ptr& getData() const noexcept;
321 
322  /**
323  * @brief Sets new port data for current port
324  *
325  * @param data Port data
326  */
327  void setData(const PortData::Ptr& data);
328 
329 private:
330  std::map<std::string, Parameter> parameters;
331  PortData::Ptr data;
332 
333  IE_SUPPRESS_DEPRECATED_END
334 };
335 
336 class INetwork;
337 template <class T>
339 
340 /**
341  * @deprecated Use ngraph API instead.
342  * @brief This class is the main interface to describe the Inference Engine layer.
343  *
344  * All methods here are constant and do not throw exceptions.
345  */
346 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED ILayer {
347 public:
348  IE_SUPPRESS_DEPRECATED_START
349 
350  /**
351  * @brief A shared pointer to the const ILayer object
352  */
353  using CPtr = std::shared_ptr<const ILayer>;
354 
355  IE_SUPPRESS_DEPRECATED_END
356 
357  /**
358  * @brief Virtual destructor for the layer interface
359  */
360  virtual ~ILayer() = default;
361 
362  /**
363  * @brief Returns a id of the layer
364  *
365  * @return Layer id
366  */
367  virtual idx_t getId() const noexcept = 0;
368 
369  /**
370  * @brief Returns a layer name
371  *
372  * @return Layer name
373  */
374  virtual const std::string& getName() const noexcept = 0;
375 
376  /**
377  * @brief Returns a layer type
378  * @return Layer type
379  */
380  virtual const std::string& getType() const noexcept = 0;
381 
382  /**
383  * @brief Returns a constant smart pointer reference to a Parameters interface
384  *
385  * @return Parameters interface smart pointer
386  */
387  virtual const std::map<std::string, Parameter>& getParameters() const noexcept = 0;
388 
389  IE_SUPPRESS_DEPRECATED_START
390 
391  /**
392  * @brief Returns a constant reference to a vector with input ports
393  *
394  * @return Vector of input ports
395  */
396  virtual const std::vector<Port>& getInputPorts() const noexcept = 0;
397 
398  /**
399  * @brief Returns a constant reference to a vector with output ports
400  *
401  * @return Vector of output ports
402  */
403  virtual const std::vector<Port>& getOutputPorts() const noexcept = 0;
404 
405  IE_SUPPRESS_DEPRECATED_END
406 };
407 
408 namespace details {
409 
410 template <class NT, class LT>
411 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED INetworkIterator;
412 
413 } // namespace details
414 
415 /**
416  * @deprecated Use ngraph API instead.
417  * @brief This class is the main interface to describe the Inference Engine network.
418  *
419  * All methods here are constant and do not throw exceptions.
420  */
421 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED INetwork {
422 public:
423  IE_SUPPRESS_DEPRECATED_START
424 
425  /**
426  * @brief A shared pointer to the constant INetwork object.
427  */
428  using CPtr = std::shared_ptr<const INetwork>;
429  /**
430  * @brief A constant iterator for INetwork definition
431  */
432  using const_iterator = details::INetworkIterator<const INetwork, const ILayer>;
433 
434  IE_SUPPRESS_DEPRECATED_END
435 
436  /**
437  * @brief Virtual destructor for the network interface
438  */
439  virtual ~INetwork() = default;
440 
441  /**
442  * @brief Begin network iterator
443  *
444  * @return const INetwork iterator
445  */
446  virtual const_iterator begin() const noexcept = 0;
447 
448  /**
449  * @brief End network iterator
450  *
451  * @return const INetwork iterator
452  */
453  virtual const_iterator end() const noexcept = 0;
454 
455  /**
456  * @brief Returns a number of layers in the network.
457  *
458  * @return Layers count
459  */
460  virtual size_t size() const noexcept = 0;
461 
462  IE_SUPPRESS_DEPRECATED_START
463 
464  /**
465  * @brief Returns a constant smart pointer to a Layer interface.
466  *
467  * If the layer is missing, returns nullptr.
468  *
469  * @param id Id of the Layer
470  * @return Layer interface smart pointer
471  */
472  virtual const ILayer::CPtr getLayer(idx_t id) const noexcept = 0;
473 
474  /**
475  * @brief Returns a constant vector of input layers.
476  *
477  * @return Vector of input layers
478  */
479  virtual const std::vector<ILayer::CPtr> getInputs() const noexcept = 0;
480 
481  /**
482  * @brief Returns a constant vector of output layers.
483  *
484  * @return Vector of output layers
485  */
486  virtual const std::vector<ILayer::CPtr> getOutputs() const noexcept = 0;
487 
488  /**
489  * @brief Returns a constant vector of connections for specific layer.
490  *
491  * If the layer is missing, returns empty vector.
492  *
493  * @param layerId layer index
494  * @return Vector of connections
495  */
496  virtual const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept = 0;
497 
498  /**
499  * @brief Returns a network context
500  *
501  * @return const reference to Context
502  */
503  virtual const Context& getContext() const noexcept = 0;
504 
505  IE_SUPPRESS_DEPRECATED_END
506 
507  /**
508  * @brief Returns a network name.
509  * @return Network name
510  */
511  virtual const std::string& getName() const noexcept = 0;
512 };
513 
514 } // namespace InferenceEngine
515 
516 #include <details/ie_inetwork_iterator.hpp>
PortInfo(idx_t layerID)
The constructor creates a PortInfo object for port 0.
Definition: ie_network.hpp:42
bool operator==(const Connection &connection) const
Compares the given Connection with the current one.
Definition: ie_network.hpp:121
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
const PortInfo & from() const
Definition: ie_network.hpp:139
std::string name
Layer name.
Definition: ie_layers.h:42
std::vector< int > shape
A vector of sizes of the shape.
Definition: ie_layers.h:1035
This class implements object.
Definition: ie_context.hpp:25
std::shared_ptr< const ILayer > CPtr
A shared pointer to the const ILayer object.
Definition: ie_network.hpp:353
A header file for Blob and generic TBlob<>
Connection(const PortInfo &input, const PortInfo &output)
Constructor of a connection object.
Definition: ie_network.hpp:113
std::shared_ptr< const INetwork > CPtr
A shared pointer to the constant INetwork object.
Definition: ie_network.hpp:428
PortInfo(idx_t layerID, idx_t portID)
The constructor creates a PortInfo object.
Definition: ie_network.hpp:50
bool operator!=(const PortInfo &portInfo) const
Checks if the given PortInfo object is not equal to the current one.
Definition: ie_network.hpp:88
idx_t portId() const
Get port id.
Definition: ie_network.hpp:66
This class defines Tensor description.
Definition: ie_layouts.h:153
const PortInfo & to() const
Definition: ie_network.hpp:147
idx_t layerId() const
Get layer id.
Definition: ie_network.hpp:57
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:42
A header file for data layouts and conversion between them.
Definition: ie_network.hpp:338
size_t idx_t
A type of network objects indexes.
Definition: ie_network.hpp:29
A header file for the Parameter class.
This class is the main interface to describe the Inference Engine network.
Definition: ie_network.hpp:421
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:37
std::map< std::string, std::string > params
Map of pairs: (parameter name, parameter value)
Definition: ie_layers.h:367
details::INetworkIterator< const INetwork, const ILayer > const_iterator
A constant iterator for INetwork definition.
Definition: ie_network.hpp:432
std::shared_ptr< PortData > Ptr
A shared pointer to the PortData object.
Definition: ie_network.hpp:169
This class is the main interface to describe the Inference Engine layer.
Definition: ie_network.hpp:346
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:37
bool operator!=(const Connection &connection) const
Checks if the given Connection is not equal to the current one.
Definition: ie_network.hpp:131
This class is the main object to describe the Inference Engine port.
Definition: ie_network.hpp:230
bool operator==(const PortInfo &portInfo) const
Compares the given PortInfo object with the current one.
Definition: ie_network.hpp:78
Precision precision
Layer precision.
Definition: ie_layers.h:52
std::vector< size_t > SizeVector
Represents tensor size.
Definition: ie_common.h:29
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
Definition: ie_network.hpp:162
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:22
Definition: ie_precision.hpp:26