Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensors are on different GPUs #32

Closed
DragonBornHD opened this issue Jun 26, 2017 · 7 comments
Closed

tensors are on different GPUs #32

DragonBornHD opened this issue Jun 26, 2017 · 7 comments

Comments

@DragonBornHD
Copy link

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!

@alexkoltun
Copy link

alexkoltun commented Jun 26, 2017

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()

@DragonBornHD
Copy link
Author

I tried this way, another error occurred:

TypeError: mul received an invalid combination of arguments - got (torch.FloatTensor), but expected one of:

  • (float value)
    didn't match because some of the arguments have invalid types: (torch.FloatTensor)
  • (torch.cuda.FloatTensor other)
    didn't match because some of the arguments have invalid types: (torch.FloatTensor)

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.

@alexkoltun
Copy link

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')

@DragonBornHD
Copy link
Author

That's doesn't work, same problem.

@alexkoltun
Copy link

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()

@DragonBornHD
Copy link
Author

Yes it works!
torch.set_default_tensor_type('torch.cuda.FloatTensor') Should before net = build_ssd('test', 300, 21)
Thank you very much !!

@DonghoonPark12
Copy link

DonghoonPark12 commented Aug 12, 2019

@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??

images = images.cuda()
# and
images = images

Thanks ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants