should work
Browse files- handler.py +10 -11
handler.py
CHANGED
@@ -15,15 +15,14 @@ class EndpointHandler():
|
|
15 |
|
16 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
17 |
imageData = data.pop("image", data)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# aligned = aligned.to(self.device)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
15 |
|
16 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
17 |
imageData = data.pop("image", data)
|
18 |
+
image = Image.open(BytesIO(base64.b64decode(imageData)))
|
19 |
+
face_batch = self.mtcnn([image])
|
20 |
+
face_batch = [i for i in face_batch if i is not None]
|
21 |
+
if face_batch:
|
22 |
+
aligned = torch.stack(face_batch)
|
23 |
+
if self.device.type == "cuda":
|
24 |
+
aligned = aligned.to(self.device)
|
|
|
25 |
|
26 |
+
embeddings = self.resnet(aligned).detach().cpu()
|
27 |
+
return embeddings.tolist()
|
28 |
+
else: return None
|