How to Download timm models to a specified location

Hi everyone,
I’m trying to download a timm model to a user-specified location on my local machine using the following code:
model = timm.create_model(model_name, pretrained=True)

The code above downloads the model to the default location: C:\Users\17swa\.cache\torch\hub\checkpoints, which I don’t want. I want the model to be stored in my user specified location.

However, I couldn’t find a way to specify the download location. Is it possible to do this? If yes, could someone please guide me on how to achieve it?

{Currently I’m at lecture 03 of the fast.ai course :slight_smile: }

Hi,

I have just tried the following and it seems to work:

save_path = /path/to/your/directory

model = timm.create_model(model_name, pretrained=True)

# Save the model's state dictionary (weights) to the specified location

torch.save(model.state_dict(), save_path)

and to load the model you can add:

model.load_state_dict(torch.load(save_path))

model.eval()

I hope this helps!

2 Likes

Thank you for the response.
I’ll do check this way out :slight_smile:

1 Like