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  * @param layout Data layout
78  */
79  Data(const std::string &name, Precision _precision, Layout layout = NCHW);
80 
81  /**
82  * @brief A full constructor (with dimensions)
83  * @param name Name of the data node
84  * @param a_dims Data tensor dimensions
85  * @param _precision Precision of the data
86  * @param layout Data layout
87  */
88  Data(const std::string &name, const SizeVector &a_dims, Precision _precision, Layout layout = NCHW);
89  /**
90  * @brief A constructor with tensor descriptor
91  * @param name Name of the data node
92  * @param desc Tensor descriptor
93  */
94  Data(const std::string &name, const TensorDesc& desc);
95 
96  /**
97  * @brief A copy constructor
98  * @param data A data
99  */
100  Data(const Data & data);
101 
102  /**
103  * @brief A destructor
104  */
105  ~Data();
106 
107  /**
108  * @brief An assignment operator
109  */
110  Data & operator = (const Data &);
111 
112  /**
113  * @brief Checks if the current node is resolved
114  * @return true if resolved, false otherwise.
115  */
116  bool isInitialized() const;
117 
118  /**
119  * @brief Sets the data dimensions.
120  * After the current node is marked as resolved.
121  * @param a_dims Tensor dimensions to set
122  */
123  void setDims(const SizeVector &a_dims);
124 
125  /**
126  * @deprecated Use Data::setDims to set batch size.
127  * @brief Sets the batch value in the data dimensions.
128  * Batch is defined as the last element in the dimensions vector.
129  * @param batch_size Batch size to set
130  */
131  INFERENCE_ENGINE_DEPRECATED
132  void setBatchSize(size_t batch_size);
133 
134  /**
135  * @brief Sets the layout value for this Data instance
136  * @param layout Layout value to set
137  */
138  void setLayout(Layout layout);
139 
140  /**
141  * @brief changes dims and layout at same time
142  * @param dims new dimensions
143  * @param layout new layout
144  */
145  void reshape(const SizeVector &dims, Layout layout);
146 
147  /**
148  * @brief Gets the layout value for this Data instance
149  */
150  Layout getLayout() const;
151 
152  /**
153  * @brief Gets Tensor descriptor reference
154  @return reference to TensorDesc
155  */
156  const TensorDesc& getTensorDesc() const;
157 
158  /**
159  * @brief Gets a precision type of this Data instance
160  * @return Precision type
161  */
162  const Precision& getPrecision() const;
163 
164  /**
165  * @brief Sets a precision type of this Data instance
166  * @param precision Precision of the data
167  */
168  void setPrecision(const Precision& precision);
169 
170  /**
171  * @return data dimensions
172  */
173  const SizeVector& getDims() const;
174 
175  /**
176  * @return owner of this data layer, parent layer in di-graph
177  */
178  CNNLayerWeakPtr& getCreatorLayer();
179 
180  /**
181  * @return name of the data object
182  */
183  const std::string& getName() const;
184 
185 
186  /**
187  * @brief Sets a name the Data object
188  * @param newName Name of the data node
189  */
190 
191  void setName(const std::string& newName);
192 
193  /**
194  * @brief returns child layers in di-graph
195  */
196  std::map<std::string, CNNLayerPtr>& getInputTo();
197 
198  /**
199  * @return convenient arbitrary user data holder
200  */
201  const UserValue& getUserObject() const;
202 private:
203  mutable TensorDesc tensorDesc;
204 };
205 } // 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