jonzhaocn / cnnmrf-pytorch

41 stars 8 forks source link

Crashes with latest Pytorch #2

Closed borisfom closed 5 years ago

borisfom commented 5 years ago

Here, with default parameters: python main.py --style_path Images/kiss.png --content_path Images/blurred.jpg Namespace(content_path='Images/blurred.jpg', content_weight=1, gpu_chunck_size=512, max_iter=100, mrf_style_stride=2, mrf_synthesis_stride=2, num_res=3, sample_step=50, style_path='Images/kiss.png', style_weight=0.4, tv_weight=0.1) /home/bfomitchev/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py:2539: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details. "See the documentation of nn.Upsample for details.".format(mode)) res-1-iteration-10: 15.228654 res-1-iteration-20: 14.772127 res-1-iteration-30: 14.471009 res-1-iteration-40: 14.463431 res-1-iteration-50: 14.320925 Traceback (most recent call last): File "main.py", line 148, in main(config) File "main.py", line 130, in main optimizer.step(closure) File "/home/bfomitchev/anaconda3/lib/python3.6/site-packages/torch/optim/lbfgs.py", line 213, in step loss = float(closure()) File "main.py", line 120, in closure image = get_synthesis_image(synthesis, denorm_transform) File "main.py", line 32, in get_synthesisimage image = denorm(image).clamp(0, 1) File "/home/bfomitchev/anaconda3/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/bfomitchev/anaconda3/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 208, in normalize tensor.sub(mean[:, None, None]).div(std[:, None, None]) RuntimeError: expected device cuda:0 and dtype Float but got device cpu and dtype Float

jonzhaocn commented 5 years ago

if you change the get_synthesis_image function to this:

def get_synthesis_image(synthesis, denorm):
    cpu_device = torch.device('cpu')
    image = synthesis.clone().squeeze().to(cpu_device)
    image = denorm(image).clamp_(0, 1)
    return image

does it work?😃 move image to cpu device before denorm function

borisfom commented 5 years ago

So this is torchvision error - you may want to report it! The workaround you suggested, actually did work, but made my box crawl, consuming 100% CPU and was super-slow. I suppose I can try moving it back to CUDA after denorm ....

borisfom commented 5 years ago

This worked better for me : def get_synthesis_image(synthesis, denorm, device): cpu_device = torch.device('cpu') image = synthesis.clone().squeeze().to(cpudevice) image = denorm(image) return image.to(device).clamp(0, 1)

(and passing device from main).

jonzhaocn commented 5 years ago

Thanks for your suggestion.