Saved Location for learn.save

When we run the command:

learn.save(‘stage-1’)

Where does this file get saved to and do we have access to this file?

3 Likes

Yes. I also wanted to ask this.

It gets saved to a local directory, default name = “models”.
If you want to save it somewhere else, say “foodir” you can add model_dir=“foodir” in the Learner constructor.
Yes, we have access to these files, eg models/stage-1.pth

1 Like

Thanks German, but there isn’t a models directory for me. I’m using the Google Cloud Platform. Are you using your own machine?

I am using both a local machine and an IBM Cloud machine.
Which version of fastai are you running?
See

import fastai.version
fastai.__version__
1 Like

Seems like lots of ppl ask the same question. I am using GCP and I found the save files using this command:

$ find . -name *.pth -print
./.torch/models/resnet34-333f7ec4.pth
./.fastai/data/oxford-iiit-pet/images/models/tmp.pth
./.fastai/data/oxford-iiit-pet/images/models/stage-2.pth
./.fastai/data/oxford-iiit-pet/images/models/stage-1.pth

5 Likes

Already answered in the forum here.

This has been answered before, but as this thread will get found easily, I’ll try again :wink:

For the lesson 1 notebook example, by default things will get saved here:

~/.fastai/data/oxford-iiit-pet/images/models/

Genereally there is a new .fastai directory in your linux home folder (go there using cd ~/.fastai)

in it you find a data folder in which the downloaded models get stored by default.

But, this may vary by system because you can set this default path in this file:

~/.fastai/config.yml

This yaml file currently has exactly one line, and in it you can specify the path to store your data (so you can redirect it to e.g. an nvme drive), so you can edit this yourself here.

data_path: ~/.fastai/data

So, for most of the users this will got to the .fastai folder itself, but depending on the preinstalled image you use, this may have been redirected to a different folder (paperspace…). But you can look it up in this file.

So the models you save yourself will generaly get stored in:

<path_in_config_yaml>/<dataset_name>/images/<model>

for the standard datasets.
It will get stored in the path

<train_path_you_specified_for_your_data_in_DataBunch>/models/

So, if that is your current dir, then it gets stored there.

6 Likes

Thanks. I found the saved models using that command.

I found the model too, but I can’t access it using the jupyter environnement on Google Cloud Platform. Is there any command to DL the model exported directly to our computer ?

1 Like

It should be saved in a data/models directory than you can access and download the file.

If the file is in a hidden directory, then use this

gcloud compute scp --recurse my-fastai-instance:~/full directory where the file is/filename.pth ~/

And that will move it to the main GCP folder where you can access it and download it.

Hi @Mauro

thanks for your help. Turns out you can specify a complete path inside the learn.save() and learn.export() functions. So I got around my problem that way. But your solution is great (the model was indeed save inside a hidden directory)

1 Like

Hi, please help, I am a new learner here, I have got the same issue?

I am using GCP, on MacOS. The lesson 1 cat or dog save learned model file ‘stage-1’ is not in my local Jupyter notebook folder, I am assuming it is in the GCP path somewhere, but I don’t know how to access to it?

Also, may I use the model file to deploy on GCP by the "Production’’ guide here https://course.fast.ai/?

Thank you!
best regards,

Hi, can you help me please, I can’t find the .pth file in my GCP account? Iam using macOS.

I try your line of CLI code, but it doesn’t work?

gcloud compute scp --recurse my-fastai-instance:~/full directory where the file is/filename.pth ~/

Should I change the “my-fastai-instance” to my own instance name?

Hi @dummie ,

it might be a lot late, but for future readers as well:

Assuming you’ve called your model “learn”, just as in the lessons:
You can type “learn.” in your jupyter notebook cell and press tab. You should see a lot of options appearing. One of those is “path”.
If nothing appears, don’t worry. Just type “learn.path” and run the cell. You’ll get a path towards the model’s data.
Then type “learn.model_dir”
You’ll get the name of the model directory where the weights are saved.

Now type “learn.path/learn.model_dir”
Voilà, here is your path towards your weights :wink:

3 Likes

what if i wanna save the model in the elsewhere (not in the directory of the dataset)?

Have you solved this?

May be late, but here is my solution:
Instead of learn.save(‘stage-1’), you do
learn.save(‘/your desired path/whatever name you want’)