From 45a7b25a0a82af0c53f598a2d1a36c0540b4924b Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Sat, 24 Jun 2023 14:15:46 -0500 Subject: [PATCH] remove torch for smaller binary. kill bug for mommy --- EyeTrackApp/config.py | 2 +- EyeTrackApp/mommy.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/EyeTrackApp/config.py b/EyeTrackApp/config.py index 02c5857..960be46 100644 --- a/EyeTrackApp/config.py +++ b/EyeTrackApp/config.py @@ -121,4 +121,4 @@ class EyeTrackConfig(BaseModel): pass with open(CONFIG_FILE_NAME, "w") as settings_file: json.dump(obj=self.dict(), fp=settings_file) - print("[INFO] Config Saved Successfully") + print(f"\033[92m[INFO] Config Saved Successfully\033[0m") diff --git a/EyeTrackApp/mommy.py b/EyeTrackApp/mommy.py index 9db5e45..9a4bb54 100644 --- a/EyeTrackApp/mommy.py +++ b/EyeTrackApp/mommy.py @@ -30,8 +30,6 @@ import os os.environ["OMP_NUM_THREADS"] = "1" import onnxruntime import numpy as np -from PIL import Image -import torchvision.transforms as transforms import cv2 import time import math @@ -52,10 +50,20 @@ def run_model(input_queue, output_queue, session): if frame is None: break - to_tensor = transforms.ToTensor() - img_tensor = to_tensor(frame) - img_tensor.unsqueeze_(0) - img_np = img_tensor.numpy() + # to_tensor = transforms.ToTensor() + # img_tensor = to_tensor(frame) + # img_tensor.unsqueeze_(0) + # img_np = img_tensor.numpy() + img_np = np.array(frame) + + # Normalize the pixel values to [0, 1] and convert the data type to float32 + img_np = img_np.astype(np.float32) / 255.0 + + # Transpose the dimensions from (height, width, channels) to (channels, height, width) + img_np = np.transpose(img_np, (2, 0, 1)) + + # Add a batch dimension + img_np = np.expand_dims(img_np, axis=0) ort_inputs = {session.get_inputs()[0].name: img_np} pre_landmark = session.run(None, ort_inputs) @@ -180,7 +188,7 @@ class MOMMY_C(object): x = pre_landmark[17][0] y = pre_landmark[17][1] frame = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) - return frame, x, y, per + return frame, float(x), float(y), per frame = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)