forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ov_preprocess_test.cpp
440 lines (329 loc) · 17.6 KB
/
ov_preprocess_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "ov_test.hpp"
class ov_preprocess : public ::testing::Test {
protected:
void SetUp() override {
core = nullptr;
model = nullptr;
preprocess = nullptr;
input_info = nullptr;
input_tensor_info = nullptr;
input_process = nullptr;
tensor = nullptr;
output_info = nullptr;
output_tensor_info = nullptr;
input_model = nullptr;
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
EXPECT_NE(nullptr, model);
}
void TearDown() override {
ov_preprocess_input_model_info_free(input_model);
ov_preprocess_output_tensor_info_free(output_tensor_info);
ov_preprocess_output_info_free(output_info);
ov_tensor_free(tensor);
ov_preprocess_preprocess_steps_free(input_process);
ov_preprocess_input_tensor_info_free(input_tensor_info);
ov_preprocess_input_info_free(input_info);
ov_preprocess_prepostprocessor_free(preprocess);
ov_model_free(model);
ov_core_free(core);
}
public:
ov_core_t* core;
ov_model_t* model;
ov_preprocess_prepostprocessor_t* preprocess;
ov_preprocess_input_info_t* input_info;
ov_preprocess_input_tensor_info_t* input_tensor_info;
ov_preprocess_preprocess_steps_t* input_process;
ov_tensor_t* tensor;
ov_preprocess_output_info_t* output_info;
ov_preprocess_output_tensor_info_t* output_tensor_info;
ov_preprocess_input_model_info_t* input_model;
};
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_create) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_input_info) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info(preprocess, &input_info));
EXPECT_NE(nullptr, input_info);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_input_info_by_name) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_name(preprocess, "data", &input_info));
EXPECT_NE(nullptr, input_info);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_input_info_by_index) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
}
TEST_F(ov_preprocess, ov_preprocess_input_info_get_tensor_info) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
}
TEST_F(ov_preprocess, ov_preprocess_input_info_get_preprocess_steps) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_resize) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_preprocess_steps_resize(input_process, ov_preprocess_resize_algorithm_e::RESIZE_LINEAR));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_scale) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_preprocess_steps_scale(input_process, 2.0f));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_mean) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_preprocess_steps_mean(input_process, 2.0f));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_crop) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
int32_t begin[] = {0, 0, 5, 10};
int32_t end[] = {1, 3, 15, 20};
OV_EXPECT_OK(ov_preprocess_preprocess_steps_crop(input_process, begin, 4, end, 4));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_convert_layout) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
ov_layout_t* layout = nullptr;
const char* input_layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(input_layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_layout(input_process, layout));
ov_layout_free(layout);
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_reverse_channels) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_preprocess_steps_reverse_channels(input_process));
}
TEST_F(ov_preprocess, ov_preprocess_input_tensor_info_set_element_type) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_element_type(input_tensor_info, ov_element_type_e::F32));
}
TEST_F(ov_preprocess, ov_preprocess_input_tensor_info_set_from) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
ov_shape_t shape;
int64_t dims[4] = {1, 416, 416, 4};
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
OV_EXPECT_OK(ov_tensor_create(ov_element_type_e::F32, shape, &tensor));
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_from(input_tensor_info, tensor));
ov_shape_free(&shape);
}
TEST_F(ov_preprocess, ov_preprocess_input_tensor_info_set_layout) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
ov_layout_t* layout = nullptr;
const char* input_layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(input_layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_layout(input_tensor_info, layout));
ov_layout_free(layout);
}
TEST_F(ov_preprocess, ov_preprocess_input_tensor_info_set_color_format) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
OV_EXPECT_OK(
ov_preprocess_input_tensor_info_set_color_format(input_tensor_info, ov_color_format_e::NV12_SINGLE_PLANE));
}
TEST_F(ov_preprocess, ov_preprocess_input_tensor_info_set_spatial_static_shape) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
size_t input_height = 500;
size_t input_width = 500;
OV_EXPECT_OK(
ov_preprocess_input_tensor_info_set_spatial_static_shape(input_tensor_info, input_height, input_width));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_convert_element_type) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_element_type(input_tensor_info, ov_element_type_e::U8));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_element_type(input_process, ov_element_type_e::F32));
}
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_convert_color) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
OV_EXPECT_OK(
ov_preprocess_input_tensor_info_set_color_format(input_tensor_info, ov_color_format_e::NV12_SINGLE_PLANE));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_color(input_process, ov_color_format_e::BGR));
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_output_info) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info(preprocess, &output_info));
EXPECT_NE(nullptr, output_info);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_output_info_by_index) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info_by_index(preprocess, 0, &output_info));
EXPECT_NE(nullptr, output_info);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_output_info_by_name) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info_by_name(preprocess, "fc_out", &output_info));
EXPECT_NE(nullptr, output_info);
}
TEST_F(ov_preprocess, ov_preprocess_output_info_get_tensor_info) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info_by_index(preprocess, 0, &output_info));
EXPECT_NE(nullptr, output_info);
OV_EXPECT_OK(ov_preprocess_output_info_get_tensor_info(output_info, &output_tensor_info));
EXPECT_NE(nullptr, output_tensor_info);
}
TEST_F(ov_preprocess, ov_preprocess_output_set_element_type) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info_by_index(preprocess, 0, &output_info));
EXPECT_NE(nullptr, output_info);
OV_EXPECT_OK(ov_preprocess_output_info_get_tensor_info(output_info, &output_tensor_info));
EXPECT_NE(nullptr, output_tensor_info);
OV_EXPECT_OK(ov_preprocess_output_set_element_type(output_tensor_info, ov_element_type_e::F32));
}
TEST_F(ov_preprocess, ov_preprocess_input_info_get_model_info) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
EXPECT_NE(nullptr, input_model);
}
TEST_F(ov_preprocess, ov_preprocess_input_model_info_set_layout) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
EXPECT_NE(nullptr, input_model);
ov_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_build) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
ov_model_t* new_model = nullptr;
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
EXPECT_NE(nullptr, new_model);
ov_model_free(new_model);
}
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_build_apply) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
EXPECT_NE(nullptr, input_tensor_info);
ov_shape_t shape;
int64_t dims[4] = {1, 416, 416, 3};
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
OV_EXPECT_OK(ov_tensor_create(ov_element_type_e::U8, shape, &tensor));
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_from(input_tensor_info, tensor));
const char* layout_desc = "NHWC";
ov_layout_t* layout = nullptr;
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_layout(input_tensor_info, layout));
ov_layout_free(layout);
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);
OV_EXPECT_OK(ov_preprocess_preprocess_steps_resize(input_process, ov_preprocess_resize_algorithm_e::RESIZE_LINEAR));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
EXPECT_NE(nullptr, input_model);
const char* model_layout_desc = "NCHW";
ov_layout_t* model_layout = nullptr;
OV_EXPECT_OK(ov_layout_create(model_layout_desc, &model_layout));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, model_layout));
ov_layout_free(model_layout);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_output_info_by_index(preprocess, 0, &output_info));
EXPECT_NE(nullptr, output_info);
OV_EXPECT_OK(ov_preprocess_output_info_get_tensor_info(output_info, &output_tensor_info));
EXPECT_NE(nullptr, output_tensor_info);
OV_EXPECT_OK(ov_preprocess_output_set_element_type(output_tensor_info, ov_element_type_e::F32));
ov_model_t* new_model = nullptr;
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
EXPECT_NE(nullptr, new_model);
ov_shape_free(&shape);
ov_model_free(new_model);
}