longcw/RoIAlign.pytorch

ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'

kgavrilyuk opened this issue · 30 comments

I am using anaconda 3. When I run

python setup.py install

it works fine without any errors:

running install
running bdist_egg
running egg_info
creating roi_align.egg-info
writing roi_align.egg-info/PKG-INFO
writing dependency_links to roi_align.egg-info/dependency_links.txt
writing requirements to roi_align.egg-info/requires.txt
writing top-level names to roi_align.egg-info/top_level.txt
writing manifest file 'roi_align.egg-info/SOURCES.txt'
reading manifest file 'roi_align.egg-info/SOURCES.txt'
writing manifest file 'roi_align.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/roi_align
copying roi_align/crop_and_resize.py -> build/lib.linux-x86_64-3.7/roi_align
copying roi_align/__init__.py -> build/lib.linux-x86_64-3.7/roi_align
copying roi_align/roi_align.py -> build/lib.linux-x86_64-3.7/roi_align
running build_ext
building 'roi_align.crop_and_resize_cpu' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/roi_align
creating build/temp.linux-x86_64-3.7/roi_align/src
gcc -pthread -B /home/kirill/workspace/software/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/crop_and_resize.cpp -o build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_cpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
roi_align/src/crop_and_resize.cpp:31:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
     #pragma omp parallel for
 
g++ -pthread -shared -B /home/kirill/workspace/software/anaconda3/compiler_compat -L/home/kirill/workspace/software/anaconda3/lib -Wl,-rpath=/home/kirill/workspace/software/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize.o -o build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so
building 'roi_align.crop_and_resize_gpu' extension
creating build/temp.linux-x86_64-3.7/roi_align/src/cuda
gcc -pthread -B /home/kirill/workspace/software/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/crop_and_resize_gpu.cpp -o build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize_gpu.o -g -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_gpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/usr/local/cuda/bin/nvcc -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/cuda/crop_and_resize_kernel.cu -o build/temp.linux-x86_64-3.7/roi_align/src/cuda/crop_and_resize_kernel.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' -O2 -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_gpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
g++ -pthread -shared -B /home/kirill/workspace/software/anaconda3/compiler_compat -L/home/kirill/workspace/software/anaconda3/lib -Wl,-rpath=/home/kirill/workspace/software/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize_gpu.o build/temp.linux-x86_64-3.7/roi_align/src/cuda/crop_and_resize_kernel.o -L/usr/local/cuda/lib64 -lcudart -o build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/__init__.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/roi_align.py -> build/bdist.linux-x86_64/egg/roi_align
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize.py to crop_and_resize.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/__init__.py to __init__.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/roi_align.py to roi_align.cpython-37.pyc
creating stub loader for roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so
creating stub loader for roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize_cpu.py to crop_and_resize_cpu.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize_gpu.py to crop_and_resize_gpu.cpython-37.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
roi_align.__pycache__.crop_and_resize_cpu.cpython-37: module references __file__
roi_align.__pycache__.crop_and_resize_gpu.cpython-37: module references __file__
creating dist
creating 'dist/roi_align-0.0.1-py3.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing roi_align-0.0.1-py3.7-linux-x86_64.egg
removing '/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg' (and everything under it)
creating /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg
Extracting roi_align-0.0.1-py3.7-linux-x86_64.egg to /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
roi-align 0.0.1 is already the active version in easy-install.pth

Installed /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg
Processing dependencies for roi-align==0.0.1
Searching for torch==1.1.0
Best match: torch 1.1.0
Adding torch 1.1.0 to easy-install.pth file
Installing convert-caffe2-to-onnx script to /home/kirill/workspace/software/anaconda3/bin
Installing convert-onnx-to-caffe2 script to /home/kirill/workspace/software/anaconda3/bin

Using /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
Searching for numpy==1.16.2
Best match: numpy 1.16.2
Adding numpy 1.16.2 to easy-install.pth file
Installing f2py script to /home/kirill/workspace/software/anaconda3/bin
Installing f2py3 script to /home/kirill/workspace/software/anaconda3/bin
Installing f2py3.7 script to /home/kirill/workspace/software/anaconda3/bin

Using /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
Finished processing dependencies for roi-align==0.0.1

However, when I run

./test.sh

it outputs the following:

Unexpected error: <class 'ModuleNotFoundError'>
Traceback (most recent call last):
  File "tests/test.py", line 13, in <module>
    from roi_align.crop_and_resize import CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'
