RuntimeError: The size of tensor a (128) must match the size of tensor b (32) at non-singleton dimen

RuntimeError: The size of tensor a (128) must match the size of tensor b (32) at non-singleton dimension 0

D_loss = -torch.mean(torch.log(D_real_gauss + TINY) + torch.log(1 - D_fake_gauss + TINY))
RuntimeError: The size of tensor a (128) must match the size of tensor b (32) at non-singleton dimension 0

运行Pytorch时出现了这样一个错误,原因在于计算二分类交叉熵损失函数时是在每个batch中进行的,而总的图片数量并不能被所设置的batch_size整除,造成最后一个batch的图片数量与batch_size不相等。

你可能感兴趣的:(Pytorch)