Skip to content

Commit dd6b355

Browse files
committed
fix perf
1 parent dcae638 commit dd6b355

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

BabbleApp/babble_model_loader.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616
def run_model(self):
1717

1818

19-
opts = ort.SessionOptions()
20-
opts.intra_op_num_threads = 1
21-
opts.inter_op_num_threads = 1
22-
opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_EXTENDED
23-
if not self.use_gpu:
24-
sess = ort.InferenceSession(self.model, opts, providers=['CPUExecutionProvider'])
25-
else:
26-
sess = ort.InferenceSession(self.model, opts, providers=['DmlExecutionProvider'])
27-
input_name = sess.get_inputs()[0].name
28-
output_name = sess.get_outputs()[0].name
2919

3020
min_cutoff = 15.5004
3121
beta = 0.62
@@ -48,7 +38,7 @@ def run_model(self):
4838
# make it a numpy array
4939
frame = frame.numpy()
5040

51-
out = sess.run([output_name], {input_name: frame})
41+
out = self.sess.run([self.output_name], {self.input_name: frame})
5242
#end = time.time()
5343
output = out[0]
5444
output = output[0]

BabbleApp/babble_processor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ def __init__(
113113
self.use_gpu = self.settings.gui_use_gpu
114114
self.output = []
115115
self.calibrate_config = np.empty((1, 45))
116+
117+
self.opts = ort.SessionOptions()
118+
self.opts.intra_op_num_threads = 1
119+
self.opts.inter_op_num_threads = 1
120+
self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_EXTENDED
121+
if not self.use_gpu:
122+
self.sess = ort.InferenceSession(self.model, self.opts, providers=['CPUExecutionProvider'])
123+
else:
124+
self.sess = ort.InferenceSession(self.model, self.opts, providers=['DmlExecutionProvider'])
125+
self.input_name = self.sess.get_inputs()[0].name
126+
self.output_name = self.sess.get_outputs()[0].name
116127

117128

118129
try:

0 commit comments

Comments
 (0)