Skip to content

关于训练出现的报错 #3

Open
@Hsuan2021

Description

@Hsuan2021

您好,我用的图片数据是512*512的单通道图片,在训练过程中出现了以下报错信息,

UserWarning: Using a target size (torch.Size([10])) that is different to the input size (torch.Size([5])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
  return F.mse_loss(input, target, reduction=self.reduction)
Traceback (most recent call last):
  File "Unsupervised-Defect-Detection-Project-Based-on-VAE-GAN-Architecture-master\VAE_GAN_train.py", line 57, in <module>
    model.train(train_epochs, 5)
  File "Unsupervised-Defect-Detection-Project-Based-on-VAE-GAN-Architecture-master\GAN.py", line 264, in train
    loss_G_adv = self.criterion_GAN(self.discriminator(y), self.real_labels) + \
  File "anaconda3\envs\tensorflow\lib\site-packages\torch\nn\modules\module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "anaconda3\envs\tensorflow\lib\site-packages\torch\nn\modules\module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
  File "anaconda3\envs\tensorflow\lib\site-packages\torch\nn\modules\loss.py", line 535, in forward
    return F.mse_loss(input, target, reduction=self.reduction)
  File "anaconda3\envs\tensorflow\lib\site-packages\torch\nn\functional.py", line 3365, in mse_loss
    expanded_input, expanded_target = torch.broadcast_tensors(input, target)
  File "anaconda3\envs\tensorflow\lib\site-packages\torch\functional.py", line 76, in broadcast_tensors
    return _VF.broadcast_tensors(tensors)  # type: ignore[attr-defined]
RuntimeError: The size of tensor a (5) must match the size of tensor b (10) at non-singleton dimension 0

请问应该如何解决呢?谢谢!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions