Problems using learn.export(): "PicklingError: Can't pickle <function <lambda>"

Having issues trying to export a binary segmentation model using fastai’s .export() method. The model is similar to the CAMVID segmentation presented in 2019 course. Has anyone encountered this error using .export()? Are there any other options for inference?

I remember reading somewhere that fastai export might not work with lambda functions. How about if you change lambda to named functions, would it work then?


Thanks! Worked a treat

1 Like

I had a situation where I couldn’t define (or import) named functions in the execution context. The __main__ context was strictly defined to accept only a single class called Deployment so I couldn’t import my function (or define it as a global).

The solution was to use pickle_protocol=dill which is an option on saving methods for learners and data loaders. (and also is available using torch directly to save or load)


please give me a example

import dill
learn_smp.export(‘learn_smp_resnet_20epoch.pkl’, pickle_module=dill)