9
9
10
10
#pragma once
11
11
12
- #include < algorithm>
13
- #include < fstream>
14
- #include < functional>
15
- #include < iomanip>
16
- #include < iostream>
17
- #include < list>
18
- #include < limits>
19
- #include < map>
20
12
#include < string>
21
- #include < random >
13
+ #include < map >
22
14
#include < vector>
15
+ #include < list>
16
+ #include < limits>
17
+ #include < functional>
18
+ #include < fstream>
19
+ #include < iomanip>
23
20
#include < utility>
21
+ #include < algorithm>
22
+ #include < random>
23
+ #include < iostream>
24
24
25
25
#include < inference_engine.hpp>
26
26
#include " openvino/openvino.hpp"
27
27
#include " utils/slog.hpp"
28
28
#include " utils/args_helper.hpp"
29
29
30
30
#ifndef UNUSED
31
- #ifdef _WIN32
32
- #define UNUSED
33
- #else
34
- #define UNUSED __attribute__ ((unused))
35
- #endif
31
+ #ifdef _WIN32
32
+ #define UNUSED
33
+ #else
34
+ #define UNUSED __attribute__ ((unused))
35
+ #endif
36
36
#endif
37
37
38
38
template <typename T, std::size_t N>
@@ -86,8 +86,8 @@ class Color {
86
86
* @param b - value for blue channel
87
87
*/
88
88
Color (unsigned char r,
89
- unsigned char g,
90
- unsigned char b) : _r(r), _g(g), _b(b) {}
89
+ unsigned char g,
90
+ unsigned char b) : _r(r), _g(g), _b(b) {}
91
91
92
92
inline unsigned char red () const {
93
93
return _r;
@@ -132,16 +132,17 @@ inline std::size_t getTensorWidth(const InferenceEngine::TensorDesc& desc) {
132
132
const auto & dims = desc.getDims ();
133
133
const auto & size = dims.size ();
134
134
if ((size >= 2 ) &&
135
- (layout == InferenceEngine::Layout::NCHW ||
136
- layout == InferenceEngine::Layout::NHWC ||
137
- layout == InferenceEngine::Layout::NCDHW ||
138
- layout == InferenceEngine::Layout::NDHWC ||
139
- layout == InferenceEngine::Layout::OIHW ||
140
- layout == InferenceEngine::Layout::CHW ||
141
- layout == InferenceEngine::Layout::HW)) {
135
+ (layout == InferenceEngine::Layout::NCHW ||
136
+ layout == InferenceEngine::Layout::NHWC ||
137
+ layout == InferenceEngine::Layout::NCDHW ||
138
+ layout == InferenceEngine::Layout::NDHWC ||
139
+ layout == InferenceEngine::Layout::OIHW ||
140
+ layout == InferenceEngine::Layout::CHW ||
141
+ layout == InferenceEngine::Layout::HW)) {
142
142
// Regardless of layout, dimensions are stored in fixed order
143
143
return dims.back ();
144
- } else {
144
+ }
145
+ else {
145
146
throw std::runtime_error (" Tensor does not have width dimension" );
146
147
}
147
148
return 0 ;
@@ -152,72 +153,75 @@ inline std::size_t getTensorHeight(const InferenceEngine::TensorDesc& desc) {
152
153
const auto & dims = desc.getDims ();
153
154
const auto & size = dims.size ();
154
155
if ((size >= 2 ) &&
155
- (layout == InferenceEngine::Layout::NCHW ||
156
- layout == InferenceEngine::Layout::NHWC ||
157
- layout == InferenceEngine::Layout::NCDHW ||
158
- layout == InferenceEngine::Layout::NDHWC ||
159
- layout == InferenceEngine::Layout::OIHW ||
160
- layout == InferenceEngine::Layout::CHW ||
161
- layout == InferenceEngine::Layout::HW)) {
156
+ (layout == InferenceEngine::Layout::NCHW ||
157
+ layout == InferenceEngine::Layout::NHWC ||
158
+ layout == InferenceEngine::Layout::NCDHW ||
159
+ layout == InferenceEngine::Layout::NDHWC ||
160
+ layout == InferenceEngine::Layout::OIHW ||
161
+ layout == InferenceEngine::Layout::CHW ||
162
+ layout == InferenceEngine::Layout::HW)) {
162
163
// Regardless of layout, dimensions are stored in fixed order
163
164
return dims.at (size - 2 );
164
- } else {
165
+ }
166
+ else {
165
167
throw std::runtime_error (" Tensor does not have height dimension" );
166
168
}
167
169
return 0 ;
168
170
}
169
171
170
172
inline std::size_t getTensorChannels (const InferenceEngine::TensorDesc& desc) {
171
173
const auto & layout = desc.getLayout ();
172
- if (layout == InferenceEngine::Layout::NCHW ||
173
- layout == InferenceEngine::Layout::NHWC ||
174
+ if (layout == InferenceEngine::Layout::NCHW ||
175
+ layout == InferenceEngine::Layout::NHWC ||
174
176
layout == InferenceEngine::Layout::NCDHW ||
175
177
layout == InferenceEngine::Layout::NDHWC ||
176
- layout == InferenceEngine::Layout::C ||
177
- layout == InferenceEngine::Layout::CHW ||
178
- layout == InferenceEngine::Layout::NC ||
178
+ layout == InferenceEngine::Layout::C ||
179
+ layout == InferenceEngine::Layout::CHW ||
180
+ layout == InferenceEngine::Layout::NC ||
179
181
layout == InferenceEngine::Layout::CN) {
180
182
// Regardless of layout, dimensions are stored in fixed order
181
183
const auto & dims = desc.getDims ();
182
184
switch (desc.getLayoutByDims (dims)) {
183
- case InferenceEngine::Layout::C: return dims.at (0 );
184
- case InferenceEngine::Layout::NC: return dims.at (1 );
185
- case InferenceEngine::Layout::CHW: return dims.at (0 );
186
- case InferenceEngine::Layout::NCHW: return dims.at (1 );
187
- case InferenceEngine::Layout::NCDHW: return dims.at (1 );
188
- case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
189
- case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
190
- default :
191
- throw std::runtime_error (" Tensor does not have channels dimension" );
185
+ case InferenceEngine::Layout::C: return dims.at (0 );
186
+ case InferenceEngine::Layout::NC: return dims.at (1 );
187
+ case InferenceEngine::Layout::CHW: return dims.at (0 );
188
+ case InferenceEngine::Layout::NCHW: return dims.at (1 );
189
+ case InferenceEngine::Layout::NCDHW: return dims.at (1 );
190
+ case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
191
+ case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
192
+ default :
193
+ throw std::runtime_error (" Tensor does not have channels dimension" );
192
194
}
193
- } else {
195
+ }
196
+ else {
194
197
throw std::runtime_error (" Tensor does not have channels dimension" );
195
198
}
196
199
return 0 ;
197
200
}
198
201
199
202
inline std::size_t getTensorBatch (const InferenceEngine::TensorDesc& desc) {
200
203
const auto & layout = desc.getLayout ();
201
- if (layout == InferenceEngine::Layout::NCHW ||
202
- layout == InferenceEngine::Layout::NHWC ||
204
+ if (layout == InferenceEngine::Layout::NCHW ||
205
+ layout == InferenceEngine::Layout::NHWC ||
203
206
layout == InferenceEngine::Layout::NCDHW ||
204
207
layout == InferenceEngine::Layout::NDHWC ||
205
- layout == InferenceEngine::Layout::NC ||
208
+ layout == InferenceEngine::Layout::NC ||
206
209
layout == InferenceEngine::Layout::CN) {
207
210
// Regardless of layout, dimensions are stored in fixed order
208
211
const auto & dims = desc.getDims ();
209
212
switch (desc.getLayoutByDims (dims)) {
210
- case InferenceEngine::Layout::NC: return dims.at (0 );
211
- case InferenceEngine::Layout::NCHW: return dims.at (0 );
212
- case InferenceEngine::Layout::NCDHW: return dims.at (0 );
213
- case InferenceEngine::Layout::CHW: // [[fallthrough]]
214
- case InferenceEngine::Layout::C: // [[fallthrough]]
215
- case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
216
- case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
217
- default :
218
- throw std::runtime_error (" Tensor does not have channels dimension" );
213
+ case InferenceEngine::Layout::NC: return dims.at (0 );
214
+ case InferenceEngine::Layout::NCHW: return dims.at (0 );
215
+ case InferenceEngine::Layout::NCDHW: return dims.at (0 );
216
+ case InferenceEngine::Layout::CHW: // [[fallthrough]]
217
+ case InferenceEngine::Layout::C: // [[fallthrough]]
218
+ case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
219
+ case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
220
+ default :
221
+ throw std::runtime_error (" Tensor does not have channels dimension" );
219
222
}
220
- } else {
223
+ }
224
+ else {
221
225
throw std::runtime_error (" Tensor does not have channels dimension" );
222
226
}
223
227
return 0 ;
0 commit comments