"Can't pickle local object" on learner.export() for unet_learner

When trying to export a learner which has been trained to identify regions in an image I get the following error:

While not exactly the same as the lesson 2 notebooks, there is a lot of similarities:

def get_y_fn(x): return x.parent.parent / ('labels/' + x.name)

codes = ['background', 'foreground']

src = (SegmentationItemList.from_folder(path)
.split_by_rand_pct(valid_pct=0.1)
.label_from_func(get_y_fn, classes=codes))

data = (src.transform(get_transforms(), tfm_y=True)
.databunch(bs=bs)
.normalize(imagenet_stats))

learn = unet_learner(data, models.resnet34, wd=1e-2, bottle=True)

lr=3e-5

learn.fit_one_cycle(10, slice(lr), pct_start=0.9)

learn.unfreeze()

lrs = slice(lr/400,lr/4)

learn.fit_one_cycle(12, lrs, pct_start=0.8)

learn.export()

I have used a fast.ai installation on my local machine and run the same code via Salamander and both return the same error. Any advice would be fantastic.

2 Likes