Shift-Net_pytorch icon indicating copy to clipboard operation
Shift-Net_pytorch copied to clipboard

RuntimeError: cannot reshape tensor of 0 elements into shape [1, 0, -1] because the unspecified dimension size -1 can be any value and is ambiguous

Open lrn1314 opened this issue 1 year ago • 3 comments

Hi, I'm reproducing the code with my PSV dataset and celebA-HQ dataset and it always reports an error right at the beginning of the run, what's going on?

(epoch: 1, iters: 6300, time: 0.130, data: 0.001) G_GAN: 0.364 G_L1: 3.201 D: 0.357 style: 0.000 content: 3.616 tv: 0.000 (epoch: 1, iters: 6350, time: 0.055, data: 0.001) G_GAN: 0.907 G_L1: 10.731 D: 0.013 style: 0.001 content: 9.537 tv: 0.000 (epoch: 1, iters: 6400, time: 0.120, data: 0.001) G_GAN: 0.556 G_L1: 3.999 D: 0.497 style: 0.000 content: 3.406 tv: 0.000 (epoch: 1, iters: 6450, time: 0.058, data: 0.001) G_GAN: 0.717 G_L1: 6.215 D: 0.751 style: 0.001 content: 5.853 tv: 0.000 (epoch: 1, iters: 6500, time: 0.110, data: 0.001) G_GAN: 0.533 G_L1: 5.849 D: 0.084 style: 0.001 content: 4.193 tv: 0.000 (epoch: 1, iters: 6550, time: 0.064, data: 0.001) G_GAN: 0.480 G_L1: 7.094 D: 0.181 style: 0.001 content: 8.660 tv: 0.000 (epoch: 1, iters: 6600, time: 0.100, data: 0.000) G_GAN: 0.341 G_L1: 9.444 D: 0.302 style: 0.001 content: 9.420 tv: 0.000 Traceback (most recent call last): File "E:\对比方法\Shift-Net_pytorch-master\train.py", line 39, in model.optimize_parameters() File "E:\对比方法\Shift-Net_pytorch-master\models\shift_net\shiftnet_model.py", line 312, in optimize_parameters self.forward() File "E:\对比方法\Shift-Net_pytorch-master\models\shift_net\shiftnet_model.py", line 186, in forward self.set_gt_latent() File "E:\对比方法\Shift-Net_pytorch-master\models\shift_net\shiftnet_model.py", line 182, in set_gt_latent self.netG(real_B) # input ground truth File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\parallel\data_parallel.py", line 169, in forward return self.module(*inputs[0], **kwargs[0]) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\对比方法\Shift-Net_pytorch-master\models\modules\shift_unet.py", line 59, in forward return self.model(input) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\对比方法\Shift-Net_pytorch-master\models\modules\unet.py", line 80, in forward return self.model(x) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\container.py", line 217, in forward input = module(input) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\对比方法\Shift-Net_pytorch-master\models\modules\unet.py", line 82, in forward x_latter = self.model(x) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\container.py", line 217, in forward input = module(input) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\对比方法\Shift-Net_pytorch-master\models\modules\shift_unet.py", line 132, in forward x_latter = self.model(x) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\container.py", line 217, in forward input = module(input) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\对比方法\Shift-Net_pytorch-master\models\shift_net\InnerShiftTriple.py", line 36, in forward final_out = InnerShiftTripleFunction.apply(input, self.shift_sz, self.stride, self.triple_weight, self.flag, self.show_flow) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\autograd\function.py", line 506, in apply return super().apply(*args, **kwargs) # type: ignore[misc] File "E:\对比方法\Shift-Net_pytorch-master\models\shift_net\InnerShiftTripleFunction.py", line 36, in forward cosine, latter_windows, i_2, i_3, i_1 = bNonparm.cosine_similarity(former_all.clone(), latter_all.clone(), 1, stride, flag) File "E:\对比方法\Shift-Net_pytorch-master\util\NonparametricShift.py", line 90, in cosine_similarity former = self._filter(former_windows, flag, 1) File "E:\对比方法\Shift-Net_pytorch-master\util\NonparametricShift.py", line 138, in _filter return input_window.view(bz, input_window.size(0)//bz, -1) RuntimeError: cannot reshape tensor of 0 elements into shape [1, 0, -1] because the unspecified dimension size -1 can be any value and is ambiguous

Process finished with exit code 1

lrn1314 avatar Jan 13 '24 09:01 lrn1314

It seems the data is corrupted or the size of some images are no larger than fineSize, causing here a empty tensor.

Zhaoyi-Yan avatar Jan 24 '24 08:01 Zhaoyi-Yan

Hi, thanks for the answer. I have solved the problem and it was indeed a problem with the mask data. I have another question, when I finished training the models for the three datasets: celeba, PSV, and place, how should I select the corresponding model I trained for the test?

lrn1314 avatar Jan 25 '24 07:01 lrn1314

If the test image is a face, using celeba model, I do not know the PSV dataset. If the test image is about the natural scenery, using the place model. Here’s a piece of advice for you: maybe you need to try more advanced inpainting methods. This repo is old, you can use it for learning, not suitable for production or practical use.

Zhaoyi-Yan avatar Jan 26 '24 03:01 Zhaoyi-Yan