junyanz / CycleGAN

Software that can generate photos from paintings, turn horses into zebras, perform style transfer, and more.
Other
12.34k stars 1.94k forks source link

Size mismatch RuntimeError on training with FINE_SIZE more than 256. #101

Closed siddhartha-iitd closed 5 years ago

siddhartha-iitd commented 5 years ago

Using LOAD_SIZE=640, FINE_SIZE=256 for training works fine. However, using LOAD_SIZE=640, FINE_SIZE=512 or LOAD_SIZE=512, FINE_SIZE=512 throws a RunTimeError shown below:

Traceback (most recent call last):
  File "./train.py", line 34, in <module>
    model.optimize_parameters()
  File "bicyclegan/BicycleGAN/models/bicycle_gan_model.py", line 209, in optimize_parameters
    self.forward()
  File "bicyclegan/BicycleGAN/models/bicycle_gan_model.py", line 106, in forward
    self.z_encoded, self.mu, self.logvar = self.encode(self.real_B_encoded)
  File "bicyclegan/BicycleGAN/models/bicycle_gan_model.py", line 83, in encode
    mu, logvar = self.netE.forward(input_image)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 121, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "bicyclegan/BicycleGAN/models/networks.py", line 602, in forward
    output = self.fc(conv_flat)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py", line 91, in forward
    input = module(input)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py", line 55, in forward
    return F.linear(input, self.weight, self.bias)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1024, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [1 x 1024], m2: [256 x 8] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:249

Could you please help me find out how can I train the model for FINE_SIZE values of 512 or more ? Thanks!

junyanz commented 5 years ago

I think the question was posted in the wrong repo. This question is related to BicycleGAN. The default generator in BicycleGAN is unet_128 or unet_256. It now only supports 128 or 256. For 512 images, you can either use resnet_256 or add a few layers to unet_256.

siddhartha-iitd commented 5 years ago

Thanks @junyanz for reply. I just made that change and it works :) Thanks again!