报错信息:
RuntimeError: tried to construct a tensor from a nested int sequence, but found an item of type float at index (0, 0, 0)
我的出错代码是:
in_words_ = Variable(torch.LongTensor(in_words).view(batch_size, len(in_words[0])))
错误处在:
torch.LongTensor(in_words)
验证错误方式:
在代码中加上print(in_words[0][0][0]) 发现输出是-0.41xxx
错误原因:
LongTensor要求输入为Int,但是在[0][0][0]得到了float
解决方式:
错误的代码 改为:in_words_ = Variable(torch.FloatTensor(in_words).view(batch_size, len(in_words[0])))
【error】RuntimeError: tried to construct a tensor from a nested int sequence, but found an item
最新推荐文章于 2023-05-11 10:19:33 发布