I was trying to add WGAN_GP loss function into my anime faces gan as model was falling apart (real score was going to 1).
I found this github that implements it in pytorch:
In there was a step of adding the real image with generated image together generate an interpolated image.
But I noticed that on the last batch the real_images(from dataload) only has 77 images while the fake images has 128 images (since generated images come from random pixels) and it resulted in this error:
in gradient_penalty(discriminator, real_data, generated_data, gp_weight)
9 alpha = alpha.expand_as(real_data)
10 alpha = to_device(alpha, device)
—> 11 interpolated = alpha * real_data.data + (1 - alpha) * generated_data.data
12 interpolated = Variable(interpolated, requires_grad=True)
13 interpolated = to_device(interpolated, device)
RuntimeError: The size of tensor a (77) must match the size of tensor b (128) at non-singleton dimension 0
I think for this scenario I should get batch size based on size of real_images coming from data loader? (instead of using the batch size variable hyperparameter)
Also just wondering, will the different batch sizes between real and generated images cause issues in the model?