to.(device) AttributeError: ‘list‘ object has no attribute ‘to‘

 错误点:

 data, target = data.to(self.device), target.to(self.device)
AttributeError: 'list' object has no attribute 'to'

测试显示:print("6666666666666666666       ",target)

解决方案:将列表元素取出(即list类型转换成tensor类型,将[tensor[....], ...]的数据改为tensor[....], ...)在错误点前输入:target=torch.stack(target, dim=1)

target=torch.stack(target, dim=1)
data, target = data.to(self.device), target.to(self.device)

结果显示:通过

猜你喜欢

转载自blog.csdn.net/weixin_45866058/article/details/130742102