1adrianb / face-alignment

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

ImportError: cannot import name 'download_url_to_file' #256

Closed mshb9999 closed 3 years ago

mshb9999 commented 3 years ago

Hi, I didn't find this particular issue and it's getting to my head. For similar issues, I tried to do different things, including: completely uninstall numpy (triple checked that I don't have two diff versions installed), and installed numpy with version 1.15.0 and also tried with the latest I also tried to install face-alignment in different ways (pip and conda) and installed it using requirements.txt. I tried an older version of pytorch (1.0.0) and the newest version, same with torchvision.
I ensured I have ffmpeg and imageio-ffmpeg.

I use --inp --cpu (I don't have cuda)

I get this error: ImportError: cannot import name 'download_url_to_file'

Nothing worked and with some of the other versions, I would get these: ValueError: At least one stride in the given numpy array is negative ImportError: numpy.core.multiarray failed to import AttributeError: module 'numpy' has no attribute 'byte'

Any help would be appreciated.

1adrianb commented 3 years ago

You should try a newer version of pytorch, not older. As per the documentation, download_url_to_file is part of the torch.hub package: https://pytorch.org/docs/stable/hub.html?highlight=download_url_to_file#torch.hub.download_url_to_file

The numpy error also suggests an issue with your numpy installation. Please also make sure you are using python3, python2 is not supported.

The only error that could potentially be related to this package is "ValueError: At least one stride in the given numpy array is negative". If you address the other issues, please try to run the tests or the examples/detect_landmarks_in_image.py (adjusting it to run on cpu) and let me know if you still encounter an issue.

mshb9999 commented 3 years ago

Thanks Adrian and kudos for your work. Here is what I tried (please note that I didn't use python2) I have another environment running python 3.8.5 and pytorch 1.7.1 and got the: ValueError: At least one stride ...

As you suggested, I went to the examples folder and used this command: python demo.ipynb --inp 04.mp4 --cpu and got this error: TypeError: init() got an unexpected keyword argument 'face_detector_kwargs'

I also went back to my python 3.6, uninstalled pytorch and twice torch and re-installed a new version of pytorch (1.7.1) and torchvision (0.2.1) and got this: ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

Any ideas?

1adrianb commented 3 years ago

Thanks for testing this, there still seams to be an issue with you environment in 3.6 unrelated to this package, this could probably provide some hints on fixing this.

Regarding the rest, it seams that I forgot to merge a pull request, sorry for this. In your python 3.8 env could you please try to install the lib from source instead of pip/conda and see if this addresses your issue?

mshb9999 commented 3 years ago

Good news. But first the bad I proceeded to install the latest python 3.9, then latest pytorch and torchvision, then face-alignment and got a similar error: ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy().)

Then I saw your message and went back to 3.8.5 and it's working now :)

Thanks for looking into this Adrian.