Traceback (most recent call last):
  File "tests/test2.py", line 5, in <module>
    from roi_align.roi_align import RoIAlign
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'
Traceback (most recent call last):
  File "tests/crop_and_resize_example.py", line 5, in <module>
    from roi_align.crop_and_resize import CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'

What could be the reason of the problem? How to fix it?

I am having a very simal issue thou mine cant find roi_align._ext.crop_and_resize._crop_and_resize
error below

**ModuleNotFoundError: No module named 'roi_align._ext.crop_and_resize._crop_and_resize'
**

I solved this.
For me, this was an issue of (due to loading my CUDA via a package) the CUDA_PATH in the install.sh file.
In my case, I need to change it to "/usr/lib/nvidia-cuda-toolkit"
but here is a link for finding when your system has placed your CUDA_PATH
https://stackoverflow.com/questions/36279045/where-did-cuda-get-installed-in-my-computer
Hope this helps

@PHDPeter
Hello Peter, I am wondering where is the install.sh file. I can only find setup.py file and there is no CUDA_PATH variable.

Hi @mangoSteve
Yes, I should have said I was working on the pytorch_0.4 branch.
Looking over the up to date branch I could not find any CUDA_PATH variable.
This might be something you will need to set before running?
Here is the code from the install.sh file that deals with the CUDA_PATH.

CUDA_PATH=/usr/local/cuda

echo "Compiling crop_and_resize kernels by nvcc..."
cd roi_align/src/cuda
$CUDA_PATH/bin/nvcc -c -o crop_and_resize_kernel.cu.o crop_and_resize_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_30
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_62,code=sm_62 \

same problem

I am still not sure what is the reason of the problem. I tried to set CUDA_PATH as suggested @PHDPeter. It didn't help for pytorch 1.x for CUDA 9.2 (tried buiding pytorch from source as well). However, on the other machine with pytorch 1.1 and CUDA 10.0 everything works.

I am still not sure what is the reason of the problem. I tried to set CUDA_PATH as suggested @PHDPeter. It didn't help for pytorch 1.x for CUDA 9.2 (tried buiding pytorch from source as well). However, on the other machine with pytorch 1.1 and CUDA 10.0 everything works.

No module named 'roi_align._ext.crop_and_resize._crop_and_resize' i mat the same problem, can you help how to fix it?

Same error here... I am trying to use this verison instead..

Rename the folder "roi_align" (in your
decompressed directory) to other name solves the problem.

I solved this.
For me, this was an issue of (due to loading my CUDA via a package) the CUDA_PATH in the install.sh file.
In my case, I need to change it to "/usr/lib/nvidia-cuda-toolkit"
but here is a link for finding when your system has placed your CUDA_PATH
https://stackoverflow.com/questions/36279045/where-did-cuda-get-installed-in-my-computer
Hope this helps

if I don't have CUDA, can I solve this ?

Thanks to @Hub-Tian , just like he(she) said, the name of roi_align folder is conflict with the same named roi_align package built in '..\Lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg' , so rename the folder name in the project and related import script works.

Thanks to @Hub-Tian , just like he(she) said, the name of roi_align folder is conflict with the same named roi_align package built in '..\Lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg' , so rename the folder name in the project and related import script works.

Did you change all the name of "roi_align"? or just the floder

Thanks to @Hub-Tian , just like he(she) said, the name of roi_align folder is conflict with the same named roi_align package built in '..\Lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg' , so rename the folder name in the project and related import script works.

Did you change all the name of "roi_align"? or just the floder
I have just changed the name of roi_align folder and roi_align.py in the folder.

Thanks to @Hub-Tian , just like he(she) said, the name of roi_align folder is conflict with the same named roi_align package built in '..\Lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg' , so rename the folder name in the project and related import script works.

Did you change all the name of "roi_align"? or just the floder
I have just changed the name of roi_align folder and roi_align.py in the folder.

Thank you for your advice, I have solved my problem.

For anybody who was getting ModuleNotFound Errors after building roi_align.
Restart the python kernel if you're running from a notebook and make sure you don't have a folder named roi_align in your current working directory..!!

Rename the folder "roi_align" (in your
decompressed directory) to other name solves the problem.

brilliant, this solves the issue. Thank you

For anybody who was getting ModuleNotFound Errors after building roi_align.
Restart the python kernel if you're running from a notebook and make sure you don't have a folder named roi_align in your current working directory..!!

