NVIDIA / flownet2-pytorch

Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks
Other
3.09k stars 739 forks source link

ModuleNotFoundError: No module named 'resample2d_cuda' #215

Closed GeorgeAdamon closed 4 years ago

GeorgeAdamon commented 4 years ago
Platform version
Windows 10
CUDA 10.2
Python 3.7
pytorch 0.4.1

I'm trying to run main.py right after running install.sh, and I get the following 2 errors:

C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch>python main.py --help
Traceback (most recent call last):
  File "C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch\models.py", line 9, in <module>
    from networks.resample2d_package.resample2d import Resample2d
  File "C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch\networks\resample2d_package\resample2d.py", line 3, in <module>
    import resample2d_cuda
ModuleNotFoundError: No module named 'resample2d_cuda'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 16, in <module>
    import models, losses, datasets
  File "C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch\models.py", line 19, in <module>
    from .networks.resample2d_package.resample2d import Resample2d
ImportError: attempted relative import with no known parent package

The second one is an easy fix, I just removed the relative imports from Resample2d.

But I have no idea how to fix the first one. Apparently resample2d_cuda.py never gets generated when I run install.sh.

Any ideas would be much appreciated.

zsameem commented 4 years ago

It seems that the Resample2d package is not installed. Try installing it separately and see if you get any errors in the process. For this you can run

python setup.py install

in the networks/resample2d_package.

GeorgeAdamon commented 4 years ago

Thanks for the suggestion @zsameem . Running this gives me the following path-related error:

C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch\networks\resample2d_package>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    from torch.utils.cpp_extension import BuildExtension, CUDAExtension
  File "C:\Python37\lib\site-packages\torch\utils\cpp_extension.py", line 61, in <module>
    CUDA_HOME = _find_cuda_home()
  File "C:\Python37\lib\site-packages\torch\utils\cpp_extension.py", line 30, in _find_cuda_home
    if not os.path.exists(cuda_home):
  File "C:\Python37\lib\genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not list
zsameem commented 4 years ago

My guess is that you don't have the proper setup to compile the CUDA code. I was able to get this running on windows once. You will need the CUDA Toolkit, MS Visual Studio C++ and also the CUDA plugin for Visual Studio. Make sure you have all these things installed and then try running the setup.py again as mentioned in my previous comment.

GeorgeAdamon commented 4 years ago

That's really strange, since I'm actually writing & compiling custom C++ CUDA plugins just fine, and I haven't had problems compiling NVIDIA libraries like Optix.

nvcc -V

C:\Users\GeorgeAdamon\Documents\GitHub\flownet2-pytorch\networks\resample2d_package>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:32:27_Pacific_Daylight_Time_2019
Cuda compilation tools, release 10.2, V10.2.89

image

zsameem commented 4 years ago

From your second post, it seems that the build tool of torch is having trouble finding/setting the CUDA_HOME path. I noticed that your torch version is very old. Did you also try with a newer version of torch. If I remember correctly, it simply worked with torch 1.2/1.3 for me.

GeorgeAdamon commented 4 years ago

Thank you @zsameem !

Upgrading to latest pytorch via
pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html fixed the issue!

I also had to go to networks/correlation_package and networks/channelnorm_package and "manually" run python setup.py install.

Finally I need to report that using the latest version of scipy (1.4.0) resulted in scipy.misc.imread errors, because imread is deprecated. I had to go back to scipy 1.1.0 for everything to work.

So for future reference, I confirm that the following combination works: Tool Version
Windows 10
Visual Studio 2017
CUDA 10.2
python 3.7
pytorch 1.5.0
scipy 1.1.0
numpy 1.17.2