Problem with load_learner()

Hi there

I created a model, exported it and now i’m trying to load it in again.
learn.export(fname=“model.pkl”)
learn = load_learner(“model.pkl”)

However this throws an error:


image

Does anyone know what the problem could be here?
Thanks in advance!

Possibly this link may help: Cannot Load Learner in different script

2 Likes

Is get_y_array a function you defined? If so, learn.export can pickle this function (see the docs). You either need to re-define the function, so that it can be loaded from __main__ or you could use dill instead of pickle.

2 Likes

That was indeed the case, I forgot about that method and didn’t remember writing it, it seemed like an internal method to me. I redefined it and I was able to import the model.
Thanks for the help!