Commit ·
871e118
1
Parent(s): f761a37
face recognition
Browse files- app/Hackathon_setup/face_recognition.py +6 -6
- app/main.py +4 -2
app/Hackathon_setup/face_recognition.py
CHANGED
|
@@ -120,15 +120,15 @@ def get_face_class(img1):
|
|
| 120 |
ckpt = torch.load(ckpt_path, map_location=device)
|
| 121 |
myModel.load_state_dict(ckpt['net_dict'])
|
| 122 |
myModel.eval()
|
| 123 |
-
myModel = myModel.float()
|
| 124 |
# 3 Face detection (if available)
|
| 125 |
-
det_img1 = detected_face(img1) # returns cropped face or 0 if not detected
|
| 126 |
-
if det_img1 == 0:
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
# 4 Transform the face
|
| 131 |
-
img_tensor =
|
| 132 |
|
| 133 |
# 5 Extract embeddings
|
| 134 |
with torch.no_grad():
|
|
|
|
| 120 |
ckpt = torch.load(ckpt_path, map_location=device)
|
| 121 |
myModel.load_state_dict(ckpt['net_dict'])
|
| 122 |
myModel.eval()
|
| 123 |
+
# myModel = myModel.float()
|
| 124 |
# 3 Face detection (if available)
|
| 125 |
+
# det_img1 = detected_face(img1) # returns cropped face or 0 if not detected
|
| 126 |
+
# if det_img1 == 0:
|
| 127 |
+
# # fallback: use original image
|
| 128 |
+
# det_img1 = Image.fromarray(cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY))
|
| 129 |
|
| 130 |
# 4 Transform the face
|
| 131 |
+
img_tensor = transform1(img1).unsqueeze(0).to(device)
|
| 132 |
|
| 133 |
# 5 Extract embeddings
|
| 134 |
with torch.no_grad():
|
app/main.py
CHANGED
|
@@ -91,10 +91,12 @@ async def create_upload_files(request: Request, file3: UploadFile = File(...)):
|
|
| 91 |
face_rec_filename = 'app/static/' + file3.filename
|
| 92 |
with open(face_rec_filename, 'wb') as f:
|
| 93 |
f.write(contents)
|
|
|
|
| 94 |
print(face_rec_filename)
|
| 95 |
img1 = Image.open(face_rec_filename)
|
| 96 |
-
img1 = np.array(img1).reshape(img1.size[1], img1.size[0], 3).astype(np.uint8)
|
| 97 |
-
|
|
|
|
| 98 |
result = face_recognition.get_face_class(img1)
|
| 99 |
print(result)
|
| 100 |
|
|
|
|
| 91 |
face_rec_filename = 'app/static/' + file3.filename
|
| 92 |
with open(face_rec_filename, 'wb') as f:
|
| 93 |
f.write(contents)
|
| 94 |
+
|
| 95 |
print(face_rec_filename)
|
| 96 |
img1 = Image.open(face_rec_filename)
|
| 97 |
+
# img1 = np.array(img1).reshape(img1.size[1], img1.size[0], 3).astype(np.uint8)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
result = face_recognition.get_face_class(img1)
|
| 101 |
print(result)
|
| 102 |
|