1、AttributeError:‘list’ object has no attribute ‘clone’.
错误原因:之前传的数据是numpy类型,clone接受tensor类型数据,因此要将之前的数据改为tensor类型。
eg.改正方法:input=torch.tensor(input)
2、ValueError: only one element tensors can be converted to Python scalars.
错误原因:所需转换的list里面的元素包含多维tensor.
eg.改正方法:input=torch.tensor([item.cpu().detach().numpy() for item in input]).cuda()
3、AttributeError: ‘list‘ object has no attribute ‘cuda‘
错误原因:list没有cuda属性,只有tensor有,因此要将list转换为tensor.
eg.改正方法:input=np.array(input) input = torch.from_numpy(input)
还是报错:
eg.改正方法:将numpy数组强制类型转换成float类型:input = input.astype(float)