Update app.py
Browse files
app.py
CHANGED
@@ -131,9 +131,18 @@ mp_face_mesh = mp.solutions.face_mesh
|
|
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 |
-
|
135 |
-
model =
|
136 |
-
model.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
model.eval()
|
138 |
|
139 |
# Define transformation for face images
|
|
|
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 |
+
def create_model():
|
135 |
+
model = models.resnet34(pretrained=False) # Must match the architecture used during training
|
136 |
+
model.fc = torch.nn.Linear(model.fc.in_features, 2) # Adjust final layer
|
137 |
+
return model
|
138 |
+
|
139 |
+
# Load the trained model
|
140 |
+
model = create_model()
|
141 |
+
try:
|
142 |
+
model.load_state_dict(torch.load("resnet34.pkl", map_location='cpu'))
|
143 |
+
except RuntimeError as e:
|
144 |
+
print(f"Error loading model: {e}")
|
145 |
+
# Handle architecture mismatch (e.g., load weights manually)
|
146 |
model.eval()
|
147 |
|
148 |
# Define transformation for face images
|