DeepImageBlending icon indicating copy to clipboard operation
DeepImageBlending copied to clipboard

Help,Why do I report errors when I run 'python run.py' directly???

Open waifungloo opened this issue 4 years ago • 5 comments

I didn't make any changes,but it made a mistake.

Traceback (most recent call last): File "run.py", line 219, in optimizer.step(closure) File "/home/ubuntu/anaconda3/envs/lwf/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, **kwargs) File "/home/ubuntu/anaconda3/envs/lwf/lib/python3.6/site-packages/torch/optim/lbfgs.py", line 316, in step flat_grad = self._gather_flat_grad() File "/home/ubuntu/anaconda3/envs/lwf/lib/python3.6/site-packages/torch/optim/lbfgs.py", line 255, in _gather_flat_grad view = p.grad.view(-1) RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

waifungloo avatar Sep 09 '20 15:09 waifungloo

Got the same error. Has anyone resolved it?

Akbarmq01 avatar Sep 10 '20 10:09 Akbarmq01

Download the optimizer source code of LBFGS as a separate python file in your local code from pytorch github instead of importing it as "nn.optim.LBFGS ". Also, import the libraries for this file as import torch from functools import reduce from torch.optim import Optimizer

  1. In new class file, change the line view = p.grad.view(-1) to view = p.grad.contiguous().view(-1) .
  2. Also make sure to instantiate the optimizer class of your local code rather than nn.optim in run.py.

Re-run your code and it should work.

saandeepa93 avatar Sep 12 '20 21:09 saandeepa93

@saandeepa93 Your solution works perfectly! I have trouble while understanding the argument --x & --y in the run.py file. I believe they help me decide the starting point from which the mask needs to be placed (assuming origin is top left corner). I am observing these coordinates to go below 0 or more than the image shape? why is that so?

Also please provide some ideas to improve the output, I have observed the second stage output to be worse than first stage?

amil-rp-work avatar Oct 06 '20 11:10 amil-rp-work

Just change line 63 in run.py

from:

input_img = torch.randn(target_img.shape).to(gpu_id)

to:

input_img = torch.randn(target_img.shape).contiguous().to(gpu_id)

this solution works for me :)

ManuLasker avatar Jan 22 '21 15:01 ManuLasker

You can just directly change lbfgs.py installed in your site-packages folder. In my case, I've changed one line of lbfgs.py in '..Python\Python37\Lib\site-packages\torch\optim'.

from:

view = p.grad.view(-1)

to:

view = p.grad.contiguous().view(-1)

sanspareilsmyn avatar Feb 15 '21 04:02 sanspareilsmyn