RuntimeError: (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

I would greatly appreaciate it if you can help me to solve the error below

When training in google colab I get the following:

untimeError Traceback (most recent call last)
in ()
3 for epoch in range(num_epochs):
4 # train for one epoch, printing every 10 iterations
----> 5 train_one_epoch(mask_model, optimizer, data_loader, device, epoch, print_freq=10)
6 # update the learning rate
7 lr_scheduler.step()

9 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in conv2d_forward(self, input, weight)
340 _pair(0), self.dilation, self.groups)
341 return F.conv2d(input, weight, self.bias, self.stride,
–> 342 self.padding, self.dilation, self.groups)
343
344 def forward(self, input):

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same.

I

Your data is on the GPU and your model is on CPU. Pass the model to gpu and it should be fine.

1 Like

Thanks a lot that worked. However I have a new error. Please help!!

TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
116 try:
–> 117 num = operator.index(num)
118 except TypeError:

TypeError: ‘numpy.float64’ object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
7 frames
<array_function internals> in linspace(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
119 raise TypeError(
120 “object of type {} cannot be safely interpreted as an integer.”
–> 121 .format(type(num)))
122
123 if num < 0:

TypeError: object of type <class ‘numpy.float64’> cannot be safely interpreted as an integer.

Well seems like you have to cast num to an integer.