-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Skip face-swapping for images without detectable faces (#504) #508
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,9 @@ def half_det_size(det_size): | |
def analyze_faces(img_data: np.ndarray, det_size=(640, 640)): | ||
face_analyser = getAnalysisModel(det_size) | ||
faces = face_analyser.get(img_data) | ||
|
||
if len(faces) == 0: | ||
logger.status("No face found so skipping this frame") | ||
return faces | ||
# Try halving det_size if no faces are found | ||
if len(faces) == 0 and det_size[0] > 320 and det_size[1] > 320: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code will no longer be executed because for the condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated @Wiikend92 |
||
det_size_half = half_det_size(det_size) | ||
|
@@ -188,7 +190,9 @@ def analyze_faces(img_data: np.ndarray, det_size=(640, 640)): | |
return faces | ||
|
||
def get_face_single(img_data: np.ndarray, face, face_index=0, det_size=(640, 640), gender_source=0, gender_target=0, order="large-small"): | ||
|
||
# if no face found no need to swap | ||
if len(face) == 0: | ||
return None, 0 | ||
buffalo_path = os.path.join(insightface_models_path, "buffalo_l.zip") | ||
if os.path.exists(buffalo_path): | ||
os.remove(buffalo_path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem persists because the code inside this
if
will still run before the code inside theelif
. They have to switch places so that the code trying to half det size and re-analyze is run first. Sorry if my previous comment was unclear on this.