Hi, I’ve trained a model and want to export it. Following the notes in lesson 2 I think I should be able to just write
learner.export()
and it should create a file called export.pkl in the current working directory. The function runs with no complaints, but I don’t see any new file, and import doesn’t seem to find anything either. Am I missing something?
Oh I see - looks like it’s among my data folder for some reason! Wasn’t expecting it to end up there - I guess it takes the path of wherever the ImageDataBunch is from?
Anyway I can find the file there! Do I have to use PosixPath to override it?
learn.path = os.getcwd()
is giving me a
unsupported operand type(s) for /: ‘str’ and ‘str’
That path is tied to the data’s path. So if you were using Colab where any time you do untar_data, your data is downloaded to a deep hidden folder. Which isn’t readily accessible. So instead we do this.
You could of course also pass a path into the DataBunch creation instead to fix this problem. But that’s why it’s tied in such a way. Your models are saved where your data is saved inside a models/ folder.
I don’t remember if you can pass an explicit path for it to save to.
I work on a server and I have a bunch of python codes in which I create different models, for example, forward model and backward model using the same data. So, if I want to save forward model or backward model, they override the export.plk. To solve this problem, I created two folders then set learn.path to those folder and then exported the learner, while it was easier for me just to pass a path or name for the leaner to be exported.
Since you replied here, I must say, my first try was with save function but later I couldn’t load the model (for some inconsistency of vocabs, etc). I even wondered what’s the use of save function when it’s so complex to load it again.
Im having trouble with the ‘learner.export().’ I have sucessfully created the .pkl file in my data, but when I try to open the file i encounter the following error:
Jupyter can’t read the pkl file directly. You can’t click on it and open it. Though you can use load_learner() to import your model to your workspace and work therefrom.I’m attaching a link to the documentation of load_learner. https://docs.fast.ai/basic_train.html#load_learner
Cheers, Stay Safe!
Hey, I saw your answer. I am facing same problem while I view the path. It shows “.”. And when I do learn.export(). It shows " unsupported operand type(s) for /: ‘str’ and ‘str’ ". Please tell me how to resolve, I am a beginner in this.