@@ -70,9 +70,9 @@ def convert_to_onnx(reporter, model, output_dir, args, template_variables):
70
70
71
71
return success
72
72
73
- def convert (reporter , model , output_dir , args , mo_props , requested_precisions ):
73
+ def convert (reporter , model , output_dir , args , ovc_props , requested_precisions ):
74
74
telemetry = _common .Telemetry ()
75
- if model .mo_args is None :
75
+ if model .ovc_args is None :
76
76
reporter .print_section_heading ('Skipping {} (no conversions defined)' , model .name )
77
77
reporter .print ()
78
78
return True
@@ -92,16 +92,16 @@ def convert(reporter, model, output_dir, args, mo_props, requested_precisions):
92
92
return False
93
93
94
94
model_format = model .framework
95
- mo_extension_dir = mo_props .base_dir / 'extensions'
96
- if not mo_extension_dir .exists ():
97
- mo_extension_dir = mo_props .base_dir
95
+ ovc_extension_dir = ovc_props .base_dir / 'extensions'
96
+ if not ovc_extension_dir .exists ():
97
+ ovc_extension_dir = ovc_props .base_dir
98
98
99
99
template_variables = {
100
100
'config_dir' : _common .MODEL_ROOT / model .subdirectory ,
101
101
'conv_dir' : output_dir / model .subdirectory ,
102
102
'dl_dir' : args .download_dir / model .subdirectory ,
103
- 'mo_dir ' : mo_props .base_dir ,
104
- 'mo_ext_dir ' : mo_extension_dir ,
103
+ 'ovc_dir ' : ovc_props .base_dir ,
104
+ 'ovc_ext_dir ' : ovc_extension_dir ,
105
105
}
106
106
107
107
if model .conversion_to_onnx_args :
@@ -112,52 +112,54 @@ def convert(reporter, model, output_dir, args, mo_props, requested_precisions):
112
112
return False
113
113
model_format = 'onnx'
114
114
115
- expanded_mo_args = [
115
+ custom_ovc_args = [
116
116
string .Template (arg ).substitute (template_variables )
117
- for arg in model .mo_args ]
117
+ for arg in model .ovc_args ]
118
+
119
+ expanded_ovc_args = []
120
+ input_model = ''
121
+ for arg in custom_ovc_args :
122
+ if 'input_model' in arg :
123
+ input_model = arg .split ('=' )[- 1 ]
124
+ reporter .print (f'Model { input_model } ' )
125
+ # if 'output' in arg:
126
+ # expanded_ovc_args.append(arg)
118
127
119
128
for model_precision in sorted (model_precisions ):
120
129
data_type = model_precision .split ('-' )[0 ]
121
- layout_string = ',' .join (
122
- '{}({})' .format (input .name , input .layout ) for input in model .input_info if input .layout
123
- )
124
- shape_string = ',' .join (str (input .shape ) for input in model .input_info if input .shape )
130
+ shape_string = ',' .join (str (input .shape ).replace (" " , "" ) for input in model .input_info if input .shape )
125
131
126
- if layout_string :
127
- expanded_mo_args .append ('--layout={}' .format (layout_string ))
128
132
if shape_string :
129
- expanded_mo_args .append ('--input_shape ={}' .format (shape_string ))
133
+ expanded_ovc_args .append ('--input ={}' .format (shape_string ))
130
134
if data_type == "FP16" :
131
- expanded_mo_args .append ("--compress_to_fp16=True" )
135
+ expanded_ovc_args .append ("--compress_to_fp16=True" )
132
136
else :
133
- expanded_mo_args .append ("--compress_to_fp16=False" )
137
+ expanded_ovc_args .append ("--compress_to_fp16=False" )
134
138
135
- mo_output_dir = output_dir / model .subdirectory / model_precision
136
- mo_cmd = [* mo_props .cmd_prefix ,
137
- '--framework={}' .format (model_format ),
138
- f'--output_dir={ mo_output_dir } ' ,
139
- '--model_name={}' .format (model .name ),
140
- '--input={}' .format (',' .join (input .name for input in model .input_info )),
141
- * expanded_mo_args , * mo_props .extra_args ]
139
+ ovc_output_dir = output_dir / model .subdirectory / model_precision
140
+ ovc_cmd = [* ovc_props .cmd_prefix ,
141
+ input_model ,
142
+ f'--output_model={ str (Path (ovc_output_dir , model .name + ".xml" ))} ' ,
143
+ * expanded_ovc_args ]
142
144
143
145
reporter .print_section_heading ('{}Converting {} to IR ({})' ,
144
146
'(DRY RUN) ' if args .dry_run else '' , model .name , model_precision )
145
147
146
- reporter .print ('Conversion command: {}' , _common .command_string (mo_cmd ))
148
+ reporter .print ('Conversion command: {}' , _common .command_string (ovc_cmd ))
147
149
148
150
if not args .dry_run :
149
151
reporter .print (flush = True )
150
152
151
- if not reporter .job_context .subprocess (mo_cmd ):
153
+ if not reporter .job_context .subprocess (ovc_cmd ):
152
154
telemetry .send_event ('md' , 'converter_failed_models' , model .name )
153
155
telemetry .send_event ('md' , 'converter_error' ,
154
- json .dumps ({'error' : 'mo -failed' , 'model' : model .name , 'precision' : model_precision }))
156
+ json .dumps ({'error' : 'ovc -failed' , 'model' : model .name , 'precision' : model_precision }))
155
157
return False
156
158
157
159
reporter .print ()
158
160
core = Core ()
159
161
core .set_property ({"ENABLE_MMAP" : False })
160
- rt_model = core .read_model (str (mo_output_dir / model .name ) + '.xml' )
162
+ rt_model = core .read_model (str (ovc_output_dir / model .name ) + '.xml' )
161
163
try :
162
164
val = validation .validate_string ('model_type' , model .model_info ['model_type' ])
163
165
rt_model .set_rt_info (val , ['model_info' , 'model_type' ])
@@ -193,7 +195,7 @@ def convert(reporter, model, output_dir, args, mo_props, requested_precisions):
193
195
rt_model .set_rt_info (val , ['model_info' , 'labels' ])
194
196
except KeyError :
195
197
pass
196
- save_model (rt_model , str (mo_output_dir / model .name ) + '.xml' , "FP16" == data_type )
198
+ save_model (rt_model , str (ovc_output_dir / model .name ) + '.xml' , "FP16" == data_type )
197
199
return True
198
200
199
201
def num_jobs_arg (value_str ):
@@ -223,18 +225,20 @@ def converter(argv):
223
225
parser .add_argument ('--precisions' , metavar = 'PREC[,PREC...]' ,
224
226
help = 'run only conversions that produce models with the specified precisions' )
225
227
parser .add_argument ('-p' , '--python' , type = Path , metavar = 'PYTHON' , default = sys .executable ,
226
- help = 'Python executable to run Model Optimizer with' )
227
- parser .add_argument ('--mo' , type = Path , metavar = 'MO.PY' ,
228
- help = 'Model Optimizer entry point script' )
229
- parser .add_argument ('--add_mo_arg' , dest = 'extra_mo_args' , metavar = 'ARG' , action = 'append' ,
230
- help = 'Extra argument to pass to Model Optimizer' )
228
+ help = 'Python executable to run OVC Converter with' )
229
+ parser .add_argument ('--add_ovc_arg' , dest = 'extra_ovc_args' , metavar = 'ARG' , action = 'append' ,
230
+ help = 'Extra argument to pass to OVC Converter' )
231
231
parser .add_argument ('--dry_run' , action = 'store_true' ,
232
232
help = 'Print the conversion commands without running them' )
233
233
parser .add_argument ('-j' , '--jobs' , type = num_jobs_arg , default = 1 ,
234
234
help = 'number of conversions to run concurrently' )
235
235
236
236
# aliases for backwards compatibility
237
- parser .add_argument ('--add-mo-arg' , dest = 'extra_mo_args' , action = 'append' , help = argparse .SUPPRESS )
237
+ parser .add_argument ('--mo' , type = Path , metavar = 'MO.PY' ,
238
+ help = 'OVC Converter entry point script' )
239
+ parser .add_argument ('--add_mo_arg' , dest = 'extra_ovc_args' , metavar = 'ARG' , action = 'append' ,
240
+ help = 'Extra argument to pass to OVC Converter' )
241
+ parser .add_argument ('--add-mo-arg' , dest = 'extra_ovc_args' , action = 'append' , help = argparse .SUPPRESS )
238
242
parser .add_argument ('--dry-run' , action = 'store_true' , help = argparse .SUPPRESS )
239
243
240
244
args = parser .parse_args (argv )
@@ -268,47 +272,47 @@ def converter(argv):
268
272
if unknown_precisions :
269
273
sys .exit ('Unknown precisions specified: {}.' .format (', ' .join (sorted (unknown_precisions ))))
270
274
271
- mo_path = args .mo
275
+ ovc_path = args .mo
272
276
273
- if mo_path is None :
274
- mo_executable = shutil .which ('mo ' )
277
+ if ovc_path is None :
278
+ ovc_executable = shutil .which ('ovc ' )
275
279
276
- if mo_executable :
277
- mo_path = Path (mo_executable )
280
+ if ovc_executable :
281
+ ovc_path = Path (ovc_executable )
278
282
else :
279
283
try :
280
- mo_path = Path (os .environ ['INTEL_OPENVINO_DIR' ]) / 'tools/mo/openvino/tools/mo/mo.py'
281
- if not mo_path .exists ():
282
- mo_path = Path (os .environ ['INTEL_OPENVINO_DIR' ]) / 'tools/model_optimizer/mo .py'
284
+ # ovc_path = Path(os.environ['INTEL_OPENVINO_DIR']) / 'tools/mo/openvino/tools/mo/mo.py'
285
+ # if not ovc_path .exists():
286
+ ovc_path = Path (os .environ ['INTEL_OPENVINO_DIR' ]) / 'tools/ovc/ovc .py'
283
287
except KeyError :
284
- sys .exit ('Unable to locate Model Optimizer . '
285
- + 'Use --mo or run setupvars.sh/setupvars.bat from the OpenVINO toolkit.' )
288
+ sys .exit ('Unable to locate OVC Converter . '
289
+ + 'Use --ovc or run setupvars.sh/setupvars.bat from the OpenVINO toolkit.' )
286
290
287
- if mo_path is not None :
288
- mo_path = mo_path .resolve ()
289
- mo_cmd_prefix = [str (args .python ), '--' , str (mo_path )]
291
+ if ovc_path is not None :
292
+ ovc_path = ovc_path .resolve ()
293
+ ovc_cmd_prefix = [str (args .python ), '--' , str (ovc_path )]
290
294
291
- if str (mo_path ).lower ().endswith ('.py' ):
292
- mo_dir = mo_path .parent
295
+ if str (ovc_path ).lower ().endswith ('.py' ):
296
+ ovc_dir = ovc_path .parent
293
297
else :
294
- mo_package_path , stderr = _common .get_package_path (args .python , 'openvino.tools.mo ' )
295
- mo_dir = mo_package_path
298
+ ovc_package_path , stderr = _common .get_package_path (args .python , 'openvino.tools.ovc ' )
299
+ ovc_dir = ovc_package_path
296
300
297
- if mo_package_path is None :
298
- mo_package_path , stderr = _common .get_package_path (args .python , 'mo ' )
299
- if mo_package_path is None :
301
+ if ovc_package_path is None :
302
+ ovc_package_path , stderr = _common .get_package_path (args .python , 'ovc ' )
303
+ if ovc_package_path is None :
300
304
sys .exit ('Unable to load Model Optimizer. Errors occurred: {}' .format (stderr ))
301
- mo_dir = mo_package_path .parent
305
+ ovc_dir = ovc_package_path .parent
302
306
303
307
output_dir = args .download_dir if args .output_dir is None else args .output_dir
304
308
305
309
reporter = _reporting .Reporter (_reporting .DirectOutputContext ())
306
- mo_props = ModelOptimizerProperties (
307
- cmd_prefix = mo_cmd_prefix ,
308
- extra_args = args .extra_mo_args or [],
309
- base_dir = mo_dir ,
310
+ ovc_props = ModelOptimizerProperties (
311
+ cmd_prefix = ovc_cmd_prefix ,
312
+ extra_args = args .extra_ovc_args or [],
313
+ base_dir = ovc_dir ,
310
314
)
311
- shared_convert_args = (output_dir , args , mo_props , requested_precisions )
315
+ shared_convert_args = (output_dir , args , ovc_props , requested_precisions )
312
316
313
317
def convert_model (model , reporter ):
314
318
if model .model_stages :
0 commit comments