pytorch-tutorial icon indicating copy to clipboard operation
pytorch-tutorial copied to clipboard

Hi,I has this problem in style transfer!

Open BCWang93 opened this issue 5 years ago • 2 comments

I have this error in run the code of style transfer: ' Traceback (most recent call last): File "main.py", line 86, in main(opt) File "main.py", line 81, in main img=denorm(img.to(device)).clamp_(0,1) File "/home/a/anaconda3/envs/bcw_env/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File "/home/a/anaconda3/envs/bcw_env/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: expected type torch.cuda.FloatTensor but got torch.FloatTensor

' anyone can help me solve this?Thanks!

BCWang93 avatar May 13 '19 14:05 BCWang93

@BCWang93 How about change device

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

to just

device = torch.device('cpu')

achieve0410 avatar Aug 08 '19 06:08 achieve0410

Is there someone who knows how to edit code to use "cuda" to train the model instead of 'cpu'? Thanks a lot!

Yudezhi avatar Nov 23 '19 07:11 Yudezhi