resize image to optimize performance
Browse files
app.py
CHANGED
@@ -5,7 +5,21 @@ from insightface.app import FaceAnalysis
|
|
5 |
from hsemotion_onnx.facial_emotions import HSEmotionRecognizer
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def facial_emotion_recognition(img):
|
|
|
|
|
9 |
|
10 |
faces = face_detector.get(img)
|
11 |
|
@@ -35,10 +49,12 @@ def facial_emotion_recognition(img):
|
|
35 |
return img
|
36 |
|
37 |
face_margin = 0.1
|
|
|
38 |
model_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'buffalo_sc')
|
39 |
face_detector = FaceAnalysis(name=model_name, allowed_modules=['detection'], providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
40 |
face_detector.prepare(ctx_id=0, det_size=(640, 640))
|
41 |
|
|
|
42 |
hse_emo_model = HSEmotionRecognizer(model_name='enet_b0_8_best_vgaf')
|
43 |
|
44 |
webcam = gr.Image(image_mode='RGB', type='numpy', source='webcam', label='Input Image')
|
|
|
5 |
from hsemotion_onnx.facial_emotions import HSEmotionRecognizer
|
6 |
|
7 |
|
8 |
+
def resize(image, target_size):
|
9 |
+
# Get the dimensions of the input image
|
10 |
+
height, width = image.shape[0], image.shape[1]
|
11 |
+
|
12 |
+
# Calculate the scaling factor needed to resize the image to the target size
|
13 |
+
scaling_factor = min(target_size[0] / width, target_size[1] / height)
|
14 |
+
# Resize the image using cv2.resize
|
15 |
+
resized_image = cv2.resize(image, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_LINEAR)
|
16 |
+
|
17 |
+
return resized_image
|
18 |
+
|
19 |
+
|
20 |
def facial_emotion_recognition(img):
|
21 |
+
|
22 |
+
img = resize(img, target_size)
|
23 |
|
24 |
faces = face_detector.get(img)
|
25 |
|
|
|
49 |
return img
|
50 |
|
51 |
face_margin = 0.1
|
52 |
+
target_size = (640, 640)
|
53 |
model_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'buffalo_sc')
|
54 |
face_detector = FaceAnalysis(name=model_name, allowed_modules=['detection'], providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
55 |
face_detector.prepare(ctx_id=0, det_size=(640, 640))
|
56 |
|
57 |
+
|
58 |
hse_emo_model = HSEmotionRecognizer(model_name='enet_b0_8_best_vgaf')
|
59 |
|
60 |
webcam = gr.Image(image_mode='RGB', type='numpy', source='webcam', label='Input Image')
|