I rename my "roi_align" folder to "roi_align_src", and change the referenced import scripts. But after I rerun the setup instrunction, the ModuleNotFound Errors also occurs.Could you please do me a favor?

For anybody who was getting ModuleNotFound Errors after building roi_align.
Restart the python kernel if you're running from a notebook and make sure you don't have a folder named roi_align in your current working directory..!!

I rename my "roi_align" folder to "roi_align_src", and change the referenced import scripts. But after I rerun the setup instrunction, the ModuleNotFound Errors also occurs.Could you please do me a favor?

after installing try running test.sh from another directory or try the demo code in the readme.
If it still persists there might have been a problem with the install itself.
i.e you should be able to import roi_align from a python repl from any directory.

I solved this.
For me, this was an issue of (due to loading my CUDA via a package) the CUDA_PATH in the install.sh file.
In my case, I need to change it to "/usr/lib/nvidia-cuda-toolkit"
but here is a link for finding when your system has placed your CUDA_PATH
https://stackoverflow.com/questions/36279045/where-did-cuda-get-installed-in-my-computer
Hope this helps

if I don't have CUDA, can I solve this ?

yes you can :)

can you send the modified directory here.for me still it shows the same error even if i do correct installation

can you send the modified directory here.for me still it shows the same error even if i do correct installation

I have tried two methods mentioned above but didn't work. So I complied with JIT and it worked.

from torch.utils.cpp_extension import load
#import roi_align_1.crop_and_resize_cpu as crop_and_resize_cpu
crop_and_resize_cpu = load(name="crop_and_resize",
extra_include_paths=["src"],
sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize.cpp"],
verbose=True)
if torch.cuda.is_available():
#import roi_align_1.crop_and_resize_gpu as crop_and_resize_gpu
crop_and_resize_gpu = load(name="crop_and_resize_gpu",
extra_include_paths=["src"],
sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize_gpu.cpp", "/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/cuda/crop_and_resize_kernel.cu"],
verbose=True)
you may just use the code above in crop_and_resize.py. If you use JIT, you don't have to run "install.py".
The "roi_align_1" thing is because I tried the rename method(which didn't work).

can you send the modified directory here.for me still it shows the same error even if i do correct installation

I have tried two methods mentioned above but didn't work. So I complied with JIT and it worked.

from torch.utils.cpp_extension import load
#import roi_align_1.crop_and_resize_cpu as crop_and_resize_cpu
crop_and_resize_cpu = load(name="crop_and_resize",
extra_include_paths=["src"],
sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize.cpp"],
verbose=True)
if torch.cuda.is_available():
#import roi_align_1.crop_and_resize_gpu as crop_and_resize_gpu
crop_and_resize_gpu = load(name="crop_and_resize_gpu",
extra_include_paths=["src"],
sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize_gpu.cpp", "/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/cuda/crop_and_resize_kernel.cu"],
verbose=True)
you may just use the code above in crop_and_resize.py. If you use JIT, you don't have to run "install.py".
The "roi_align_1" thing is because I tried the rename method(which didn't work).

can you send the modified directory here.for me still it shows the same error even if i do correct installation

I have tried two methods mentioned above but didn't work. So I complied with JIT and it worked.

from torch.utils.cpp_extension import load #import roi_align_1.crop_and_resize_cpu as crop_and_resize_cpu crop_and_resize_cpu = load(name="crop_and_resize", extra_include_paths=["src"], sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize.cpp"], verbose=True) if torch.cuda.is_available(): #import roi_align_1.crop_and_resize_gpu as crop_and_resize_gpu crop_and_resize_gpu = load(name="crop_and_resize_gpu", extra_include_paths=["src"], sources=["/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/crop_and_resize_gpu.cpp", "/home/omnisky/sun/sparse-rcnn-versions/SparseRCNN-4.10-roiTrans/RoIAlign.pytorch-master/roi_align_1/src/cuda/crop_and_resize_kernel.cu"], verbose=True) you may just use the code above in crop_and_resize.py. If you use JIT, you don't have to run "install.py". The "roi_align_1" thing is because I tried the rename method(which didn't work).

May I ask how to use JIT? When I used your method, it reported this error that NameError: name 'load' is not defined. I don't know how to solve it.

Same error here... I am trying to use this verison instead..

请问下你是怎么修改的呢,可以发下你改的给个参考吗?我不太清楚RoIAlign里的参数需要作何改变?谢谢