Closed ojrandom1 closed 2 years ago
could you share the aligned version here?
Try this:
img = DeepFace.detectFace("tests/dataset/img31.jpg")
cv2.imwrite("base_image.jpg", img*255)
Yes,
detector_name = 'mtcnn' detector = FaceDetector.build_model('mtcnn')
img = DeepFace.detectFace("tests/dataset/img31.jpg") cv2.imwrite("base_image.jpg", img*255)
works as expected and produces an aligned image, see
What is the recommended solution to have have aligned faces for the face representations for example using an approach like this.
detector_name = 'mtcnn'
detector = FaceDetector.build_model('mtcnn')
model = DeepFace.build_model('ArcFace')
img = cv2.imread(path)
try:
faces = FaceDetector.detect_faces(detector, detector_name, img, align=True)
except:
print("error")
for face, (x, y, w, h) in faces:
if w < 100
continue
region = [x, y, w, h]
custom_face = img[y:y+h, x:x+w]
input_shape = functions.find_input_shape(model)
input_shape_x = input_shape[0]
input_shape_y = input_shape[1]
custom_face = functions.preprocess_face(
img=custom_face,
target_size=(input_shape_y, input_shape_x),
enforce_detection=False,
detector_backend=detector_name,
align = True)
representation = []
if custom_face.shape[1:3] == input_shape:
representation = self.model.predict(custom_face)[0, :]
else:
continue
Is this a bug or a wrong usage of deepface?
The aligned image (img_aligned) does not show up as aligned in