ie_data.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This header file defines the main Data representation node.
7  * @file ie_data.h
8  */
9 #pragma once
10 
11 #include <map>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include "details/ie_exception.hpp"
17 #include "ie_api.h"
18 #include "ie_common.h"
19 #include "ie_layouts.h"
20 #include "ie_precision.hpp"
21 
22 namespace InferenceEngine {
23 /**
24  * @brief This class represents the main Data representation node.
25  *
26  * The NN graphs are di-graphs consisting of data nodes and layer nodes.
27  */
28 class INFERENCE_ENGINE_API_CLASS(Data) {
29 public:
30  /**
31  * @brief An empty constructor (dimensionless)
32  * @param name Name of the data node
33  * @param _precision Precision of the data
34  * @param layout Data layout
35  */
36  Data(const std::string& name, Precision _precision, Layout layout = NCHW);
37 
38  /**
39  * @deprecated Use Data(const std::string &name, const TensorDesc& desc)
40  * @brief A full constructor (with dimensions)
41  * @param name Name of the data node
42  * @param a_dims Data tensor dimensions
43  * @param _precision Precision of the data
44  * @param layout Data layout
45  */
46  INFERENCE_ENGINE_DEPRECATED("Use Data(const std::string &name, const TensorDesc& desc) as a replacement."
47  "The ctor will be removed in 2020 R2")
48  Data(const std::string& name, const SizeVector& a_dims, Precision _precision, Layout layout = NCHW);
49  /**
50  * @brief A constructor with tensor descriptor
51  * @param name Name of the data node
52  * @param desc Tensor descriptor
53  */
54  Data(const std::string& name, const TensorDesc& desc);
55 
56  /**
57  * @brief A virtual destructor
58  */
59  virtual ~Data() = default;
60 
61  /**
62  * @brief Checks if the current node is resolved
63  * @return true if resolved, false otherwise.
64  */
65  bool isInitialized() const;
66 
67  /**
68  * @brief Sets the data dimensions.
69  * After the current node is marked as resolved.
70  * @param a_dims Tensor dimensions to set
71  */
72  void setDims(const SizeVector& a_dims);
73 
74  /**
75  * @brief Sets the layout value for this Data instance
76  * @param layout Layout value to set
77  */
78  void setLayout(Layout layout);
79 
80  /**
81  * @brief changes dims and layout at same time
82  * @param dims new dimensions
83  * @param layout new layout
84  */
85  void reshape(const SizeVector& dims, Layout layout);
86 
87  /**
88  * @brief Gets the layout value for this Data instance
89  */
90  Layout getLayout() const;
91 
92  /**
93  * @brief Gets Tensor descriptor reference
94  @return reference to TensorDesc
95  */
96  const TensorDesc& getTensorDesc() const;
97 
98  /**
99  * @brief Gets a precision type of this Data instance
100  * @return Precision type
101  */
102  const Precision& getPrecision() const;
103 
104  /**
105  * @brief Sets a precision type of this Data instance
106  * @param precision Precision of the data
107  */
108  void setPrecision(const Precision& precision);
109 
110  /**
111  * @return data dimensions
112  */
113  const SizeVector& getDims() const;
114 
115  /**
116  * @return owner of this data layer, parent layer in di-graph
117  */
118  virtual CNNLayerWeakPtr& getCreatorLayer();
119 
120  /**
121  * @return name of the data object
122  */
123  const std::string& getName() const;
124 
125  /**
126  * @brief Sets a name the Data object
127  * @param newName Name of the data node
128  */
129 
130  void setName(const std::string& newName);
131 
132  /**
133  * @brief returns child layers in di-graph
134  */
135  virtual std::map<std::string, CNNLayerPtr>& getInputTo();
136 
137  /**
138  * @return convenient arbitrary user data holder
139  */
140  const UserValue& getUserObject() const;
141 
142 private:
143  /**
144  * @brief A pointer to the layer that creates this data element, null for input data elements
145  */
146  CNNLayerWeakPtr creatorLayer;
147 
148  /**
149  * @brief A unique name that identifies this data node
150  */
151  std::string name;
152 
153  /**
154  * @brief A map of layers that use this node as input.
155  * It is useful for recursive NN graph traversal.
156  */
157  std::map<std::string, CNNLayerPtr> inputTo;
158 
159  /**
160  * @brief A user utility place holder
161  */
162  UserValue userObject;
163 
164  /**
165  * @brief A tensor descriptor
166  */
167  mutable TensorDesc tensorDesc;
168 };
169 } // namespace InferenceEngine
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:77
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:67
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
std::weak_ptr< CNNLayer > CNNLayerWeakPtr
A smart weak pointer to the CNNLayer.
Definition: ie_common.h:41
This class defines Tensor description.
Definition: ie_layouts.h:140
A header file that provides class for describing precision of data.
A header file for data layouts and conversion between them.
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
Use Data(const std::string &name, const TensorDesc &desc) as a replacement." "The ctor will be removed in 2020 R2") Data( const std Data(const std::string &name, const TensorDesc &desc)
A full constructor (with dimensions)
Definition: ie_data.h:54
std::vector< size_t > SizeVector
Represents tensor size. The order is opposite to the order in Caffe*: (w,h,n,b) where the most freque...
Definition: ie_common.h:27
This class represents the main Data representation node.
Definition: ie_data.h:28
This is a header file with common inference engine definitions.
A header file for the main Inference Engine exception.
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:21