获取两个张量中每个元素之间的均方误差

社会演员多 pytorch 477

原文标题Get mean squared error between every element in two tensors

我有两个一维张量,y_predy_true,其中:

>>> y_pred.shape
torch.Size([2730441, 1])
>>> y_true.shape
torch.Size([2730441, 1])

为了获得两个张量之间的均方误差,我可以使用torch.nn.MSELoss()但是,我想获得张量中每一行/元素之间的损失y_pred&y_trueie。我想运行一些函数elementWiseMSE(y_pred, y_true)将返回loss_tensor形状[2730441, 1]哪个包含所有预测的元素平均误差。

原文链接:https://stackoverflow.com//questions/71539108/get-mean-squared-error-between-every-element-in-two-tensors

回复

我来回复
  • lejlot的头像
    lejlot 评论

    您正在寻找的“功能”实际上是

    loss_tensor = (y_pred - y_true) ** 2
    
    2年前 0条评论