Machine-Learning-Collection
Machine-Learning-Collection copied to clipboard
RuntimeError: The size of tensor a (78) must match the size of tensor b (64) at non-singleton dimension 2
The issue is happening in WGAN-GP, using celeb dataset.
Full error:
Traceback (most recent call last):
File "train.py", line 81, in <module>
gp = gradient_penalty(critic, real, fake, device=device)
File "C:\Users\Doggo\DEV\GAN\WGANGP\utils.py", line 10, in gradient_penalty
interpolated_images = real * alpha + fake * (1 - alpha)
RuntimeError: The size of tensor a (78) must match the size of tensor b (64) at non-singleton dimension 2
printing the shape of tensors real and fake inside of the gradient_penalty function in utils.py (directly before the images are interpolated) shows that real has height of 78 instead of 64. real = torch.Size([64, 3, 78, 64]) fake = torch.Size([64, 3, 64, 64])
I fixed the issue by changing transforms.Resize in train.py from transforms.Resize(IMAGE_SIZE) → transforms.Resize((IMAGE_SIZE, IMAGE_SIZE))