【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一致,不再出现警告了。

你可能感兴趣的:(pytorch,深度学习,人工智能)