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

Solution for error on cpu-only machine #16

Closed
inyong37 opened this issue Jul 10, 2019 · 3 comments
Closed

Solution for error on cpu-only machine #16

inyong37 opened this issue Jul 10, 2019 · 3 comments

Comments

@inyong37
Copy link

net.load_state_dict(copyStateDict(torch.load(args.trained_model)))

When I run test.py on my computer that does not have cuda installed, I get the following error even though --cuda=False. I attached the picture, but I also put the error below.

image

raise RuntimeError ('Attempting to deserialize object on a CUDA'
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available () is False.
If you are running on a CPU-only machine, please use torch.load with map_location = 'cpu' to map your storages to the CPU.

In this case, modify the following line in main of test.py and the code will run well. Can you add this part to main code for cpu-only users? I put an example below.

    net.load_state_dict(copyStateDict(torch.load(args.trained_model)))

An example of a modified code:

    if args.cuda:
         net.load_state_dict(copyStateDict(torch.load(args.trained_model)))
     else:
         net.load_state_dict(copyStateDict(torch.load(args.trained_model, map_location='cpu')))

Thank you for publishing this good STD model.

@YoungminBaek
Copy link
Collaborator

@inyong37 Thank you for your suggestion.
It seems a nice solution to the part I missed.
I'll update it next time!

@YoungminBaek
Copy link
Collaborator

@inyong37 The code has been updated according to your example code.
Thanks for your suggestion.

@Iyyappan-vw
Copy link

if args.cuda:

         net.load_state_dict(copyStateDict(torch.load(args.trained_model)))
     else:
         net.load_state_dict(copyStateDict(torch.load(args.trained_model, map_location='cpu')))

I am already have same given code there but also not solve the error

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