junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
23.17k stars 6.33k forks source link

Training pix2pix with different input size #1585

Open MrMonk3y opened 1 year ago

MrMonk3y commented 1 year ago

When I try to train the pix2pix model with the --preprocess, --load_size or --crop_size flag I run into an issue.

I try to train the pix2pix model on grayscale 400x400 images. For this I use those parameters: '--model' 'pix2pix' '--direction' 'BtoA' '--input_nc' '1' '--output_nc' '1' '--load_size' '400' '--crop_size' '400'.

I get a RuntimeError on line 536 of the networks.py script:

    def forward(self, x):
        if self.outermost:
            return self.model(x)
        else:   # add skip connections
            return torch.cat([x, self.model(x)], 1)    <--- error

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 3 but got size 2 for tensor number 1 in the list.

When evaluating self.model(x) I get a shape of torch.Size([1, 512, 2, 2]) however, x has the shape torch.Size([1, 512, 3, 3]).

I tried different sizes, used even an odd numbers and made the load size bigger than the crop size. I also tried to use RGB images and get rid of the input_nc and output_nc flag. So far without success.

Does anyone have a hint?

TehreemFarooqi commented 1 year ago

Hey, did you find any solution for this? Getting "RuntimeError: Trying to resize storage that is not resizable"

MrMonk3y commented 1 year ago

Hey. Unfortunately no. I just switched back to 3 color channels from the example. Then it worked.

yftianwin commented 5 months ago

Hey, friends! I want to train not square image, such as 200×300. How can I set?