|
19 | 19 | from openvino.tools import mo |
20 | 20 | from openvino.runtime import serialize |
21 | 21 | import platform |
| 22 | +import subprocess |
22 | 23 |
|
23 | 24 |
|
24 | 25 | #ov_version = sys.argv[1] |
@@ -133,10 +134,10 @@ def convert_encoder_onnx(xtext_encoder: StableDiffusionPipeline, onnx_path:Path) |
133 | 134 | try: |
134 | 135 | encoder_model = mo.convert_model(TEXT_ENCODER_ONNX_PATH, compress_to_fp16=True) |
135 | 136 | serialize(encoder_model, xml_path=os.path.join(weight_path, 'text_encoder.xml')) |
136 | | - #os.path.join(model, "vae_encoder.xml") |
| 137 | + |
137 | 138 | except: |
138 | | - os.system('%s --input_model %s --data_type=FP16 --output_dir %s' % (sd_mo_path,TEXT_ENCODER_ONNX_PATH,weight_path)) |
139 | | - |
| 139 | + subprocess.call([sd_mo_path, '--input_model', TEXT_ENCODER_ONNX_PATH, '--data_type=FP16', '--output_dir', weight_path]) |
| 140 | + |
140 | 141 | print('Text Encoder successfully converted to IR') |
141 | 142 | else: |
142 | 143 | print(f"Text encoder will be loaded from {TEXT_ENCODER_OV_PATH}") |
@@ -192,7 +193,8 @@ def convert_unet_onnx(unet:StableDiffusionPipeline, onnx_path:Path): |
192 | 193 | unet_model = mo.convert_model(UNET_ONNX_PATH, compress_to_fp16=True) |
193 | 194 | serialize(unet_model, xml_path=os.path.join(weight_path, 'unet.xml')) |
194 | 195 | except: |
195 | | - os.system('%s --input_model %s --data_type=FP16 --output_dir %s' % (sd_mo_path, UNET_ONNX_PATH,weight_path)) |
| 196 | + subprocess.call([sd_mo_path, '--input_model', UNET_ONNX_PATH, '--data_type=FP16', '--output_dir', weight_path]) |
| 197 | + |
196 | 198 |
|
197 | 199 | print('Unet successfully converted to IR') |
198 | 200 | else: |
@@ -237,12 +239,14 @@ def forward(self, image): |
237 | 239 |
|
238 | 240 | if not VAE_ENCODER_OV_PATH.exists(): |
239 | 241 | convert_vae_encoder_onnx(vae, VAE_ENCODER_ONNX_PATH) |
240 | | - #os.system('mo --input_model %s --compress_to_fp16 --output_dir %s' % (VAE_ENCODER_ONNX_PATH,weight_path)) |
| 242 | + |
241 | 243 | try: |
242 | 244 | vae_encoder_model = mo.convert_model(VAE_ENCODER_ONNX_PATH, compress_to_fp16=True) |
243 | 245 | serialize(vae_encoder_model, xml_path=os.path.join(weight_path, 'vae_encoder.xml')) |
244 | 246 | except: |
245 | | - os.system('%s --input_model %s --data_type=FP16 --output_dir %s' % (sd_mo_path,VAE_ENCODER_ONNX_PATH,weight_path)) |
| 247 | + subprocess.call([sd_mo_path, '--input_model', VAE_ENCODER_ONNX_PATH, '--data_type=FP16', '--output_dir', weight_path]) |
| 248 | + |
| 249 | + |
246 | 250 | print('VAE encoder successfully converted to IR') |
247 | 251 | else: |
248 | 252 | print(f"VAE encoder will be loaded from {VAE_ENCODER_OV_PATH}") |
@@ -284,12 +288,13 @@ def forward(self, latents): |
284 | 288 |
|
285 | 289 | if not VAE_DECODER_OV_PATH.exists(): |
286 | 290 | convert_vae_decoder_onnx(vae, VAE_DECODER_ONNX_PATH) |
287 | | - #os.system('mo --input_model %s --compress_to_fp16 --output_dir %s' % (VAE_DECODER_ONNX_PATH,weight_path)) |
| 291 | + |
288 | 292 | try: |
289 | 293 | vae_decoder_model = mo.convert_model(VAE_DECODER_ONNX_PATH, compress_to_fp16=True) |
290 | 294 | serialize(vae_decoder_model, xml_path=os.path.join(weight_path, 'vae_decoder.xml')) |
291 | 295 | except: |
292 | | - os.system('%s --input_model %s --data_type=FP16 --output_dir %s' % (sd_mo_path,VAE_DECODER_ONNX_PATH,weight_path)) |
| 296 | + subprocess.call([sd_mo_path, '--input_model', VAE_DECODER_ONNX_PATH, '--data_type=FP16', '--output_dir', weight_path]) |
| 297 | + |
293 | 298 | print('VAE decoder successfully converted to IR') |
294 | 299 | else: |
295 | 300 | print(f"VAE decoder will be loaded from {VAE_DECODER_OV_PATH}") |
|
0 commit comments