Merge pull request #32 from RamesTheGeneric/main

Removed torch dependency, new model, and exposed deadzone setting.
This commit is contained in:
Summer authored and GitHub committed 2024-01-04 22:07:55 -08:00
commit 38f6c61246
17 files changed
+90 -13696

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ jobs:
- name: Package Application
uses: JackMcKew/pyinstaller-action-windows@main
with:
path: Babble.CPU
path: BabbleApp
- uses: actions/upload-artifact@v2
with:
-1
View File
@@ -15,7 +15,6 @@ BabbleApp/dist
/scripts
/share
scripts/example_build_app_and_installer.bat
scripts/example_build_app_and_installer.bat
scripts/installer.iss
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
+15 -2
View File
@@ -19,6 +19,7 @@ class AlgoSettingsWidget:
self.gui_inference_threads = f"-THREADS{widget_id}-"
self.gui_runtime = f"-RUNTIME{widget_id}"
self.gui_gpu_index = f"GPUINDEX{widget_id}"
self.calib_deadzone = f"CALIBDEADZONE{widget_id}"
self.main_config = main_config
self.config = main_config.settings
self.osc_queue = osc_queue
@@ -80,6 +81,14 @@ class AlgoSettingsWidget:
tooltip = "Model output modifier.",
),
],
[sg.Text("Calibration Deadzone:", background_color='#424042'),
sg.InputText(
self.config.calib_deadzone,
key=self.calib_deadzone,
size=(4),
tooltip = "Offset the minimum calibrated values.",
),
],
[
sg.Text("One Euro Filter Paramaters:", background_color='#242224'),
],
@@ -138,13 +147,17 @@ class AlgoSettingsWidget:
# If anything has changed in our configuration settings, change/update those.
changed = False
if self.config.gui_multiply != int(values[self.gui_multiply]):
self.config.gui_multiply = int(values[self.gui_multiply])
if self.config.gui_multiply != float(values[self.gui_multiply]):
self.config.gui_multiply = float(values[self.gui_multiply])
changed = True
if self.config.gui_model_file != values[self.gui_model_file]:
self.config.gui_model_file = values[self.gui_model_file]
changed = True
if self.config.calib_deadzone != float(values[self.calib_deadzone]):
self.config.calib_deadzone = float(values[self.calib_deadzone])
changed = True
if self.config.gui_use_gpu != values[self.gui_use_gpu]:
self.config.gui_use_gpu = values[self.gui_use_gpu]
+4 -6
View File
@@ -7,20 +7,18 @@ import PySimpleGUI as sg
import cv2
import numpy as np
from pythonosc import udp_client
from torchvision.transforms.functional import to_grayscale
import utils.image_transforms as transforms
import PIL.Image as Image
from torchvision import transforms
from threading import Thread
from one_euro_filter import OneEuroFilter
def run_model(self):
if self.runtime == "ONNX" or self.runtime == "Default (ONNX)":
frame = cv2.resize(self.current_image_gray, (256, 256))
frame = transforms.ToTensor()(frame).unsqueeze(0).numpy()
frame = transforms.to_tensor(frame)
frame = transforms.unsqueeze(frame,0)
out = self.sess.run([self.output_name], {self.input_name: frame})
#end = time.time()
output = out[0]
output = output[0]
output = out[0][0]
output = self.one_euro_filter(output)
+1 -3
View File
@@ -46,7 +46,7 @@ SETTINGS_RADIO_NAME = "-SETTINGSRADIO-"
ALGO_SETTINGS_RADIO_NAME = "-ALGOSETTINGSRADIO-"
page_url = "https://github.com/SummerSigh/ProjectBabble/releases/latest"
appversion = "Babble v2.0.4"
appversion = "Babble v2.0.5"
def main():
@@ -243,8 +243,6 @@ def main():
for setting in settings:
if setting.started():
setting.render(window, event, values)
# settings[0].render(window, event, values)
# settings[1].render(window, event, values)
if __name__ == "__main__":
+2 -2
View File
@@ -1,4 +1,4 @@
# -*- mode: py -3.10 ; coding: utf-8 -*-
# -*- mode: py -3.11 ; coding: utf-8 -*-
block_cipher = None
@@ -6,7 +6,7 @@ block_cipher = None
a = Analysis(['babbleapp.py'],
pathex=[],
binaries=[],
datas=[("Audio/*", "Audio"), ("Images/*", "Images/"), ("Models/*", "Models/")],
datas=[("Audio/*", "Audio"), ("Images/*", "Images/"), ("Models/*/*/*", "Models/")],
hiddenimports=[],
hookspath=[],
hooksconfig={},
+3 -2
View File
@@ -31,13 +31,14 @@ class BabbleSettingsConfig(BaseModel):
gui_update_check: bool = True
gui_ROSC: bool = False
gui_osc_location: str = ""
gui_multiply: int = 1
gui_model_file: str = 'Models/EFFB0MVE99TIMM/'
gui_multiply: float = 1
gui_model_file: str = 'Models/3MEFFB0E7MSE/'
gui_runtime: str = "ONNX"
gui_use_gpu: bool = False
gui_gpu_index: int = 0
gui_inference_threads: int = 2
gui_use_red_channel: bool = False
calib_deadzone: float = -0.1
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]]"
gui_cam_resolution_x: int = 0
gui_cam_resolution_y: int = 0
+1 -1
View File
@@ -45,7 +45,7 @@ class cal():
if self.config.use_n_calibration:
self.calibration_frame_counter = None
values = np.array(self.val_list)
deadzone_value = -0.01 # Maybe adjust from app????
deadzone_value = self.settings.calib_deadzone
# Initialize the min_max_array with shape (2, num_outputs)
num_outputs = values.shape[1]
self.min_max_array = np.zeros((2, num_outputs))
+60
View File
@@ -0,0 +1,60 @@
import numpy as np
def normalize(numpy_array):
"""
Normalize the values of a numpy array to a specified range.
Args:
- numpy_array (numpy.ndarray): Input numpy array.
Returns:
- numpy.ndarray: Normalized numpy array.
"""
normalized_array = numpy_array / 255
return normalized_array
def to_tensor(numpy_array, dtype=np.float32):
"""
Convert a numpy array to a PyTorch tensor.
Args:
- numpy_array (numpy.ndarray): Input numpy array.
- dtype (numpy.dtype): Data type of the resulting PyTorch tensor.
Returns:
- torch.Tensor: Converted PyTorch tensor.
"""
if not isinstance(numpy_array, np.ndarray):
raise ValueError("Input must be a numpy array")
# Ensure the input array has the correct data type
numpy_array = numpy_array.astype(dtype)
# Add a batch dimension if the input array is 2D
if len(numpy_array.shape) == 2:
numpy_array = numpy_array[:, :, np.newaxis]
# Transpose the array to match PyTorch tensor format (C x H x W)
tensor = normalize(np.transpose(numpy_array, (2, 0, 1)))
return tensor
def unsqueeze(numpy_array, axis: int):
"""
Add a dimension of size 1 to a numpy array at the specified position.
Args:
- numpy_array (numpy.ndarray): Input numpy array.
- axis (int): Position along which to add the new dimension.
Returns:
- numpy.ndarray: Numpy array with an additional dimension.
"""
if not isinstance(numpy_array, np.ndarray):
raise ValueError("Input must be a numpy array")
result_array = np.expand_dims(numpy_array, axis=axis)
return result_array
-8
View File
@@ -22,14 +22,6 @@ onnxruntime-directml = "^1.15.0"
colorama = "^0.4.6"
taskipy = "^1.10.4"
torch = [
{url = "https://download.pytorch.org/whl/cpu/torch-2.0.0%2Bcpu-cp311-cp311-linux_x86_64.whl", markers = "sys_platform == 'linux'"},
{url = "https://download.pytorch.org/whl/cpu/torch-2.0.0%2Bcpu-cp311-cp311-win_amd64.whl", markers = "sys_platform == 'win32'" }
]
torchvision = [
{url = "https://download.pytorch.org/whl/cpu/torchvision-0.15.1%2Bcpu-cp311-cp311-linux_x86_64.whl", markers = "sys_platform == 'linux'"},
{url = "https://download.pytorch.org/whl/cpu/torchvision-0.15.1%2Bcpu-cp311-cp311-win_amd64.whl", markers = "sys_platform == 'win32'" }
]
[tool.poetry.group.dev.dependencies]
+1 -1
View File
@@ -4,7 +4,7 @@ cd X:\Documents\GitHub\ProjectBabble\BabbleApp
pyinstaller babbleapp.spec --noconfirm
cd X:\Documents\GitHub\ProjectBabble\BabbleApp
cd 'C:\Program Files (x86)\Inno Setup 6'
./ISCC X:\Documents\GitHub\ProjectBabble\scripts\installer.iss
.\ISCC X:\Documents\GitHub\ProjectBabble\scripts\installer.iss
::cls
@echo off
color 0A
+2 -2
View File
@@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Project Babble"
#define MyAppVersion "2.0.4"
#define MyAppVersion "2.0.5"
#define MyAppPublisher "Project Babble Team"
#define MyAppURL "https://github.com/SummerSigh/ProjectBabble/tree/main"
#define MyAppExeName "Babble_App.exe"
@@ -20,7 +20,7 @@ AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
OutputDir=C:\Users\epicm\OneDrive\Desktop\build
OutputDir=C:\Users\epicm\Desktop\build
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputBaseFilename=Project_Babble-Setup
-14
View File
@@ -1,14 +0,0 @@
import onnxruntime as ort
from openvino.inference_engine import IECore
import openvino.inference_engine as ovie
'''
print(ort.get_device()) # Returns the current device
print(ort.get_all_providers())
print(ort.get_available_providers())
#sess = ort.InferenceSession(f'{self.model}onnx/model.onnx', self.opts, providers=['DmlExecutionProvider'])
'''
ie = IECore()
ovie.list_devices
#print(ie.get_devices())
#net = ie.read_network(model=f'{self.model}openvino/model.xml', weights=f'{self.model}openvino/model.bin')
#self.sess = ie.load_network(network=net, device_name='CPU')