1adrianb / face-alignment

:fire: 2D and 3D Face alignment library build using pytorch
https://www.adrianbulat.com
BSD 3-Clause "New" or "Revised" License
7.12k stars 1.35k forks source link

errors on python 3.6.5, face-alignment 1.3.4, cuda 10.2, torch 1.6.0 #273

Closed 0fine0 closed 3 years ago

0fine0 commented 3 years ago

Hi, when I try to run the demo of 2D facial landmarks detection,

my code:


import face_alignment from skimage import io

fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=False)

input = io.imread('C:/Users/csjddu/Desktop/images/1.jpg') preds = fa.get_landmarks(input)


I met the error as below: TypingError Traceback (most recent call last)

in () 5 6 input = io.imread('C:/Users/csjddu/Desktop/images/1.jpg') ----> 7 preds = fa.get_landmarks(input) D:\anaconda\lib\site-packages\face_alignment\api.py in get_landmarks(self, image_or_path, detected_faces, return_bboxes) 107 This function predicts a set of 68 2D or 3D images, one for each image present. 108 If detect_faces is None the method will also run a face detector. --> 109 110 Arguments: 111 image_or_path {string or numpy.array or torch.tensor} -- The input image or path to it. D:\anaconda\lib\site-packages\torch\autograd\grad_mode.py in decorate_context(*args, **kwargs) 13 def decorate_context(*args, **kwargs): 14 with self: ---> 15 return func(*args, **kwargs) 16 return decorate_context 17 D:\anaconda\lib\site-packages\face_alignment\api.py in get_landmarks_from_image(self, image_or_path, detected_faces, return_bboxes) 152 if pts[i, 0] > 0 and pts[i, 1] > 0: 153 heatmaps[i] = draw_gaussian( --> 154 heatmaps[i], pts[i], 2) 155 heatmaps = torch.from_numpy( 156 heatmaps).unsqueeze_(0) D:\anaconda\lib\site-packages\face_alignment\utils.py in get_preds_fromhm(hm, center, scale) 197 B, C, H, W = hm.shape 198 idx = np.argmax(hm.reshape(B, C, H * W), axis=2) --> 199 preds, preds_orig = _get_preds_fromhm(hm, idx, center, scale) 200 201 return preds, preds_orig D:\anaconda\lib\site-packages\numba\dispatcher.py in _compile_for_args(self, *args, **kws) 342 raise e 343 else: --> 344 reraise(type(e), e, None) 345 except errors.UnsupportedError as e: 346 # Something unsupported is present in the user code, add help info D:\anaconda\lib\site-packages\numba\six.py in reraise(tp, value, tb) 656 value = tp() 657 if value.__traceback__ is not tb: --> 658 raise value.with_traceback(tb) 659 raise value 660 TypingError: Failed at nopython (nopython frontend) Unknown attribute 'repeat' of type array(int64, 2d, C) File "D:\anaconda\lib\site-packages\face_alignment\utils.py", line 220: def _get_preds_fromhm(hm, idx, center=None, scale=None): idx += 1 preds = idx.repeat(2).reshape(B, C, 2).astype(np.float32) ^ [1] During: typing of get attribute at D:\anaconda\lib\site-packages\face_alignment\utils.py (220) File "D:\anaconda\lib\site-packages\face_alignment\utils.py", line 220: def _get_preds_fromhm(hm, idx, center=None, scale=None): idx += 1 preds = idx.repeat(2).reshape(B, C, 2).astype(np.float32) ^ This is not usually a problem with Numba itself but instead often caused by the use of unsupported features or an issue in resolving types. To see Python/NumPy features supported by the latest release of Numba visit: http://numba.pydata.org/numba-doc/dev/reference/pysupported.html and http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html For more information about typing errors and how to debug them visit: http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile If you think your code should work with Numba, please report the error message and traceback, along with a minimal reproducer at: https://github.com/numba/numba/issues/new
1adrianb commented 3 years ago

Does this happen for any image or just for that particular one? Could you run the examples/detect_landmarks_in_image.py using the provided assets or simply run please the test/ using pytest?

You can also try upgrading you numpy and numba version. Alternatively, as a dirty fix you can clone the repo and comment out all instance of "@jit(nopython=True)" that you found in the code, installing afterwards from source.

0fine0 commented 3 years ago

I have solved this problem. The error seems to be induced by a old version numba package. And although I tried to update my numpy, numba and torch packages, the jupyter notebook didn't update the environment until the restart.

For face-alignment 1.3.4, I think numba 0.51.2, numpy 1.19.5, torch 1.8.1 can work.

Thank you for your help!