1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief a header file for the Inference Engine Network interface
13 #include <ie_layouts.h>
15 #include <ie_context.hpp>
16 #include <ie_parameter.hpp>
23 namespace InferenceEngine {
26 * @deprecated Use ngraph API instead.
27 * @brief A type of network objects indexes.
32 * @deprecated Use ngraph API instead.
33 * @brief This class contains a pair from layerId and port index
35 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(PortInfo) {
38 * @brief The constructor creates a PortInfo object for port 0
40 * @param layerID Layer id
42 PortInfo(idx_t layerID): layer(layerID), port(0) {} // NOLINT
45 * @brief The constructor creates a PortInfo object
47 * @param layerID Layer id
48 * @param portID Port id
50 PortInfo(idx_t layerID, idx_t portID): layer(layerID), port(portID) {}
57 idx_t layerId() const {
66 idx_t portId() const {
70 IE_SUPPRESS_DEPRECATED_START
73 * @brief Compares the given PortInfo object with the current one
75 * @param portInfo PortInfo object to compare with
76 * @return true if the given PortInfo object is equal to the current one, false - otherwise
78 bool operator==(const PortInfo& portInfo) const {
79 return layer == portInfo.layerId() && port == portInfo.portId();
83 * @brief Checks if the given PortInfo object is not equal to the current one
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
88 bool operator!=(const PortInfo& portInfo) const {
89 return !(*this == portInfo);
92 IE_SUPPRESS_DEPRECATED_END
100 * @deprecated Use ngraph API instead.
101 * @brief This class is the main object to describe the Inference Engine connection.
103 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED Connection {
105 IE_SUPPRESS_DEPRECATED_START
108 * @brief Constructor of a connection object.
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
113 Connection(const PortInfo& input, const PortInfo& output): input(input), output(output) {}
116 * @brief Compares the given Connection with the current one
118 * @param connection Connection to compare with
119 * @return true if the given Connection is equal to the current one, false - otherwise
121 bool operator==(const Connection& connection) const {
122 return input == connection.from() && output == connection.to();
126 * @brief Checks if the given Connection is not equal to the current one
128 * @param connection Connection to compare with
129 * @return true if the given Connection is not equal to the current one, false - otherwise
131 bool operator!=(const Connection& connection) const {
132 return !(*this == connection);
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
139 const PortInfo& from() const {
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
147 const PortInfo& to() const {
155 IE_SUPPRESS_DEPRECATED_END
159 * @deprecated Use ngraph API instead.
160 * This class describes port data
162 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(PortData) {
164 IE_SUPPRESS_DEPRECATED_START
167 * @brief A shared pointer to the PortData object
169 using Ptr = std::shared_ptr<PortData>;
171 IE_SUPPRESS_DEPRECATED_END
174 * @brief Default constructor
179 * @brief Creates port data with precision and shape
181 * @param shape Dimensions
182 * @param precision Precision
184 PortData(const SizeVector& shape, const Precision& precision);
187 * @brief Virtual destructor
189 virtual ~PortData() = default;
192 * @brief Returns data
194 * @return Blob with data
196 const Blob::Ptr& getData() const;
201 * @param data Blob with data
203 void setData(const Blob::Ptr& data);
206 * @brief Returns data parameters
208 * @return Map of parameters
210 const std::map<std::string, Parameter>& getParameters() const noexcept;
213 * @brief Sets new shapes for data
215 * @param shape New shapes
217 void setShape(const SizeVector& shape);
221 std::map<std::string, Parameter> parameters;
223 void createData(const TensorDesc& desc);
227 * @deprecated Use ngraph API instead.
228 * @brief This class is the main object to describe the Inference Engine port.
230 class INFERENCE_ENGINE_NN_BUILDER_API_CLASS(Port) {
233 * @brief Default constructor of a port object
238 * @brief Constructor of a port object with shapes
240 * @param shapes port shapes
241 * @param precision Port precision
243 Port(const SizeVector& shapes, const Precision& precision = Precision::UNSPECIFIED);
246 * @brief Virtual destructor
248 virtual ~Port() = default;
250 IE_SUPPRESS_DEPRECATED_START
253 * @brief Copy constructor.
254 * @param port object to copy
256 Port(const Port& port);
259 * @brief Compares the given Port with the current one
261 * @param rhs Port to compare with
262 * @return true if the given Port is equal to the current one, false - otherwise
264 bool operator==(const Port& rhs) const;
267 * @brief Compares the given Port with the current one
269 * @param rhs Port to compare with
270 * @return true if the given Port is NOT equal to the current one, false - otherwise
272 bool operator!=(const Port& rhs) const;
274 IE_SUPPRESS_DEPRECATED_END
277 * @brief Returns a constant reference to a vector with shapes
279 * Shapes should be initialized if shape is empty.
280 * @return constant reference to shapes
282 const SizeVector& shape() const noexcept;
285 * @brief Sets new shapes for current port
287 * @param shape New shapes
289 void setShape(const SizeVector& shape);
292 * @brief Returns a constant reference to parameters
294 * @return Map with parameters
296 const std::map<std::string, Parameter>& getParameters() const noexcept;
299 * @brief Sets new parameters for current port
301 * @param params New parameters
303 void setParameters(const std::map<std::string, Parameter>& params) noexcept;
306 * @brief Sets the new parameter for current port
308 * @param name Name of parameter
309 * @param param New value
311 void setParameter(const std::string& name, const Parameter& param);
313 IE_SUPPRESS_DEPRECATED_START
316 * @brief Returns port data
320 const PortData::Ptr& getData() const noexcept;
323 * @brief Sets new port data for current port
325 * @param data Port data
327 void setData(const PortData::Ptr& data);
330 std::map<std::string, Parameter> parameters;
333 IE_SUPPRESS_DEPRECATED_END
338 class INetwotkIterator;
341 * @deprecated Use ngraph API instead.
342 * @brief This class is the main interface to describe the Inference Engine layer.
344 * All methods here are constant and do not throw exceptions.
346 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED ILayer {
348 IE_SUPPRESS_DEPRECATED_START
351 * @brief A shared pointer to the const ILayer object
353 using CPtr = std::shared_ptr<const ILayer>;
355 IE_SUPPRESS_DEPRECATED_END
358 * @brief Virtual destructor for the layer interface
360 virtual ~ILayer() = default;
363 * @brief Returns a id of the layer
367 virtual idx_t getId() const noexcept = 0;
370 * @brief Returns a layer name
374 virtual const std::string& getName() const noexcept = 0;
377 * @brief Returns a layer type
380 virtual const std::string& getType() const noexcept = 0;
383 * @brief Returns a constant smart pointer reference to a Parameters interface
385 * @return Parameters interface smart pointer
387 virtual const std::map<std::string, Parameter>& getParameters() const noexcept = 0;
389 IE_SUPPRESS_DEPRECATED_START
392 * @brief Returns a constant reference to a vector with input ports
394 * @return Vector of input ports
396 virtual const std::vector<Port>& getInputPorts() const noexcept = 0;
399 * @brief Returns a constant reference to a vector with output ports
401 * @return Vector of output ports
403 virtual const std::vector<Port>& getOutputPorts() const noexcept = 0;
405 IE_SUPPRESS_DEPRECATED_END
410 template <class NT, class LT>
411 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED INetworkIterator;
413 } // namespace details
416 * @deprecated Use ngraph API instead.
417 * @brief This class is the main interface to describe the Inference Engine network.
419 * All methods here are constant and do not throw exceptions.
421 class INFERENCE_ENGINE_NN_BUILDER_DEPRECATED INetwork {
423 IE_SUPPRESS_DEPRECATED_START
426 * @brief A shared pointer to the constant INetwork object.
428 using CPtr = std::shared_ptr<const INetwork>;
430 * @brief A constant iterator for INetwork definition
432 using const_iterator = details::INetworkIterator<const INetwork, const ILayer>;
434 IE_SUPPRESS_DEPRECATED_END
437 * @brief Virtual destructor for the network interface
439 virtual ~INetwork() = default;
442 * @brief Begin network iterator
444 * @return const INetwork iterator
446 virtual const_iterator begin() const noexcept = 0;
449 * @brief End network iterator
451 * @return const INetwork iterator
453 virtual const_iterator end() const noexcept = 0;
456 * @brief Returns a number of layers in the network.
458 * @return Layers count
460 virtual size_t size() const noexcept = 0;
462 IE_SUPPRESS_DEPRECATED_START
465 * @brief Returns a constant smart pointer to a Layer interface.
467 * If the layer is missing, returns nullptr.
469 * @param id Id of the Layer
470 * @return Layer interface smart pointer
472 virtual const ILayer::CPtr getLayer(idx_t id) const noexcept = 0;
475 * @brief Returns a constant vector of input layers.
477 * @return Vector of input layers
479 virtual const std::vector<ILayer::CPtr> getInputs() const noexcept = 0;
482 * @brief Returns a constant vector of output layers.
484 * @return Vector of output layers
486 virtual const std::vector<ILayer::CPtr> getOutputs() const noexcept = 0;
489 * @brief Returns a constant vector of connections for specific layer.
491 * If the layer is missing, returns empty vector.
493 * @param layerId layer index
494 * @return Vector of connections
496 virtual const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept = 0;
499 * @brief Returns a network context
501 * @return const reference to Context
503 virtual const Context& getContext() const noexcept = 0;
505 IE_SUPPRESS_DEPRECATED_END
508 * @brief Returns a network name.
509 * @return Network name
511 virtual const std::string& getName() const noexcept = 0;
514 } // namespace InferenceEngine
516 #include <details/ie_inetwork_iterator.hpp>