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?

3 Likes

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)

3 Likes