Update app.py
Browse files
app.py
CHANGED
@@ -117,7 +117,6 @@
|
|
117 |
|
118 |
|
119 |
|
120 |
-
|
121 |
import gradio as gr
|
122 |
import cv2
|
123 |
import torch
|
@@ -132,22 +131,13 @@ mp_face_mesh = mp.solutions.face_mesh
|
|
132 |
face_detection = mp_face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
|
133 |
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.5)
|
134 |
|
135 |
-
#
|
136 |
-
|
137 |
-
model
|
138 |
-
|
139 |
-
|
140 |
-
checkpoint = torch.load("resnet34.pth", map_location="cpu")
|
141 |
-
|
142 |
-
# Extract just the model weights (ignore optimizer states)
|
143 |
-
if "network" in checkpoint: # Handle different checkpoint formats
|
144 |
-
model.load_state_dict(checkpoint["network"])
|
145 |
-
elif "state_dict" in checkpoint:
|
146 |
-
model.load_state_dict(checkpoint["state_dict"])
|
147 |
-
else:
|
148 |
-
# Directly try loading if it's pure state_dict
|
149 |
-
model.load_state_dict(checkpoint)
|
150 |
|
|
|
151 |
model.eval()
|
152 |
|
153 |
# Define transformation for face images
|
@@ -212,7 +202,6 @@ def process_video(video_path: str):
|
|
212 |
output_video.release()
|
213 |
return output_path
|
214 |
|
215 |
-
# Rest of the Gradio interface remains the same
|
216 |
def gradio_interface(video_file):
|
217 |
if video_file is None:
|
218 |
return "Error: No video uploaded."
|
|
|
117 |
|
118 |
|
119 |
|
|
|
120 |
import gradio as gr
|
121 |
import cv2
|
122 |
import torch
|
|
|
131 |
face_detection = mp_face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
|
132 |
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.5)
|
133 |
|
134 |
+
# Initialize ResNet-34 model with random weights
|
135 |
+
def create_model():
|
136 |
+
model = models.resnet34(pretrained=False)
|
137 |
+
model.fc = torch.nn.Linear(model.fc.in_features, 2)
|
138 |
+
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
model = create_model()
|
141 |
model.eval()
|
142 |
|
143 |
# Define transformation for face images
|
|
|
202 |
output_video.release()
|
203 |
return output_path
|
204 |
|
|
|
205 |
def gradio_interface(video_file):
|
206 |
if video_file is None:
|
207 |
return "Error: No video uploaded."
|