I am getting an unusual error when I try to export a learner.
Code to make learner and data:
data = (PointsItemList.from_df(df, path='./', cols='image')
.split_by_valid_func(is_validation)
.label_from_func(get_coords)
.transform(tfms, tfm_y=True, size=300, padding_mode='reflection', remove_out=False)
.databunch(bs=32)
.normalize(imagenet_stats)
)
learner = cnn_learner(
data,
models.resnet18,
pretrained=False
)
After the model has been trained, I run:
learner.save('stage1',return_path=True)
learner.load('stage1')
Which works fine. Then I run:
learner.export('model.pkl')
This is the error I get:
AttributeError Traceback (most recent call last)
[<ipython-input-15-de10b3ec63b2>](https://z5ru7z1tl8o-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20200422-085601-RC00_307797972#) in <module>() ----> 1 learner.export('model.pkl')
3 frames
[/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py](https://z5ru7z1tl8o-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20200422-085601-RC00_307797972#) in export(self, file, destroy) 241 state['data'] = self.data.valid_ds.get_state(**xtra) 242 state['cls'] = self.__class__ --> 243 try_save(state, self.path, file) 244 if destroy: self.destroy() 245
[/usr/local/lib/python3.6/dist-packages/fastai/torch_core.py](https://z5ru7z1tl8o-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20200422-085601-RC00_307797972#) in try_save(state, path, file) 414 #To avoid the warning that come from PyTorch about model not being checked 415 warnings.simplefilter("ignore") --> 416 torch.save(state, target) 417 except OSError as e: 418 raise Exception(f"{e}\n Can't write {path/file}. Pass an absolute writable pathlib obj `fname`.")
[/usr/local/lib/python3.6/dist-packages/torch/serialization.py](https://z5ru7z1tl8o-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20200422-085601-RC00_307797972#) in save(obj, f, pickle_module, pickle_protocol, _use_new_zipfile_serialization) 326 327 with _open_file_like(f, 'wb') as opened_file: --> 328 _legacy_save(obj, opened_file, pickle_module, pickle_protocol) 329 330
[/usr/local/lib/python3.6/dist-packages/torch/serialization.py](https://z5ru7z1tl8o-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20200422-085601-RC00_307797972#) in _legacy_save(obj, f, pickle_module, pickle_protocol) 399 pickler = pickle_module.Pickler(f, protocol=pickle_protocol) 400 pickler.persistent_id = persistent_id --> 401 pickler.dump(obj) 402 403 serialized_storage_keys = sorted(serialized_storages.keys())
AttributeError: Can't pickle local object 'TorchHistory.add_log_hooks_to_pytorch_module.<locals>.<lambda>'