Skip to content

Solution for error on cpu-only machine #16

@inyong37

Description

@inyong37

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions