I am running Python program, but I do not have a GPU, what can I do to make Python use CPU instead of GPU?
$ python extract_feature.py --data mnist --net checkpoint_4.pth.tar --features pretrained
It gives me the following warning:
=> 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=torch.device('cpu') to map your storages to the CPU.
The photo is the Structure of my Python project:

I got into a similar error. Then by trying the following workaround issue is solved. (If your model is .pth or .h5 format.)
MODEL_PATH = 'Somemodelname.pth'
model.load_state_dict(torch.load(MODEL_PATH,
map_location=torch.device('cpu')))
If you want certain GPU to be used in your machine. Then,
map_location = torch.device('cuda:device_id')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With