yunjey / pytorch-tutorial

PyTorch Tutorial for Deep Learning Researchers
MIT License
29.79k stars 8.03k forks source link

expected backend CUDA and dtype Float but got backend CPU and dtype Float #180

Closed ouening closed 5 years ago

ouening commented 5 years ago

OS:Ubuntu18.04 pytorch:1.1.0 When I run /pytorch-tutorial-master/tutorials/03-advanced/neural_style_transfer/main.py, I got errors: Traceback (most recent call last): File "/home/gaoya/Files/python/pytorch/pytorch-tutorial-master/tutorials/03-advanced/neural_style_transfer/main.py", line 169, in <module> main(config) File "/home/gaoya/Files/python/pytorch/pytorch-tutorial-master/tutorials/03-advanced/neural_style_transfer/main.py", line 153, in main img = denorm(img).clamp_(0, 1) File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 163, in __call__ return F.normalize(tensor, self.mean, self.std, self.inplace) File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py", line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: expected backend CUDA and dtype Float but got backend CPU and dtype Float

Can someone help me?

ouening commented 5 years ago

Solved ! img = target.clone().squeeze() img = torch.FloatTensor(img.cpu()) img = denorm(img).clamp_(0, 1)