我有2个numpy数组,我将其转换为张量以使用TensorDataset对象.
import torch.utils.data as data_utils
X = np.zeros((100,30))
Y = np.zeros((100,30))
train = data_utils.TensorDataset(torch.from_numpy(X).double(), torch.from_numpy(Y))
train_loader = data_utils.DataLoader(train, batch_size=50, shuffle=True)
当我做:
for batch_idx, (data, target) in enumerate(train_loader):
data, target = Variable(data), Variable(target)
optimizer.zero_grad()
output = model(data) # error occurs here
我得到了以下错误:
TypeError: addmm_ received an invalid combination of arguments – got (int, int, torch.DoubleTensor, torch.FloatTensor), but expected one of:
[…]
* (float beta, float alpha, torch.DoubleTensor mat1, torch.DoubleTensor mat2)
didn’t match because some of the arguments have invalid types: (int, int, torch.DoubleTensor, torch.FloatTensor)
* (float beta, float alpha, torch.SparseDoubleTensor mat1, torch.DoubleTensor mat2)
didn’t match because some of the arguments have invalid types: (int, int, torch.DoubleTensor, torch.FloatTensor)
最后一个错误来自:
output.addmm_(0, 1, input, weight.t())
正如你在我的代码中看到的那样,我尝试使用.double()来转换张量 – 但这不起作用.为什么他将一个数组转换为FloatTensor对象而另一个数组转换为DoubleTensor?
有任何想法吗?