【发布时间】:2018-12-03 05:10:12
【问题描述】:
我正在 PyTorch 中实现一些 RL,并且必须编写我自己的 mse_loss 函数(我在 Stackoverflow 上找到的;))。 损失函数为:
def mse_loss(input_, target_):
return torch.sum(
(input_ - target_) * (input_ - target_)) / input_.data.nelement()
现在,在我的训练循环中,第一个输入类似于:
tensor([-1.7610e+10]), tensor([-6.5097e+10])
使用这个输入我会得到错误:
Unable to get repr for <class 'torch.Tensor'>
计算 a = (input_ - target_) 工作正常,而 b = a * a 和 b = torch.pow(a, 2) 将因上述错误而失败。
有人知道解决这个问题的方法吗?
非常感谢!
更新:
我刚刚尝试使用torch.nn.functional.mse_loss,这将导致相同的错误..
【问题讨论】:
-
repr 不是内置函数吗? (docs.python.org/3/reference/…)
-
好像.. 但它为什么会尝试调用这个方法呢?张量是 float32 类型,此错误不仅发生在调试模式下,而且在运行“正常”时也会发生..
-
这是非常奇怪的 PyTorch 行为。也许更新?