AttributeError: ‘list‘ object has no attribute ‘cuda‘

it2023-04-29  79

AttributeError: ‘list’ object has no attribute ‘cuda’ 查看自己的target类型,原为[‘1’,‘0’,‘1’,‘1’]。这种列表试字符串型。而应该修改为torch.tensor类型。才能用于网络计算 简单改为:先改为numpy再转换为tensor,搞定! label = torch.from_numpy(np.fromstring(label, dtype=int, sep=’,’))

所以需要先把target从str映射成int,再转为tensor

最新回复(0)