Export not creating export.pkl

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


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?

Ubuntu 18.04
Python 3.7.4
Fastai 1.0.60

1 Like

It saves your model to wherever learn.path points to. If you want the current working directory override learn.path

1 Like

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’


Yes you should use a Path

Amazing works like a charm thank you! :slight_smile:

@muellerzr Why should one override this path in order to export something. Why don’t you pass a parameter to the export function?!

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.

hi everyone,

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:

Anyone know a remedy here? I have searched for answers online but am starting to feel pretty demoralized

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.
Cheers, Stay Safe!

1 Like

Hey thanks a ton Palaash

Hey can you please provide the exact code you used. I am facing exactly same problem

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.