hasnanmr commited on
Commit
7894302
·
1 Parent(s): 2d3c662

fixing image input

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -66,12 +66,15 @@ def compare_embeddings(embedding, database, threshold=0.9):
66
  return None, None
67
 
68
  def align_faces(frame, mtcnn, device):
 
 
 
69
  boxes, _ = mtcnn.detect(frame)
70
  aligned_faces = []
71
  if boxes is not None:
72
  aligned_faces = mtcnn(frame)
73
  if aligned_faces is not None:
74
- aligned_faces = aligned_faces.to(device)
75
  return aligned_faces, boxes
76
 
77
  def draw_annotations(frame, detections, names=None):
@@ -122,7 +125,7 @@ iface = gr.Interface(
122
  inputs=gr.Image(type="pil"),
123
  outputs=gr.Image(type="numpy"),
124
  title="Face Detection and Recognition with MTCNN and ViT",
125
- description="Upload an image and the model will detect and align faces in it."
126
  )
127
 
128
  # Launch the interface
 
66
  return None, None
67
 
68
  def align_faces(frame, mtcnn, device):
69
+ # Convert the frame to a PIL image if it's a numpy array
70
+ if isinstance(frame, np.ndarray):
71
+ frame = Image.fromarray(frame)
72
  boxes, _ = mtcnn.detect(frame)
73
  aligned_faces = []
74
  if boxes is not None:
75
  aligned_faces = mtcnn(frame)
76
  if aligned_faces is not None:
77
+ aligned_faces = [aligned_face.to(device) for aligned_face in aligned_faces]
78
  return aligned_faces, boxes
79
 
80
  def draw_annotations(frame, detections, names=None):
 
125
  inputs=gr.Image(type="pil"),
126
  outputs=gr.Image(type="numpy"),
127
  title="Face Detection and Recognition with MTCNN and ViT",
128
+ description="Upload an image and the model will detect and recognize faces in it."
129
  )
130
 
131
  # Launch the interface