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 <vector>
14 #include "ie_api.h"
15 #include "ie_common.h"
16 #include "details/ie_exception.hpp"
17 #include "ie_precision.hpp"
18 #include "ie_layouts.h"
19 #include <string>
20 
21 namespace InferenceEngine {
22 /**
23  * @brief This class represents the main Data representation node.
24  *
25  * The NN graphs are di-graphs consisting of data nodes and layer nodes.
26  */
27 class INFERENCE_ENGINE_API_CLASS(Data) {
28 public:
29  /**
30  * @deprecated Use Data::getPrecision
31  * @brief A precision type of this Data instance
32  */
33  INFERENCE_ENGINE_DEPRECATED
35  /**
36  * @deprecated Use Data::getFormat
37  * @brief A data layout of this Data instance
38  */
39  INFERENCE_ENGINE_DEPRECATED
41  /**
42  * @deprecated Use Data::getDims
43  * @brief A tensor dimension array (the order is opposite to the order in the IR: w,h,c,n) of this Data instance
44  */
45  INFERENCE_ENGINE_DEPRECATED
47  /**
48  * @deprecated Use Data::getCreatorLayer
49  * @brief A pointer to the layer that creates this data element, null for input data elements
50  */
51  INFERENCE_ENGINE_DEPRECATED
53  /**
54  * @deprecated Use Data::getName
55  * @brief A unique name that identifies this data node
56  */
57  INFERENCE_ENGINE_DEPRECATED
58  std::string name;
59  /**
60  * @deprecated Use Data::getInputTo
61  * @brief A map of layers that use this node as input.
62  * It is useful for recursive NN graph traversal.
63  */
64  INFERENCE_ENGINE_DEPRECATED
65  std::map<std::string, CNNLayerPtr> inputTo;
66  /**
67  * @deprecated Use Data::getUserObject
68  * @brief A user utility place holder
69  */
70  INFERENCE_ENGINE_DEPRECATED
72 
73  /**
74  * @brief An empty constructor (dimensionless)
75  * @param name Name of the data node
76  * @param _precision Precision of the data
77  */
78  Data(const std::string &name, Precision _precision, Layout layout = NCHW);
79 
80  /**
81  * @brief A full constructor (with dimensions)
82  * @param name Name of the data node
83  * @param a_dims Data tensor dimensions
84  * @param _precision Precision of the data
85  */
86  Data(const std::string &name, const SizeVector &a_dims, Precision _precision, Layout layout = NCHW);
87  /**
88  * @brief A constructor with tensor descriptor
89  * @param name Name of the data node
90  * @param desc Tensor descriptor
91  */
92  Data(const std::string &name, const TensorDesc& desc);
93 
94  /**
95  * @brief A copy constructor
96  * @param data A data
97  */
98  Data(const Data & data);
99 
100  /**
101  * @brief A destructor
102  */
103  ~Data();
104 
105  /**
106  * @brief An assignment operator
107  */
108  Data & operator = (const Data &);
109 
110  /**
111  * @brief Checks if the current node is resolved
112  * @return true if resolved, false otherwise.
113  */
114  bool isInitialized() const;
115 
116  /**
117  * @brief Sets the data dimensions.
118  * After the current node is marked as resolved.
119  * @param a_dims Tensor dimensions to set
120  */
121  void setDims(const SizeVector &a_dims);
122 
123  /**
124  * @deprecated Use Data::setDims to set batch size.
125  * @brief Sets the batch value in the data dimensions.
126  * Batch is defined as the last element in the dimensions vector.
127  * @param batch_size Batch size to set
128  */
129  INFERENCE_ENGINE_DEPRECATED
130  void setBatchSize(size_t batch_size);
131 
132  /**
133  * @brief Sets the layout value for this Data instance
134  * @param layout Layout value to set
135  */
136  void setLayout(Layout layout);
137 
138  /**
139  * @brief changes dims and layout at same time
140  * @param dims new dimensions
141  * @param layout new layout
142  */
143  void reshape(const SizeVector &dims, Layout layout);
144 
145  /**
146  * @brief Gets the layout value for this Data instance
147  */
148  Layout getLayout() const;
149 
150  /**
151  * @brief Gets Tensor descriptor reference
152  @return reference to TensorDesc
153  */
154  const TensorDesc& getTensorDesc() const;
155 
156  /**
157  * @brief Gets a precision type of this Data instance
158  * @return Precision type
159  */
160  const Precision& getPrecision() const;
161 
162  /**
163  * @brief Sets a precision type of this Data instance
164  * @param precision Precision of the data
165  */
166  void setPrecision(const Precision& precision);
167 
168  /**
169  * @return data dimensions
170  */
171  const SizeVector& getDims() const;
172 
173  /**
174  * @return owner of this data layer, parent layer in di-graph
175  */
176  CNNLayerWeakPtr& getCreatorLayer();
177 
178  /**
179  * @return name of the data object
180  */
181  const std::string& getName() const;
182 
183 
184  /**
185  * @brief Sets a name the Data object
186  * @param name Name of the data node
187  */
188 
189  void setName(const std::string& newName);
190 
191  /**
192  * @brief returns child layers in di-graph
193  */
194  std::map<std::string, CNNLayerPtr>& getInputTo();
195 
196  /**
197  * @return convenient arbitrary user data holder
198  */
199  const UserValue& getUserObject() const;
200 private:
201  mutable TensorDesc tensorDesc;
202 };
203 } // namespace InferenceEngine
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:66
UserValue userObject
A user utility place holder.
Definition: ie_data.h:71
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:26
Definition: ie_argmax_layer.hpp:11
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:76
std::map< std::string, CNNLayerPtr > inputTo
A map of layers that use this node as input. It is useful for recursive NN graph traversal.
Definition: ie_data.h:65
std::weak_ptr< CNNLayer > CNNLayerWeakPtr
A smart weak pointer to the CNNLayer.
Definition: ie_common.h:40
This class defines Tensor description.
Definition: ie_layouts.h:143
CNNLayerWeakPtr creatorLayer
A pointer to the layer that creates this data element, null for input data elements.
Definition: ie_data.h:52
A header file that provides class for describing precision of data.
A header file for data layouts and conversion between them.
Precision precision
A precision type of this Data instance.
Definition: ie_data.h:34
Layout layout
A data layout of this Data instance.
Definition: ie_data.h:40
std::string name
A unique name that identifies this data node.
Definition: ie_data.h:58
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
This class represents the main Data representation node.
Definition: ie_data.h:27
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:19
SizeVector dims
A tensor dimension array (the order is opposite to the order in the IR: w,h,c,n) of this Data instanc...
Definition: ie_data.h:46