Skip to content
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 issue with blazeface when img is square #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dcetin
Copy link

@dcetin dcetin commented Oct 14, 2021

I think it's error-prone to center-crop and resize when we only need to do a resize. It somehow messes with the dimensions due to numbers rounding off and rescaled img is of size 128 to 127 instead of a square, which fails the assertion downstream. This could be a issue bigger than the example I presented here though, might need to add a few more test to it to make sure whether it only occurs on square images or the non-square images might also need a fix for rounding-off errors.

Script I ran:

import face_alignment
from skimage import io
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, face_detector='blazeface', device='cpu')
input = io.imread('test.jpeg')
preds = fa.get_landmarks(input)

Example image I used: https://images.pexels.com/photos/3042160/pexels-photo-3042160.jpeg

Error I got:

Traceback (most recent call last):
  File "fa_test.py", line 5, in <module>
    preds = fa.get_landmarks(input)
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/api.py", line 110, in get_landmarks
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
    return func(*args, **kwargs)
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/api.py", line 141, in get_landmarks_from_image
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/detection/blazeface/blazeface_detector.py", line 42, in detect_from_image
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/detection/blazeface/detect.py", line 14, in detect
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/detection/blazeface/net_blazeface.py", line 193, in predict_on_image
  File "/home/doruk/anaconda3/envs/fa/lib/python3.7/site-packages/face_alignment-1.3.4-py3.7.egg/face_alignment/detection/blazeface/net_blazeface.py", line 217, in predict_on_batch
AssertionError

@jonasricker
Copy link

Stumbled across this issue today and the fix worked as intended, thanks @dcetin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants