a-PyTorch-Tutorial-to-Object-Detection icon indicating copy to clipboard operation
a-PyTorch-Tutorial-to-Object-Detection copied to clipboard

RuntimeError: expected device cpu but got device cuda:0 when I run train.py

Open Shkunn opened this issue 5 years ago • 2 comments

Hi everyone !!!

I'm trying to run this code to train on my own dataset but I'm having this issue.

Here is my problem : Traceback (most recent call last): File "train.py", line 232, in main() File "train.py", line 101, in main epoch=epoch) File "train.py", line 153, in train loss = criterion(predicted_locs, predicted_scores, boxes, labels) # scalar File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in call result = self.forward(*input, **kwargs) File "/content/drive/My Drive/Model/SSD/model.py", line 593, in forward true_locs[i] = cxcy_to_gcxgcy(xy_to_cxcy(boxes[i][object_for_each_prior]), self.priors_cxcy) # (8732, 4) File "/content/drive/My Drive/Model/SSD/utils.py", line 312, in cxcy_to_gcxgcy return torch.cat([(cxcy[:, :2] - priors_cxcy[:, :2]) / (priors_cxcy[:, 2:] / 10), # g_c_x, g_c_y RuntimeError: expected device cuda:0 but got device cpu

So I supposed one of the two elements (cxcy or priors_cxcy) is not passed in cuda. I looked in the code for those elements but it seems that every elements are using .cuda().

If someone already has had this problem please help me. Any thoughts are welcome !

Shkunn avatar Nov 04 '19 16:11 Shkunn

It seems you're running this on a machine without a graphics card.. Or perhaps the graphics cards or the drivers are not properly configured & bind with PyTorch!

kmario23 avatar Nov 18 '19 13:11 kmario23

have you downloaded the Cuda tool kit and bind it correctly with PyTorch?

Philopatearashraf avatar Apr 06 '20 15:04 Philopatearashraf