当前位置:   article > 正文

关于pytorch中损失函数中输入输出不匹配问题_raise valueerror("target size ({}) must be the sam

raise valueerror("target size ({}) must be the same as input size ({})".form
  1. File "C:\Users\Rain\AppData\Local\Programs\Python\Anaconda.3.5.1\envs\python35\python35\lib\site-packages\torch\nn\modules\module.py", line 491, in __call__
  2. result = self.forward(*input, **kwargs)
  3. File "C:\Users\Rain\AppData\Local\Programs\Python\Anaconda.3.5.1\envs\python35\python35\lib\site-packages\torch\nn\modules\loss.py", line 500, in forward
  4. reduce=self.reduce)
  5. File "C:\Users\Rain\AppData\Local\Programs\Python\Anaconda.3.5.1\envs\python35\python35\lib\site-packages\torch\nn\functional.py", line 1514, in binary_cross_entropy_with_logits
  6. raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size()))
  7. ValueError: Target size (torch.Size([32])) must be the same as input size (torch.Size([32,2]))

原因

input 和 target 尺寸不匹配

解决办法

将target转为onehot

例如:

one_hot = torch.nn.functional.one_hot(masks, num_classes=args.num_classes)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/511651
推荐阅读
相关标签
  

闽ICP备14008679号