Pytorch遇到的坑:MSEloss的输入问题

问题

return _VF.broadcast_tensors(tensors)  # type: ignore
RuntimeError: The size of tensor a (96) must match the size of tensor b (336) at non-singleton dimension 1

loss(output,target)

当我的输入为(B,C,336)target为(B,C,96)的时候不会出现报错

而当我的输入为(B,C,96)target为(B,C,336)的时候会出现报错

解答

通过打印报告查到问题是loss的输入维度问题,请参考以下链接

  File "/home/fight/Desktop/LTSF-Linear-main/exp/exp_main.py", line 181, in train
    loss = criterion(outputs, batch_y)
  File "/home/fight/anaconda3/envs/openmmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/fight/anaconda3/envs/openmmlab/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 528, in forward
    return F.mse_loss(input, target, reduction=self.reduction)
  File "/home/fight/anaconda3/envs/openmmlab/lib/python3.7/site-packages/torch/nn/functional.py", line 2928, in mse_loss
    expanded_input, expanded_target = torch.broadcast_tensors(input, target)
  File "/home/fight/anaconda3/envs/openmmlab/lib/python3.7/site-packages/torch/functional.py", line 74, in broadcast_tensors
    return _VF.broadcast_tensors(tensors)  # type: ignore
RuntimeError: The size of tensor a (96) must match the size of tensor b (336) at non-singleton dimension 1

Pytorch遇到的坑:为什么模型训练时,L1loss损失无法下降?_一个菜鸟的奋斗的博客-CSDN博客_pytorch损失函数不下降

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值