1
0
Fork 0
mirror of https://github.com/deepfakes/faceswap synced 2025-06-08 11:53:26 -04:00
faceswap/lib/faces_detect.py
babilio 83c36b9489 Improving performance of extraction. Two main changes to improve the … (#259)
* Improving performance of extraction. Two main changes to improve the most recent modifications to extract: 1st FaceLandmarkExtractor would try to use cnn first, then try hog. The problem was that this reduced the speed by 4 for images where cnn didn't find anything, and most of the times hog wouldn't find anything either or it would be a bad extract. For me it wasn't worth it. With this you can specify on input -D if you want to use hog, cnn, or all. 'all' will try cnn, then hog like FaceLandmarkExtractor was doing. cnn or hog will just use 1 detection method. 2nd change is a rehaul of the verbose parameter. Now warnings when a face is not detected will just be shown if indicated by -v or --verbose. This restores the verbose function to what it once was. With this change I was able to process 1,000 per each 4 minutes regardless if faces were detected or not. Performance improvement just applies to not detected images but I normally will have lots of images without clear faces in my set, so I figured it would impact others. Also the introduction of 'all' would allow trying other models together more easily in the future.

* Update faces_detect.py

* Update extract.py

* Update FaceLandmarksExtractor.py

* spacing fix
2018-03-11 11:36:50 +01:00

20 lines
740 B
Python

from lib import FaceLandmarksExtractor
def detect_faces(frame, detector, verbose, rotation=0):
fd = FaceLandmarksExtractor.extract (frame, detector, verbose)
for face in fd:
x, y, right, bottom, landmarks = face[0][0], face[0][1], face[0][2], face[0][3], face[1]
yield DetectedFace(frame[y: bottom, x: right], rotation, x, right - x, y, bottom - y, landmarksXY=landmarks)
class DetectedFace(object):
def __init__(self, image=None, r=0, x=None, w=None, y=None, h=None, landmarksXY=None):
self.image = image
self.r = r
self.x = x
self.w = w
self.y = y
self.h = h
self.landmarksXY = landmarksXY
def landmarksAsXY(self):
return self.landmarksXY