Skip to content

Commit dc81880

Browse files
authored
Merge pull request #27 from RamesTheGeneric/main
Final Build Tweaks
2 parents 082e1ca + bddf4f7 commit dc81880

16 files changed

+118
-1241
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ BabbleApp/dist
1111
.vscode
1212
/testing
1313
/old_models
14+
/Lib
15+
/scripts
16+
/share
17+
18+
1419
scripts/example_build_app_and_installer.bat
1520
scripts/example_build_app_and_installer.bat
1621
scripts/installer.iss
1722
Glia_cap.py
23+
lazyass_minecraft_script.py
24+
scripts/example_build_app_and_installer.bat
22.6 MB
Binary file not shown.

BabbleApp/algo_settings_widget.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def __init__(self, widget_id: Tab, main_config: BabbleSettingsConfig, osc_queue:
1717
self.gui_speed_coefficient = f"-SPEEDCOEFFICIENT{widget_id}-"
1818
self.gui_min_cutoff = f"-MINCUTOFF{widget_id}-"
1919
self.gui_inference_threads = f"-THREADS{widget_id}-"
20-
self.gui_backend = f"-BACKEND{widget_id}"
20+
self.gui_runtime = f"-RUNTIME{widget_id}"
2121
self.gui_gpu_index = f"GPUINDEX{widget_id}"
2222
self.main_config = main_config
2323
self.config = main_config.settings
2424
self.osc_queue = osc_queue
25-
self.backend_list = "OpenVino", "ONNX"
25+
self.runtime_list = ("Default (ONNX)", "ONNX")
2626

2727
# Define the window's contents
2828
self.general_settings_layout = [
@@ -42,15 +42,15 @@ def __init__(self, widget_id: Tab, main_config: BabbleSettingsConfig, osc_queue:
4242
tooltip = "How many threads to use for processing the model.",
4343
),
4444
],
45-
[sg.Text("Backend:", background_color='#424042'), # Replace with Dropdown once I have internet to view docs.
45+
[sg.Text("Runtime:", background_color='#424042'), # Replace with Dropdown once I have internet to view docs.
4646
sg.OptionMenu(
47-
self.backend_list,
48-
self.config.gui_backend,
49-
key=self.gui_backend,
47+
self.runtime_list,
48+
self.config.gui_runtime,
49+
key=self.gui_runtime,
5050
),
5151
#sg.InputText(
52-
# self.config.gui_backend,
53-
# key=self.gui_backend,
52+
# self.config.gui_runtime,
53+
# key=self.gui_runtime,
5454
# size=(4),
5555
# tooltip = "Method to run the model.",
5656

@@ -149,26 +149,27 @@ def render(self, window, event, values):
149149
if self.config.gui_use_gpu != values[self.gui_use_gpu]:
150150
self.config.gui_use_gpu = values[self.gui_use_gpu]
151151
changed = True
152+
if values[self.gui_gpu_index] != '':
153+
if self.config.gui_gpu_index != int(values[self.gui_gpu_index]):
154+
self.config.gui_gpu_index = int(values[self.gui_gpu_index])
155+
changed = True
152156

153-
if self.config.gui_gpu_index != int(values[self.gui_gpu_index]):
154-
self.config.gui_gpu_index = int(values[self.gui_gpu_index])
155-
changed = True
156-
157-
if self.config.gui_backend != str(values[self.gui_backend]):
158-
self.config.gui_backend = str(values[self.gui_backend])
157+
if self.config.gui_runtime != str(values[self.gui_runtime]):
158+
self.config.gui_runtime = str(values[self.gui_runtime])
159159
changed = True
160160

161-
if self.config.gui_inference_threads != int(values[self.gui_inference_threads]):
162-
self.config.gui_inference_threads = int(values[self.gui_inference_threads])
163-
changed = True
164-
165-
if self.config.gui_min_cutoff != values[self.gui_min_cutoff]:
166-
self.config.gui_min_cutoff = values[self.gui_min_cutoff]
167-
changed = True
168-
169-
if self.config.gui_speed_coefficient != values[self.gui_speed_coefficient]:
170-
self.config.gui_speed_coefficient = values[self.gui_speed_coefficient]
171-
changed = True
161+
if values[self.gui_inference_threads] != '':
162+
if self.config.gui_inference_threads != int(values[self.gui_inference_threads]):
163+
self.config.gui_inference_threads = int(values[self.gui_inference_threads])
164+
changed = True
165+
if values[self.gui_min_cutoff] != '':
166+
if self.config.gui_min_cutoff != values[self.gui_min_cutoff]:
167+
self.config.gui_min_cutoff = values[self.gui_min_cutoff]
168+
changed = True
169+
if values[self.gui_speed_coefficient] != '':
170+
if self.config.gui_speed_coefficient != values[self.gui_speed_coefficient]:
171+
self.config.gui_speed_coefficient = values[self.gui_speed_coefficient]
172+
changed = True
172173

173174
if changed:
174175
self.main_config.save()

BabbleApp/babble_model_loader.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import json
33
os.environ["OMP_NUM_THREADS"] = "1"
4-
from openvino.inference_engine import IECore
54
import onnxruntime as ort
65
import time
76
import PySimpleGUI as sg
@@ -16,29 +15,7 @@
1615

1716

1817
def run_model(self):
19-
if self.backend == "OpenVino":
20-
frame = cv2.resize(self.current_image_gray, (256, 256))
21-
# make it pil
22-
frame = Image.fromarray(frame)
23-
# make it grayscale
24-
frame = to_grayscale(frame)
25-
# make it a tensor
26-
frame = transforms.ToTensor()(frame)
27-
# make it a batch
28-
frame = frame.unsqueeze(0)
29-
# make it a numpy array
30-
frame = frame.numpy()
31-
out = self.sess.infer(inputs={self.input_name: frame})
32-
#out = self.sess.run([self.output_name], {self.input_name: frame})
33-
#end = time.time()
34-
output = out[self.output_name]
35-
output = output[0]
36-
output = self.one_euro_filter(output)
37-
for i in range(len(output)): # Clip values between 0 - 1
38-
output[i] = max(min(output[i], 1), 0)
39-
self.output = output
40-
41-
if self.backend == "ONNX":
18+
if self.runtime == "ONNX" or self.runtime == "Default (ONNX)":
4219
frame = cv2.resize(self.current_image_gray, (256, 256))
4320
# make it pil
4421
frame = Image.fromarray(frame)

BabbleApp/babble_processor.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878

7979
self.current_algo = CamInfoOrigin.MODEL
8080
self.model = self.settings.gui_model_file
81-
self.backend = self.settings.gui_backend
81+
self.runtime = self.settings.gui_runtime
8282
self.use_gpu = self.settings.gui_use_gpu
8383
self.gpu_index = self.settings.gui_gpu_index
8484
self.output = []
@@ -88,24 +88,13 @@ def __init__(
8888

8989
self.opts = ort.SessionOptions()
9090
self.opts.intra_op_num_threads = settings.gui_inference_threads
91-
self.opts.inter_op_num_threads = settings.gui_inference_threads # Figure out how to set openvino threads
9291
self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
93-
if self.backend == "OpenVino": # OpenVino
94-
if self.use_gpu: provider = f'GPU.{self.gpu_index}'
95-
else: provider = 'CPU'
96-
ie = IECore()
97-
net = ie.read_network(model=f'{self.model}openvino/model.xml', weights=f'{self.model}openvino/model.bin')
98-
self.sess = ie.load_network(network=net, device_name=provider)
99-
self.input_name = next(iter(net.input_info))
100-
self.output_name = next(iter(net.outputs))
101-
if self.backend == "ONNX": # ONNX
102-
if self.use_gpu: provider = 'DmlExecutionProvider' # Figure out how to set ONNX gpu index
103-
else: provider = "CPUExecutionProvider"
104-
self.sess = ort.InferenceSession(f'{self.model}onnx/model.onnx', self.opts, providers=[provider])
92+
if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": # ONNX
93+
if self.use_gpu: provider = 'DmlExecutionProvider'
94+
else: provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO
95+
self.sess = ort.InferenceSession(f'{self.model}onnx/model.onnx', self.opts, providers=[provider], provider_options=[{'device_id': self.gpu_index}])
10596
self.input_name = self.sess.get_inputs()[0].name
10697
self.output_name = self.sess.get_outputs()[0].name
107-
108-
10998
try:
11099
min_cutoff = float(self.settings.gui_min_cutoff) # 15.5004
111100
beta = float(self.settings.gui_speed_coefficient) # 0.62

BabbleApp/babbleapp.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,12 @@ def main():
161161
],
162162
]
163163

164-
165164
if config.cam_display_id in [Tab.CAM]:
166165
cams[0].start()
167166
if config.cam_display_id in [Tab.SETTINGS]:
168167
settings[0].start()
169168
if config.cam_display_id in [Tab.ALGOSETTINGS]:
170169
settings[1].start()
171-
'''
172-
if config.cam_display_id in [Tab.CALIBSETTINGS]:
173-
settings[2].start()
174-
'''
175170

176171
# the cam needs to be running before it is passed to the OSC
177172
if config.settings.gui_ROSC:

BabbleApp/babbleapp.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ a = Analysis(['babbleapp.py'],
77
pathex=[],
88
binaries=[],
99
datas=[("Audio/*", "Audio"), ("Images/*", "Images/"), ("Models/*", "Models/")],
10-
hiddenimports=['cv2', 'numpy', 'PySimpleGui', 'onnxruntime-directml'],
10+
hiddenimports=[],
1111
hookspath=[],
1212
hooksconfig={},
1313
runtime_hooks=[],

BabbleApp/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class BabbleSettingsConfig(BaseModel):
3232
gui_ROSC: bool = False
3333
gui_osc_location: str = ""
3434
gui_multiply: int = 1
35-
gui_model_file: str = 'Models/ENEXTXXE100D4/'
36-
gui_backend: str = "OpenVino"
35+
gui_model_file: str = 'Models/EFFB0MVE99TIMM/'
36+
gui_runtime: str = "ONNX"
3737
gui_use_gpu: bool = False
3838
gui_gpu_index: int = 0
39-
gui_inference_threads: int = 1
39+
gui_inference_threads: int = 2
4040
gui_use_red_channel: bool = False
4141
calib_array: str = "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]"
4242
gui_cam_resolution_x: int = 0

BabbleApp/general_settings_widget.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,18 @@ def render(self, window, event, values):
224224
if self.config.gui_osc_location != values[self.gui_osc_location]:
225225
self.config.gui_osc_location = values[self.gui_osc_location]
226226
changed = True
227-
228-
if self.config.gui_cam_resolution_x != int(values[self.gui_cam_resolution_x]):
229-
self.config.gui_cam_resolution_x = int(values[self.gui_cam_resolution_x])
230-
changed = True
231-
232-
if self.config.gui_cam_resolution_y != int(values[self.gui_cam_resolution_y]):
233-
self.config.gui_cam_resolution_y = int(values[self.gui_cam_resolution_y])
234-
changed = True
235-
236-
if self.config.gui_cam_framerate != int(values[self.gui_cam_framerate]):
237-
self.config.gui_cam_framerate = int(values[self.gui_cam_framerate])
238-
changed = True
227+
if values[self.gui_cam_resolution_x] != '':
228+
if self.config.gui_cam_resolution_x != int(values[self.gui_cam_resolution_x]):
229+
self.config.gui_cam_resolution_x = int(values[self.gui_cam_resolution_x])
230+
changed = True
231+
if values[self.gui_cam_resolution_y] != '':
232+
if self.config.gui_cam_resolution_y != int(values[self.gui_cam_resolution_y]):
233+
self.config.gui_cam_resolution_y = int(values[self.gui_cam_resolution_y])
234+
changed = True
235+
if values[self.gui_cam_framerate] != '':
236+
if self.config.gui_cam_framerate != int(values[self.gui_cam_framerate]):
237+
self.config.gui_cam_framerate = int(values[self.gui_cam_framerate])
238+
changed = True
239239

240240
if self.config.gui_use_red_channel != bool(values[self.gui_use_red_channel]):
241241
self.config.gui_use_red_channel = bool(values[self.gui_use_red_channel])

BabbleApp/osc_calibrate_filter.py

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from math import log
23
from enum import IntEnum
34
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
45

@@ -7,43 +8,65 @@ class CamId(IntEnum):
78
SETTINGS = 1
89

910
class cal():
11+
1012
def cal_osc(self, array):
1113
#print(self.calibration_frame_counter)
1214
if self.calibration_frame_counter == 0:
15+
if not self.config.use_n_calibration:
16+
self.calibration_frame_counter = None
17+
values = np.array(self.val_list)
1318

14-
self.calibration_frame_counter = None
15-
values = np.array(self.val_list)
19+
# Initialize the min_max_array with shape (2, num_outputs)
20+
num_outputs = values.shape[1]
21+
self.min_max_array = np.zeros((2, num_outputs))
1622

17-
# Initialize the min_max_array with shape (2, num_outputs)
18-
num_outputs = values.shape[1]
19-
self.min_max_array = np.zeros((2, num_outputs))
23+
# Iterate over each output index
24+
for i in range(num_outputs):
25+
# Calculate the lower and upper thresholds for the current index
26+
lower_threshold = np.percentile(values[:, i], 1)
27+
upper_threshold = np.percentile(values[:, i], 99)
2028

21-
# Iterate over each output index
22-
for i in range(num_outputs):
23-
# Calculate the lower and upper thresholds for the current index
24-
lower_threshold = np.percentile(values[:, i], 1)
25-
upper_threshold = np.percentile(values[:, i], 99)
29+
# Filter out values within the thresholds for the current index
30+
filtered_values = values[(values[:, i] >= lower_threshold) & (values[:, i] <= upper_threshold), i]
2631

27-
# Filter out values within the thresholds for the current index
28-
filtered_values = values[(values[:, i] >= lower_threshold) & (values[:, i] <= upper_threshold), i]
32+
# Extract the minimum and maximum values for the current index
33+
min_value = np.min(filtered_values)
34+
max_value = np.max(filtered_values)
35+
36+
# Store the min and max values in the min_max_array
37+
self.min_max_array[0, i] = min_value
38+
self.min_max_array[1, i] = max_value
39+
self.settings.calib_array = np.array2string(self.min_max_array, separator=',')
40+
self.config_class.save()
41+
print("[INFO] Calibration completed.")
42+
43+
PlaySound('Audio/completed.wav', SND_FILENAME | SND_ASYNC)
44+
45+
if self.config.use_n_calibration:
46+
self.calibration_frame_counter = None
47+
values = np.array(self.val_list)
48+
deadzone_value = -0.01 # Maybe adjust from app????
49+
# Initialize the min_max_array with shape (2, num_outputs)
50+
num_outputs = values.shape[1]
51+
self.min_max_array = np.zeros((2, num_outputs))
52+
lower_threshold = np.clip([np.mean(values, axis = 0) + deadzone_value], 0, 1)
53+
upper_threshold = np.ones((1, num_outputs)) # We don't need to adjust the max values.
54+
print(lower_threshold)
55+
print(upper_threshold)
56+
self.min_max_array = np.array([lower_threshold, upper_threshold])
57+
self.settings.calib_array = np.array2string(self.min_max_array, separator=',')
58+
self.config_class.save()
59+
print("[INFO] Calibration completed.")
2960

30-
# Extract the minimum and maximum values for the current index
31-
min_value = np.min(filtered_values)
32-
max_value = np.max(filtered_values)
3361

34-
# Store the min and max values in the min_max_array
35-
self.min_max_array[0, i] = min_value
36-
self.min_max_array[1, i] = max_value
37-
self.settings.calib_array = np.array2string(self.min_max_array, separator=',')
38-
self.config_class.save()
39-
print("[INFO] Calibration completed.")
4062

41-
PlaySound('Audio/completed.wav', SND_FILENAME | SND_ASYNC)
4263

43-
elif self.calibration_frame_counter != None:
4464

65+
66+
elif self.calibration_frame_counter != None:
4567
self.val_list.append(array)
4668
self.calibration_frame_counter -= 1
69+
4770

4871
if self.settings.calib_array is not None and self.config.use_calibration:
4972
self.min_max_array = np.fromstring(self.settings.calib_array.replace('[', '').replace(']', ''), sep=',')
@@ -70,10 +93,9 @@ def cal_osc(self, array):
7093
for i, value in enumerate(array):
7194
min_value = self.min_max_array[0, i]
7295

73-
7496
calibrated_value = (value - min_value) / (1.0 - min_value)
7597

7698
calibrated_array[i] = calibrated_value
7799
array = calibrated_array
78-
79-
return array
100+
#array[4] = log((np.clip(array[4]*10,0,10))+1.0, 11) Log Filter: Move to filter system.
101+
return np.clip(array,0,1) # Clamp outputs between 0-1

0 commit comments

Comments
 (0)