8
8
import sys
9
9
import time
10
10
import tarfile
11
- import zipfile
12
11
import subprocess
13
12
import datetime
14
13
import numpy
15
14
from tqdm import tqdm
16
15
import tensorflow_hub as hub
17
16
import onnxruntime as ort
18
- from tf2onnx import utils , convert
17
+ from tf2onnx import utils
19
18
20
19
21
20
def generate_random_images (shape = (100 , 100 ), n = 10 ):
@@ -80,14 +79,14 @@ def convert_model(model_name, output_path, opset=13, verbose=True):
80
79
"""
81
80
if not os .path .exists (output_path ):
82
81
begin = datetime .datetime .now ()
83
- cmd = [sys .executable .replace ("pythonw" , "python" ),
84
- '-m' , 'tf2onnx.convert' , '--saved-model' ,
85
- '"%s"' % model_name .replace ("\\ " , "/" ),
86
- '--output' , '"%s"' % output_path .replace ("\\ " , "/" ),
87
- '--opset' , "%d" % opset ]
82
+ cmdl = ['-m' , 'tf2onnx.convert' , '--saved-model' ,
83
+ '"%s"' % model_name .replace ("\\ " , "/" ),
84
+ '--output' , '"%s"' % output_path .replace ("\\ " , "/" ),
85
+ '--opset' , "%d" % opset ]
88
86
if verbose :
89
- print ("cmd: %s" % " " .join (cmd ))
90
- pproc = subprocess .Popen (cmdl , shell = True , stdin = None , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
87
+ print ("cmd: python %s" % " " .join (cmdl ))
88
+ pproc = subprocess .Popen (cmdl , shell = True , stdin = None , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
89
+ executable = sys .executable .replace ("pythonw" , "python" ))
91
90
stdoutdata , stderrdata = pproc .communicate ()
92
91
if verbose :
93
92
print ('--OUT--' )
@@ -99,7 +98,7 @@ def convert_model(model_name, output_path, opset=13, verbose=True):
99
98
100
99
# Downloads the model
101
100
url = "https://tfhub.dev/captain-pool/esrgan-tf2/1?tf-hub-format=compressed"
102
- dest = "tf-esrgan-tf2"
101
+ dest = os . path . abspath ( "tf-esrgan-tf2" )
103
102
name = "esrgan-tf2"
104
103
opset = 13
105
104
onnx_name = os .path .join (dest , "esrgan-tf2-%d.onnx" % opset )
@@ -126,4 +125,6 @@ def convert_model(model_name, output_path, opset=13, verbose=True):
126
125
results_tf , duration_tf = measure_time (model , imgs )
127
126
print ("TF" , len (imgs ), duration_tf )
128
127
129
- print ("ratio ORT / TF" , sum (duration_ort ) / sum (duration_tf ))
128
+ mean_ort = sum (duration_ort ) / len (duration_ort )
129
+ mean_tf = sum (duration_tf ) / len (duration_tf )
130
+ print ("ratio ORT=%r / TF=%r = %r" % (mean_ort , mean_tf , mean_ort / mean_tf ))
0 commit comments