sniklaus / pytorch-pwc

a reimplementation of PWC-Net in PyTorch that matches the official Caffe version
GNU General Public License v3.0
620 stars 123 forks source link

CuPy correlation layer error #56

Closed DavidePaglieri closed 2 years ago

DavidePaglieri commented 2 years ago

Hello! When running your code I get the following error:

python run.py --model default --one ./images/one.png --two ./images/two.png --out ./out.flo
Traceback (most recent call last):
  File "run.py", line 319, in <module>
    tenOutput = estimate(tenOne, tenTwo)
  File "run.py", line 305, in estimate
    tenFlow = torch.nn.functional.interpolate(input=netNetwork(tenPreprocessedOne, tenPreprocessedTwo), size=(intHeight, intWidth), mode='bilinear', align_corners=False)
  File "/home/wizard/miniconda/envs/PWC/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "run.py", line 266, in forward
    objEstimate = self.netSix(tenOne[-1], tenTwo[-1], None)
  File "/home/wizard/miniconda/envs/PWC/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "run.py", line 194, in forward
    tenVolume = torch.nn.functional.leaky_relu(input=correlation.FunctionCorrelation(tenOne=tenOne, tenTwo=tenTwo), negative_slope=0.1, inplace=False)
  File "/home/wizard/pytorch-pwc/./correlation/correlation.py", line 386, in FunctionCorrelation
    return _FunctionCorrelation.apply(tenOne, tenTwo)
  File "/home/wizard/pytorch-pwc/./correlation/correlation.py", line 291, in forward
    cupy_launch('kernel_Correlation_rearrange', cupy_kernel('kernel_Correlation_rearrange', {
  File "cupy/_util.pyx", line 67, in cupy._util.memoize.decorator.ret
  File "/home/wizard/pytorch-pwc/./correlation/correlation.py", line 275, in cupy_launch
    return cupy.cuda.compile_with_cache(strKernel).get_function(strFunction)
AttributeError: 'NoneType' object has no attribute 'get_function'

Any ideas on how to solve this? I have installed the requirements correctly.

sniklaus commented 2 years ago

You are hitting this bug in CuPy which you should be able to resolve be using an older CuPy version: https://github.com/cupy/cupy/issues/6231

DavidePaglieri commented 2 years ago

Thank you for answering this so fast, however could you say more precisely which versions you are using for Pytorch, cuda and cupy? I have tried different things and still get errors.

sniklaus commented 2 years ago

The specific versions don't matter that much as long as your PyTorch version isn't too old and you are not using version 10.0 of CuPy. What matters more is that your PyTorch and CuPy use the same CUDA version, so make sure this is the case.

DavidePaglieri commented 2 years ago

Okay thank you very much for the help! I managed to make it work. For reference if anyone has the same error in the future, these worked for me:

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch pip install cupy-cuda92