Data loader error after transforming data
Hi guys, I was wondering if someone can help me out on this one. My problem is the following. I load the mnist dataset using the data loader. I transform the data to numpy to do some operations and transform it back to torch.Tensor. then I do the following: <SCODE>train = torch.utils.data.TensorDataset(train_data, train_ds.train_labels)
train_loader = torch.utils.data.DataLoader(train, batch_size=args.batch_size, shuffle=True)
<ECODE> <SCODE>TypeError                                 Traceback (most recent call last)
/home/user/mnist.py in <module>()
    141
    142 for epoch in range(1, args.epochs + 1):
--> 143     train(epoch)
    144     test(epoch)
    145

/home/mnist.py in train(epoch)
    111         data, target = Variable(data), Variable(target)
    112         optimizer.zero_grad()
--> 113         output = model(data)
    114         loss = F.nll_loss(output, target)
    115         loss.backward()

/home/site-packages/torch/nn/modules/module.pyc in __call__(self, *input, **kwargs)
    208
    209     def __call__(self, *input, **kwargs):
--> 210         result = self.forward(*input, **kwargs)
    211         for hook in self._forward_hooks.values():
    212             hook_result = hook(self, input, result)

/home/ in forward(self, x)
     88
     89     def forward(self, x):
---> 90         x = F.relu(self.linear1(x))
     91         x = F.linear_drop(x)
     92         x = F.relu(self.linear2(x))

/home/lib/python2.7/site-packages/torch/nn/modules/module.pyc in __call__(self, *input, **kwargs)
    208
    209     def __call__(self, *input, **kwargs):
--> 210         result = self.forward(*input, **kwargs)
    211         for hook in self._forward_hooks.values():
    212             hook_result = hook(self, input, result)

/home/lib/python2.7/site-packages/torch/nn/modules/linear.pyc in forward(self, input)
     51             return self._backend.Linear()(input, self.weight)
     52         else:
---> 53             return self._backend.Linear()(input, self.weight, self.bias)
     54
     55     def __repr__(self):

/home/miniconda2/lib/python2.7/site-packages/torch/nn/_functions/linear.pyc in forward(self, input, weight, bias)
      8         self.save_for_backward(input, weight, bias)
      9         output = input.new(input.size(0), weight.size(0))
---> 10         output.addmm_(0, 1, input, weight.t())
     11         if bias is not None:
     12             # cuBLAS doesn't support 0 strides in sger, so we can't use expand

TypeError: addmm_ received an invalid combination of arguments - got (int, int, torch.DoubleTensor, torch.FloatTensor), but expected one of:
 * (torch.DoubleTensor mat1, torch.DoubleTensor mat2)
 * (torch.SparseDoubleTensor mat1, torch.DoubleTensor mat2)
 * (float beta, torch.DoubleTensor mat1, torch.DoubleTensor mat2)
 * (float alpha, torch.DoubleTensor mat1, torch.DoubleTensor mat2)
 * (float beta, torch.SparseDoubleTensor mat1, torch.DoubleTensor mat2)
 * (float alpha, torch.SparseDoubleTensor mat1, torch.DoubleTensor mat2)
 * (float beta, float alpha, torch.DoubleTensor mat1, torch.DoubleTensor mat2)
 * (float beta, float alpha, torch.SparseDoubleTensor mat1, torch.DoubleTensor mat2)

> /home/miniconda2/lib/python2.7/site-packages/torch/nn/_functions/linear.py(10)forward()
      8         self.save_for_backward(input, weight, bias)
      9         output = input.new(input.size(0), weight.size(0))
---> 10         output.addmm_(0, 1, input, weight.t())
     11         if bias is not None:
     12             # cuBLAS doesn't support 0 strides in sger, so we can't use expand
<ECODE>
kirk86
The type of data from  dataloader seem to be float64, so, you can change this float32 like below <SCODE># if img is numpy
img = img.astype('float32')
# if img is torch.tensor
img = img.float()
<ECODE>
jhjungCode
kirk86