sgugger / Deep-Learning

A few notebooks about deep learning in pytorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

to_gpu(x, *args, **kwargs) 'numpy.ndarray' object has no attribute 'cuda'

LittlePandaSea opened this issue · comments

Hi, I try to run the code of the website (https://github.com/sgugger/Deep-Learning/blob/master/DeepPainterlyHarmonization.ipynb).

When in the cell 22, I met a error.
In [22]: m_vgg(VV(input_tfm[None]))
input_ftrs = [s.features for s in sfs]
[sf.shape for sf in input_ftrs]

d:\python3.6.5\lib\site-packages\fastai\core.py in VV(x)
20 def V(x): return [V_(o) for o in x] if isinstance(x,list) else V_(x)
21 def VV_(x): return to_gpu(x, async=True) if isinstance(x, Variable) else Variable(to_gpu(x, async=True), volatile=True)
---> 22 def VV(x): return [VV_(o) for o in x] if isinstance(x,list) else VV_(x)
23
24 def to_np(v):

d:\python3.6.5\lib\site-packages\fastai\core.py in VV_(x)
19 def V_(x): return to_gpu(x, async=True) if isinstance(x, Variable) else Variable(to_gpu(x, async=True))
20 def V(x): return [V_(o) for o in x] if isinstance(x,list) else V_(x)
---> 21 def VV_(x): return to_gpu(x, async=True) if isinstance(x, Variable) else Variable(to_gpu(x, async=True), volatile=True)
22 def VV(x): return [VV_(o) for o in x] if isinstance(x,list) else VV_(x)
23

d:\python3.6.5\lib\site-packages\fastai\core.py in to_gpu(x, *args, **kwargs)
28 def to_gpu(x, *args, **kwargs):
29 if torch.cuda.is_available():
---> 30 return x.cuda(*args, **kwargs)
31 else:
32 return x

AttributeError: 'numpy.ndarray' object has no attribute 'cuda'

the programe is runing in the windows 10 with GTX Titan X.
The software environment is : fastai 0.6 troch 0.4.0 cuda 9.1 + v7.1

I would like to know why ?
Did I installed the software with the wrong version?
How can I fix it ?

Weird... I have the latest version of fastai, pytorch 0.4.0, cuda9.1 and I'm running the notebook on Windows 10 too but I don't get that error.
Looking at your code, I think you may not have the latest version of fastai (there's some stuff linked to pytorch 0.4 in the latest merged PR), so please try a git pull and let me know if it fixes the bug.