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

 Error point:

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

The test shows: print("6666666666666666666 ", target)

Solution: Take out the list elements (that is, convert the list type to tensor type, change [tensor[....], ...]the data to tensor[....], ...) before the error point and enter: target=torch.stack(target, dim=1)

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

The result shows: passed

Guess you like

Origin blog.csdn.net/weixin_45866058/article/details/130742102