PicklingError while exporting a Learner with label smoothing


I’m experimenting with the techniques from chapter 7. I trained a standard CNN learner with the loss function for label smoothing:

learn = cnn_learner(dls, resnet34, metrics=accuracy, loss_func=LabelSmoothingCrossEntropyFlat())

Training runs fine, but when I try to export the learner, the following error occurs:

PicklingError: Can't pickle typing.Callable[..., typing.Any]: it's not the same object as typing.Callable

Exporting the model with the default loss function works fine.

Running fastai 2.0.16 in Colab.
Thank you for any help!

I am facing the same issue in fastai==2.1.4 & Python 3.6.10 .

I could workaround the issue by using cloudpickle for export.

import cloudpickle

learn.export('myexport.pkl', pickle_module=cloudpickle)

cloudpickle won’t work on loading, so you could leave the default setting or use dill (e.g. for unet model)

import dill

learn = load_learner(fname = 'myexport.pkl', cpu=False) #, pickle_module=dill)
1 Like