Trouble with learner.load()

I’m following along lesson 1 with google colab. Great fun, and very interesting, but I’ve run into an issue.

I pulled the whole repo down to my google drive. This was kind of an accident. I did it before I read the instructions to get one file at a time and then use ‘save a copy’ as you go. However, I decided to run with it, because I’ll have to remember to ‘save a copy’ and risk losing my work.

I first had an issue with learn.save(), because it was saving the model to some directory that actually exists in the parent directory of my Google Drive. I always thought ‘My Drive’ was the root directory but I guess I was wrong.

So I fixed that with the directions from this post: How to save FAST AI resnet50 model to Google Drive after training in google colab notebook

basically I set

learn.path = '/content/gdrive/My Drive/Colab Notebooks/course-v3/nbs/dl1/models/'

and everything worked great. Model saved.

Now, I’m to the part of lesson one where we are supposed to use learner.load(), However, it seems like the load function isn’t getting the notice about the changed path where my models reside. It is trying to load my model from:

/content/gdrive/My Drive/Colab Notebooks/course-v3/nbs/dl1/models/models/stage-1.pth

You might notice, it is looking in ../models/models/, which is not a folder that exists, and is not the path I specified when I set learn.path.

I wanted to read the docs about how this function works, but I can’t find the method under vision.learner. In fact I can’t find much info about any of the methods. The docs seem to be missing a lot, and that’s making it really hard for me to figure this out.

I also tried using the doc() function as in earlier in lesson one:

doc(vision.learner.load()) and I get a error saying the method load does not exist. When I Ctrl+Click on the load method, it shows me the definition, but the code is barely readable for someone of my ability…

I saw mention of another method load_learner but is also not described in the documentation. All and all the docs seem kinda lacking.

So I’m stuck, and I’m frustrated. Can someone please help me?

You should do doc(learn.load) here and it will pull up the documentation from your current learn file.

Now to answer your question, if you notice it’s making an extra call to models (as you pointed out). So first, this path is dictated by your data and the path you pass into it when generating it (so you shouldn’t need to override learn.path) Now when doing learn.load, yes it’s looking in models/models/stage-1.pth. So your learn.path should point to one directory above it. IE: learn.path = '/content/gdrive/My Drive/Colab Notebooks/course-v3/nbs/dl1/

Try this and report back :slight_smile:

@muellerzr Thank you for the fast response!

I tried your method before I posted actually. However, that causes it to save the file as
/content/gdrive/My Drive/Colab Notebooks/course-v3/nbs/dl1/stage-1.pth

Then learn.load('stage-1') looks for the file in

/content/gdrive/My Drive/Colab Notebooks/course-v3/nbs/dl1/models/stage-1.pth

No matter what you set learn.path equal to, learn.load appends ‘/models/’, and so will never find the file.

I finally made two paths, one to save to and one to load from:

dest = Path(base_dir + "nbs/dl1/models")
learn.save(dest/'stage-1')
load_from = Path(base_dir + "nbs/dl1/")
learn.load(load_from/'stage-1')

this did the trick for me…