bit-guber commited on
Commit
3453c44
1 Parent(s): 892aed2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -3,6 +3,7 @@ from transformers import ViTImageProcessor, ViTForImageClassification, AutoModel
3
  import torch
4
  import numpy as np
5
  import face_recognition
 
6
 
7
  torch.backends.cudnn.benchmark = True
8
 
@@ -157,7 +158,10 @@ def image_inference(image):
157
  # Draw rectangle around the faces
158
  # rawfaces = postProcessed( rawfaces, image.shape[:2] )
159
 
160
- rawfaces = face_recognition.face_locations( image, number_of_times_to_upsample = 1 , model="hog")
 
 
 
161
  faces = [ image[top:bottom, left:right].copy() for (top, left, bottom, right) in rawfaces ]
162
  faces_mean = [ x.mean() for x in faces ]
163
  # faces = [ image[x:w+x, y:h+y].copy() for (x, y, w, h) in rawfaces ]
@@ -192,7 +196,11 @@ def video_inference(video_path):
192
  except:
193
  break
194
  # rawfaces = postProcessed( rawfaces, image.shape[:2] )
195
- rawfaces = face_recognition.face_locations( image, number_of_times_to_upsample = 1 , model="hog")
 
 
 
 
196
  # Draw rectangle around the faces
197
  # https://stackoverflow.com/questions/15589517/how-to-crop-an-image-in-opencv-using-python for fliping axis
198
  global_facesCo.append( rawfaces )
 
3
  import torch
4
  import numpy as np
5
  import face_recognition
6
+ from retinaface import RetinaFace
7
 
8
  torch.backends.cudnn.benchmark = True
9
 
 
158
  # Draw rectangle around the faces
159
  # rawfaces = postProcessed( rawfaces, image.shape[:2] )
160
 
161
+ # rawfaces = face_recognition.face_locations( image, number_of_times_to_upsample = 1 , model="hog")
162
+ rawfaces = []
163
+ for name, keys in RetinaFace.detect_faces( image ).items():
164
+ rawfaces.append( keys['facial_area'] )
165
  faces = [ image[top:bottom, left:right].copy() for (top, left, bottom, right) in rawfaces ]
166
  faces_mean = [ x.mean() for x in faces ]
167
  # faces = [ image[x:w+x, y:h+y].copy() for (x, y, w, h) in rawfaces ]
 
196
  except:
197
  break
198
  # rawfaces = postProcessed( rawfaces, image.shape[:2] )
199
+ rawfaces = []
200
+ for name, keys in RetinaFace.detect_faces( image ).items():
201
+ rawfaces.append( keys['facial_area'] )
202
+
203
+ # rawfaces = face_recognition.face_locations( image, number_of_times_to_upsample = 1 , model="hog")
204
  # Draw rectangle around the faces
205
  # https://stackoverflow.com/questions/15589517/how-to-crop-an-image-in-opencv-using-python for fliping axis
206
  global_facesCo.append( rawfaces )