Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import cv2
|
|
6 |
import torch
|
7 |
import facer
|
8 |
from typing import Tuple
|
|
|
9 |
|
10 |
def process_image(input_image: np.ndarray) -> np.ndarray:
|
11 |
"""
|
@@ -21,9 +22,11 @@ def process_image(input_image: np.ndarray) -> np.ndarray:
|
|
21 |
|
22 |
# Convert numpy array to PIL Image and back to ensure correct format
|
23 |
input_pil = Image.fromarray(input_image)
|
|
|
|
|
24 |
|
25 |
# Convert image to format expected by facer
|
26 |
-
|
27 |
|
28 |
# Initialize face detector
|
29 |
face_detector = facer.face_detector('retinaface/mobilenet', device=device)
|
|
|
6 |
import torch
|
7 |
import facer
|
8 |
from typing import Tuple
|
9 |
+
import torchvision.transforms as transforms
|
10 |
|
11 |
def process_image(input_image: np.ndarray) -> np.ndarray:
|
12 |
"""
|
|
|
22 |
|
23 |
# Convert numpy array to PIL Image and back to ensure correct format
|
24 |
input_pil = Image.fromarray(input_image)
|
25 |
+
|
26 |
+
transform = transforms.Compose([transforms.PILToTensor()])
|
27 |
|
28 |
# Convert image to format expected by facer
|
29 |
+
image = facer.hwc2bchw(transform(input_pil)).to(device=device)
|
30 |
|
31 |
# Initialize face detector
|
32 |
face_detector = facer.face_detector('retinaface/mobilenet', device=device)
|