@@ -139,7 +139,7 @@ def convert_model(model_name, output_path, opset=13, tag=None, verbose=True):
139
139
large_model = ext == ".zip"
140
140
if not os .path .exists (output_path ):
141
141
begin = datetime .datetime .now ()
142
- cmdl = ['-m' , 'tf2onnx.convert' , '--saved-model' ,
142
+ cmdl = ['python' , ' -m' , 'tf2onnx.convert' , '--saved-model' ,
143
143
'"%s"' % os .path .abspath (model_name ).replace ("\\ " , "/" ),
144
144
'--output' , '"%s"' % os .path .abspath (output_path ).replace ("\\ " , "/" ),
145
145
'--opset' , "%d" % opset ]
@@ -148,17 +148,20 @@ def convert_model(model_name, output_path, opset=13, tag=None, verbose=True):
148
148
if large_model :
149
149
cmdl .append ('--large_model' )
150
150
if verbose :
151
- print ("cmd: python %s" % " " .join (cmdl ))
151
+ print ("cmd: %s" % " " .join (cmdl ))
152
+
152
153
pproc = subprocess .Popen (
153
- cmdl , shell = True , stdin = None , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
154
- executable = sys .executable .replace ("pythonw" , "python" ))
155
- stdoutdata , stderrdata = pproc .communicate ()
156
- if verbose :
157
- print ('--OUT--' )
158
- print (stdoutdata .decode ('ascii' ))
159
- print ('--ERR--' )
160
- print (stderrdata .decode ('ascii' ))
161
- print ("Duration %r." % (datetime .datetime .now () - begin ))
154
+ [c .strip ('"' ) for c in cmdl ], shell = False ,
155
+ stdin = None , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
156
+ executable = None )
157
+ with pproc :
158
+ stdoutdata , stderrdata = pproc .communicate ()
159
+ if verbose :
160
+ print ('--OUT--' )
161
+ print (stdoutdata .decode ('ascii' ))
162
+ print ('--ERR--' )
163
+ print (stderrdata .decode ('ascii' ))
164
+ print ("Duration %r." % (datetime .datetime .now () - begin ))
162
165
163
166
164
167
def convert_tflite (model_name , output_path , opset = 13 , verbose = True ):
0 commit comments