Skip to content

Commit a38afb6

Browse files
committed
replaced os.system calls with subprocess to handle paths with spaces in them
1 parent 31e7016 commit a38afb6

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

choose_sd_model.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import platform
55

66
if platform.system() == "Linux":
7-
sd_python_path=os.path.join(".", "model_conv/bin/python3")
7+
sd_python_path=os.path.join(".", "model_conv/bin/python3")
8+
chose_model=os.path.join(os.path.dirname(__file__), "sd_model_conversion.py")
89
else:
9-
sd_python_path=r'model_conv\Scripts\python.exe'
10-
11-
12-
chose_model=os.path.join(os.path.dirname(__file__), "sd_model_conversion.py") #r'openvino-ai-plugins-gimp\sd_model_conversion.py'
10+
sd_python_path=r'model_conv\Scripts\python.exe'
11+
chose_model=r'openvino-ai-plugins-gimp\sd_model_conversion.py'
1312

1413
print("=========Chose SD-1.5 models to download and convert=========")
1514
print("1 - Square (512x512 output image) ")
@@ -26,20 +25,22 @@
2625

2726
if choice=="6":
2827
for i in range(1,6):
29-
command = sd_python_path + ' ' + chose_model + ' ' + str(i)
30-
os.system(command)
28+
29+
subprocess.call([sd_python_path, chose_model, str(i)])
30+
3131
break
3232
elif choice=="7":
3333
for i in range(1,4):
34-
command = sd_python_path + ' ' + chose_model + ' ' + str(i)
35-
os.system(command)
34+
35+
subprocess.call([sd_python_path, chose_model, str(i)])
3636
break
3737
elif choice=="8":
3838
print("Exiting SD-1.5 Model setup.........")
3939
break
4040
elif choice in ["1","2","3","4","5"]:
41-
command = sd_python_path + ' ' + chose_model + ' ' + choice
42-
os.system(command)
41+
42+
subprocess.call([sd_python_path, chose_model, choice])
43+
4344
break
4445

4546
else:

sd_model_conversion.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from openvino.tools import mo
2020
from openvino.runtime import serialize
2121
import platform
22+
import subprocess
2223

2324

2425
#ov_version = sys.argv[1]
@@ -133,10 +134,10 @@ def convert_encoder_onnx(xtext_encoder: StableDiffusionPipeline, onnx_path:Path)
133134
try:
134135
encoder_model = mo.convert_model(TEXT_ENCODER_ONNX_PATH, compress_to_fp16=True)
135136
serialize(encoder_model, xml_path=os.path.join(weight_path, 'text_encoder.xml'))
136-
#os.path.join(model, "vae_encoder.xml")
137+
137138
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+
140141
print('Text Encoder successfully converted to IR')
141142
else:
142143
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):
192193
unet_model = mo.convert_model(UNET_ONNX_PATH, compress_to_fp16=True)
193194
serialize(unet_model, xml_path=os.path.join(weight_path, 'unet.xml'))
194195
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+
196198

197199
print('Unet successfully converted to IR')
198200
else:
@@ -237,12 +239,14 @@ def forward(self, image):
237239

238240
if not VAE_ENCODER_OV_PATH.exists():
239241
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+
241243
try:
242244
vae_encoder_model = mo.convert_model(VAE_ENCODER_ONNX_PATH, compress_to_fp16=True)
243245
serialize(vae_encoder_model, xml_path=os.path.join(weight_path, 'vae_encoder.xml'))
244246
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+
246250
print('VAE encoder successfully converted to IR')
247251
else:
248252
print(f"VAE encoder will be loaded from {VAE_ENCODER_OV_PATH}")
@@ -284,12 +288,13 @@ def forward(self, latents):
284288

285289
if not VAE_DECODER_OV_PATH.exists():
286290
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+
288292
try:
289293
vae_decoder_model = mo.convert_model(VAE_DECODER_ONNX_PATH, compress_to_fp16=True)
290294
serialize(vae_decoder_model, xml_path=os.path.join(weight_path, 'vae_decoder.xml'))
291295
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+
293298
print('VAE decoder successfully converted to IR')
294299
else:
295300
print(f"VAE decoder will be loaded from {VAE_DECODER_OV_PATH}")

0 commit comments

Comments
 (0)