prob * SCORES 报错:
RuntimeError: expected device cpu and dtype Float but got device cpu and dtype Long
其中prob和SCORES的数据及类型是:
SCORES = torch.tensor([[1, 2, 3, 4, 5]])
In [71]: prob
Out[71]:
tensor([[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],
[0.2001, 0.2002, 0.1998, 0.2001, 0.1998],
[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],
...,
[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],
[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],
[0.1999, 0.2000, 0.2000, 0.2000, 0.2000]], grad_fn=<SoftmaxBackward>)
解决方法:
将SCORES由整数类型改为float类型:
SCORES = torch.tensor([[1., 2., 3., 4., 5.]])
或者:
SCORES = SCORES.float()
pytorch报错RuntimeError: expected device cpu and dtype Float but got device cpu and dtype Long
最新推荐文章于 2024-05-25 22:21:23 发布