【Pytorch警告】Using a target size (torch.Size([])) that is different to the input size (torch.Size([1])

Pytorch警告记录:


UserWarning: Using a target size (torch.Size([])) that is different to the input size (torch.Size([1]))

我代码中造成警告的语句是:

value_loss = F.mse_loss(predicted_value, td_value) # predicted_value是预测值,td_value是目标值,用MSE函数计算误差

原因:mse_loss损失函数的两个输入Tensor的shape不一致。经过reshape或者一些矩阵运算以后使得shape一致,不再出现警告了。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2023年7月15日
下一篇 2023年7月15日

相关推荐