2
2
// SPDX-License-Identifier: Apache-2.0
3
3
//
4
4
5
+ #include < gflags/gflags.h>
6
+
5
7
#include < algorithm>
6
8
#include < chrono>
7
9
#include < cstdlib>
8
10
#include < fstream>
9
11
#include < iostream>
10
12
#include < map>
13
+ #include < openvino/core/partial_shape.hpp>
14
+ #include < openvino/openvino.hpp>
11
15
#include < string>
12
16
#include < unordered_map>
13
17
#include < vector>
14
18
15
- #include < gflags/gflags.h>
16
-
17
- #include < openvino/core/partial_shape.hpp>
18
- #include < openvino/openvino.hpp>
19
-
20
19
#include " tools_helpers.hpp"
21
20
22
-
23
21
static constexpr char help_message[] = " Optional. Print the usage message." ;
24
22
25
23
static constexpr char model_message[] = " Required. Path to the XML model." ;
26
24
27
25
static constexpr char targetDeviceMessage[] =
28
- " Required. Specify a target device for which executable network will be compiled.\n "
29
- " Use \" -d HETERO:<comma-separated_devices_list>\" format to "
30
- " specify HETERO plugin.\n "
31
- " Use \" -d MULTI:<comma-separated_devices_list>\" format to "
32
- " specify MULTI plugin.\n "
33
- " The application looks for a suitable plugin for the specified "
34
- " device." ;
26
+ " Required. Specify a target device for which executable network will be compiled.\n "
27
+ " Use \" -d HETERO:<comma-separated_devices_list>\" format to "
28
+ " specify HETERO plugin.\n "
29
+ " Use \" -d MULTI:<comma-separated_devices_list>\" format to "
30
+ " specify MULTI plugin.\n "
31
+ " The application looks for a suitable plugin for the specified "
32
+ " device." ;
35
33
36
34
static constexpr char output_message[] = " Optional. Path to the output file. Default value: \" <model_xml_file>.blob\" ." ;
37
35
@@ -42,42 +40,42 @@ static constexpr char config_message[] = "Optional. Path to the configuration fi
42
40
static constexpr char inputs_precision_message[] = " Optional. Specifies precision for all input layers of the network." ;
43
41
44
42
static constexpr char outputs_precision_message[] =
45
- " Optional. Specifies precision for all output layers of the network." ;
43
+ " Optional. Specifies precision for all output layers of the network." ;
46
44
47
45
static constexpr char iop_message[] =
48
- " Optional. Specifies precision for input and output layers by name.\n "
49
- " Example: -iop \" input:FP16, output:FP16\" .\n "
50
- " Notice that quotes are required.\n "
51
- " Overwrites precision from ip and op options for specified "
52
- " layers." ;
46
+ " Optional. Specifies precision for input and output layers by name.\n "
47
+ " Example: -iop \" input:FP16, output:FP16\" .\n "
48
+ " Notice that quotes are required.\n "
49
+ " Overwrites precision from ip and op options for specified "
50
+ " layers." ;
53
51
54
52
static constexpr char inputs_layout_message[] = " Optional. Specifies layout for all input layers of the network." ;
55
53
56
54
static constexpr char outputs_layout_message[] = " Optional. Specifies layout for all output layers of the network." ;
57
55
58
56
static constexpr char iol_message[] =
59
- " Optional. Specifies layout for input and output layers by name.\n "
60
- " Example: -iol \" input:NCHW, output:NHWC\" .\n "
61
- " Notice that quotes are required.\n "
62
- " Overwrites layout from il and ol options for specified layers." ;
57
+ " Optional. Specifies layout for input and output layers by name.\n "
58
+ " Example: -iol \" input:NCHW, output:NHWC\" .\n "
59
+ " Notice that quotes are required.\n "
60
+ " Overwrites layout from il and ol options for specified layers." ;
63
61
64
62
static constexpr char inputs_model_layout_message[] =
65
- " Optional. Specifies model layout for all input layers of the network." ;
63
+ " Optional. Specifies model layout for all input layers of the network." ;
66
64
67
65
static constexpr char outputs_model_layout_message[] =
68
- " Optional. Specifies model layout for all output layers of the network." ;
66
+ " Optional. Specifies model layout for all output layers of the network." ;
69
67
70
68
static constexpr char ioml_message[] =
71
- " Optional. Specifies model layout for input and output tensors by name.\n "
72
- " Example: -ionl \" input:NCHW, output:NHWC\" .\n "
73
- " Notice that quotes are required.\n "
74
- " Overwrites layout from il and ol options for specified layers." ;
69
+ " Optional. Specifies model layout for input and output tensors by name.\n "
70
+ " Example: -ionl \" input:NCHW, output:NHWC\" .\n "
71
+ " Notice that quotes are required.\n "
72
+ " Overwrites layout from il and ol options for specified layers." ;
75
73
76
74
static const char shape_message[] =
77
- " Set shape for model input. For example, \" input1[1,3,224,224],input2[1,4]\" or \" [1,3,224,224]\" "
78
- " in case of one input size. This parameter affect model input shape and can be dynamic."
79
- " For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."
80
- " For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?]." ;
75
+ " Set shape for model input. For example, \" input1[1,3,224,224],input2[1,4]\" or \" [1,3,224,224]\" "
76
+ " in case of one input size. This parameter affect model input shape and can be dynamic."
77
+ " For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."
78
+ " For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?]." ;
81
79
82
80
static const char override_model_batch_size[] = " Enforce a model to be compiled for batch size" ;
83
81
@@ -152,14 +150,14 @@ ov::element::Type getType(std::string value, const supported_type_t& supported_p
152
150
}
153
151
ov::element::Type getType (const std::string& value) {
154
152
static const supported_type_t supported_types = {
155
- {" FP32" , ov::element::f32}, {" f32" , ov::element::f32}, {" FP16" , ov::element::f16},
156
- {" f16" , ov::element::f16}, {" BF16" , ov::element::bf16}, {" bf16" , ov::element::bf16},
157
- {" U64" , ov::element::u64}, {" u64" , ov::element::u64}, {" I64" , ov::element::i64},
158
- {" i64" , ov::element::i64}, {" U32" , ov::element::u32}, {" u32" , ov::element::u32},
159
- {" I32" , ov::element::i32}, {" i32" , ov::element::i32}, {" U16" , ov::element::u16},
160
- {" u16" , ov::element::u16}, {" I16" , ov::element::i16}, {" i16" , ov::element::i16},
161
- {" U8" , ov::element::u8}, {" u8" , ov::element::u8}, {" I8" , ov::element::i8},
162
- {" i8" , ov::element::i8}, {" BOOL" , ov::element::boolean}, {" boolean" , ov::element::boolean},
153
+ {" FP32" , ov::element::f32}, {" f32" , ov::element::f32}, {" FP16" , ov::element::f16},
154
+ {" f16" , ov::element::f16}, {" BF16" , ov::element::bf16}, {" bf16" , ov::element::bf16},
155
+ {" U64" , ov::element::u64}, {" u64" , ov::element::u64}, {" I64" , ov::element::i64},
156
+ {" i64" , ov::element::i64}, {" U32" , ov::element::u32}, {" u32" , ov::element::u32},
157
+ {" I32" , ov::element::i32}, {" i32" , ov::element::i32}, {" U16" , ov::element::u16},
158
+ {" u16" , ov::element::u16}, {" I16" , ov::element::i16}, {" i16" , ov::element::i16},
159
+ {" U8" , ov::element::u8}, {" u8" , ov::element::u8}, {" I8" , ov::element::i8},
160
+ {" i8" , ov::element::i8}, {" BOOL" , ov::element::boolean}, {" boolean" , ov::element::boolean},
163
161
};
164
162
165
163
return getType (value, supported_types);
@@ -169,9 +167,15 @@ bool isFP32(const ov::element::Type& type) {
169
167
return type == ov::element::f32;
170
168
}
171
169
172
- void configurePrePostProcessing (std::shared_ptr<ov::Model>& model, const std::string& ip, const std::string& op,
173
- const std::string& iop, const std::string& il, const std::string& ol,
174
- const std::string& iol, const std::string& iml, const std::string& oml,
170
+ void configurePrePostProcessing (std::shared_ptr<ov::Model>& model,
171
+ const std::string& ip,
172
+ const std::string& op,
173
+ const std::string& iop,
174
+ const std::string& il,
175
+ const std::string& ol,
176
+ const std::string& iol,
177
+ const std::string& iml,
178
+ const std::string& oml,
175
179
const std::string& ioml) {
176
180
auto preprocessor = ov::preprocess::PrePostProcessor (model);
177
181
const auto inputs = model->inputs ();
@@ -367,17 +371,19 @@ static std::map<std::string, std::string> parseConfigFile(char comment = '#') {
367
371
continue ;
368
372
}
369
373
size_t spacePos = option.find_first_of (" \t\n\r " );
370
- OPENVINO_ASSERT (spacePos != std::string::npos, " Failed to find a space separator in "
371
- " provided plugin config option: " +
372
- option);
374
+ OPENVINO_ASSERT (spacePos != std::string::npos,
375
+ " Failed to find a space separator in "
376
+ " provided plugin config option: " +
377
+ option);
373
378
374
379
std::string key = option.substr (0 , spacePos);
375
380
376
381
std::string value{};
377
382
size_t valueStart = option.find_first_not_of (" \t\n\r " , spacePos);
378
- OPENVINO_ASSERT (valueStart != std::string::npos, " An invalid config parameter value detected, "
379
- " it mustn't be empty: " +
380
- option);
383
+ OPENVINO_ASSERT (valueStart != std::string::npos,
384
+ " An invalid config parameter value detected, "
385
+ " it mustn't be empty: " +
386
+ option);
381
387
size_t valueEnd = option.find_last_not_of (" \t\n\r " );
382
388
value = option.substr (valueStart, valueEnd - valueStart + 1 );
383
389
@@ -403,7 +409,6 @@ std::string getFileNameFromPath(const std::string& path,
403
409
404
410
using TimeDiff = std::chrono::milliseconds;
405
411
406
-
407
412
int main (int argc, char * argv[]) {
408
413
try {
409
414
TimeDiff loadNetworkTimeElapsed{0 };
@@ -444,6 +449,7 @@ int main(int argc, char* argv[]) {
444
449
if (FLAGS_shape.empty ()) {
445
450
setModelBatch (model, FLAGS_override_model_batch_size);
446
451
}
452
+
447
453
std::cout << " Printing Input and Output Info from model" << std::endl;
448
454
printInputAndOutputsInfoShort (*model);
449
455
auto timeBeforeLoadNetwork = std::chrono::steady_clock::now ();
@@ -453,7 +459,7 @@ int main(int argc, char* argv[]) {
453
459
std::cout << " Compiling model" << std::endl;
454
460
auto compiledModel = core.compile_model (model, FLAGS_d, {configs.begin (), configs.end ()});
455
461
loadNetworkTimeElapsed =
456
- std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now () - timeBeforeLoadNetwork);
462
+ std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now () - timeBeforeLoadNetwork);
457
463
std::string outputName = FLAGS_o;
458
464
if (outputName.empty ()) {
459
465
outputName = getFileNameFromPath (fileNameNoExt (FLAGS_m)) + " .blob" ;
@@ -467,6 +473,20 @@ int main(int argc, char* argv[]) {
467
473
std::cout << " Writing into file - " << outputName << std::endl;
468
474
compiledModel.export_model (outputFile);
469
475
}
476
+
477
+ // DEBUG EXPORT
478
+ // {
479
+ // std::string outputInitName = outputName.substr(0, outputName.size()-5) + "_init.blob";
480
+ // std::ofstream outputInitFile{outputInitName, std::ios::out | std::ios::binary};
481
+ // if (!outputInitFile.is_open()) {
482
+ // std::cout << "Outputting file " << outputInitName << " can't be opened for writing" << std::endl;
483
+ // return EXIT_FAILURE;
484
+ // } else {
485
+ // std::cout << "Writing into file - " << outputInitName << std::endl;
486
+ // compiledModel.export_model(outputInitFile);
487
+ // }
488
+ // }
489
+
470
490
std::cout << " Done. LoadNetwork time elapsed: " << loadNetworkTimeElapsed.count () << " ms" << std::endl;
471
491
} catch (const std::exception & error) {
472
492
std::cerr << error.what () << std::endl;
0 commit comments