'How do I load a deep learning checkpoint without getting an error related to my device location

I wrote a function to load a previously saved checkpoint as shown below:

load_checkpoint(filepath):
    checkpoint = torch.load(filepath,  map_location = torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
    model.classifier = checkpoint['classifier']
    model.load_state_dict(checkpoint['state_dict'])
    model.class_to_idx = checkpoint['model_index']


    return model
load_checkpoint(in_args.save_dir)

And I got the following error: TypeError: 'torch.Device' object is not callable How do i possibly fix this please



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source