I run the demo, return 'tensors are on different GPSs' , but I have only one GPU.
The demo was run successfully with CPU.
Can you put the process of using the GPU to release it?
Thank you very much!
Most likely that the net is not on GPU, try adding the following, just after weight loading:
if torch.cuda.is_available():
net = net.cuda()
I tried this way, another error occurred:
TypeError: mul received an invalid combination of arguments - got (torch.FloatTensor), but expected one of:
I added the 'net = net.cuda()' after 'net.load_state_dict(torch.load(trained_model))' , and 'x = x.cuda()' after 'x = Variable(x.unsqueeze(0))' .
Thank you.
I see.. I think setting the default tensor to be cuda might solve it, try to put the following somewhere before model loading:
if torch.cuda.is_available():
torch.set_default_tensor_type('torch.cuda.FloatTensor')
That's doesn't work, same problem.
Did you restart the kernel?
I tested with the following change on a GPU machine and it works:
if torch.cuda.is_available():
torch.set_default_tensor_type('torch.cuda.FloatTensor')
net = build_ssd('test', 300, 21) # initialize SSD
net.load_weights('../weights/ssd300_mAP_77.43_v2.pth')
if torch.cuda.is_available():
net = net.cuda()
Yes it works!
torch.set_default_tensor_type('torch.cuda.FloatTensor') Should before net = build_ssd('test', 300, 21)
Thank you very much !!
@alexkoltun
I'm sorry but, when I train my network on gpu by below code,
if torch.cuda.is_available():
net = net.cuda()
Why there is another need when I'm training for example in train.py
if args.cuda:
images = images.cuda()
targets = [ann.cuda() for ann in targets]
else:
images = images
targets = [ann for ann in targets]
Is there also diffenrence between below two line??
```python
images = images.cuda()
images = images
````
Thanks ahead.
Most helpful comment
Did you restart the kernel?
I tested with the following change on a GPU machine and it works: