NVIDIA / pix2pixHD

Synthesizing and manipulating 2048x1024 images with conditional GANs
https://tcwang0509.github.io/pix2pixHD/
Other
6.62k stars 1.39k forks source link

train on own dataset error : Size of tensor mismatch #248

Open sw5park opened 3 years ago

sw5park commented 3 years ago

I am training on my own dataset, set of images and corresponding label maps.

ran python train.py --name clayseam --batchSize 4 --label_nc 2 --no_instance --dataroot /pub2/sw5park/p2phd, where dataroot folder contains 4 folders : train_label, train_img, test_label, test_img

gives the following error :

Traceback (most recent call last): File "train.py", line 71, in Variable(data['image']), Variable(data['feat']), infer=save_fake) File "/home/sw5park/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, kwargs) File "/home/sw5park/venv/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 153, in forward return self.module(*inputs[0], *kwargs[0]) File "/home/sw5park/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(input, kwargs) File "/home/sw5park/generative/pix2pixHD/models/pix2pixHD_model.py", line 166, in forward pred_fake_pool = self.discriminate(input_label, fake_image, use_pool=True) File "/home/sw5park/generative/pix2pixHD/models/pix2pixHD_model.py", line 145, in discriminate input_concat = torch.cat((input_label, test_image.detach()), dim=1) RuntimeError: Sizes of tensors must match except in dimension 2. Got 560 and 546 (The offending index is 0)

syfbme commented 3 years ago

The size of input and label must be the same

lbf4616 commented 3 years ago

I also met this problem, the input image and label are the same size, after 'scale_with' preprocessing. So, it seems a bug from the Discriminator.

YaoOOoooolin commented 2 years ago

Hello, how did you solve this problem later? I encountered the same problem

HyperSimon commented 1 year ago

把图片大小改为一致就可以了

undcloud commented 1 year ago
b = cv2.imread(j)
h = b.shape[0]
w = b.shape[1]
h = int ( 1024 / w * h // 32 * 32 )
b = cv2.resize(b, (1024, h))
wenyi-li commented 7 months ago

I encountered the same problem. My train script is python train.py --name mydata --dataroot ./datasets/mydata --batchSize 2 --gpu_ids 4,5 --label_nc 3 --no_instance The size of input and label are the same, they are both 512×512

wenyi-li commented 7 months ago

I also met this problem, the input image and label are the same size, after 'scale_with' preprocessing. So, it seems a bug from the Discriminator.

In pix2pixHD_model.py: line 163

fake_image = self.netG.forward(input_concat)
# Fake Detection and Loss
pred_fake_pool = self.discriminate(input_label, fake_image, use_pool=True)

My input_label is [1, 3, 852, 1024], but the fake_image is [1, 3, 864, 1024]. I use the following way to make the code run successfully.

fake_image = fake_image[:, :, :input_label.shape[2], :]

However, I'm not sure whether it will influence the performance of the model.

pilipala818 commented 2 months ago

I also met this problem, the input image and label are the same size, after 'scale_with' preprocessing. So, it seems a bug from the Discriminator.

In pix2pixHD_model.py: line 163

fake_image = self.netG.forward(input_concat)
# Fake Detection and Loss
pred_fake_pool = self.discriminate(input_label, fake_image, use_pool=True)

My input_label is [1, 3, 852, 1024], but the fake_image is [1, 3, 864, 1024]. I use the following way to make the code run successfully.

fake_image = fake_image[:, :, :input_label.shape[2], :]

However, I'm not sure whether it will influence the performance of the model.

直接丢掉会影响,插值成要的大小影响会小一点 fake_image = F.interpolate(fake_image, size=(, ), ............)

zhangxiaojuan66 commented 2 months ago

你好,邮件已收到,祝你万事如意,生活愉快!