Hi, so I am trying to load a pickled (.pkl
) learner in my Kaggle inference kernel that was created using learner.export()
function. When I tried loading using load_learner()
I encountered the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_75/4239519382.py in <module>
----> 1 learn = load_learner("../input/cassava-classification-training/cassava-v1.pkl")
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in load_learner(fname, cpu, pickle_module)
384 "Load a `Learner` object in `fname`, optionally putting it on the `cpu`"
385 distrib_barrier()
--> 386 try: res = torch.load(fname, map_location='cpu' if cpu else None, pickle_module=pickle_module)
387 except AttributeError as e:
388 e.args = [f"Custom classes or functions exported with your `Learner` are not available in the namespace currently.\nPlease re-declare or import them before calling `load_learner`:\n\t{e.args[0]}"]
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
605 opened_file.seek(orig_position)
606 return torch.jit.load(opened_file)
--> 607 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
608 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
609
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
880 unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
881 unpickler.persistent_load = persistent_load
--> 882 result = unpickler.load()
883
884 torch._utils._validate_loaded_sparse_tensors()
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in find_class(self, mod_name, name)
873 def find_class(self, mod_name, name):
874 mod_name = load_module_mapping.get(mod_name, mod_name)
--> 875 return super().find_class(mod_name, name)
876
877 # Load the data (which may in turn use `persistent_load` to load tensors)
AttributeError: Custom classes or functions exported with your `Learner` are not available in the namespace currently.
Please re-declare or import them before calling `load_learner`:
Can't get attribute 'AlbumentationsTransform' on <module '__main__'>
I have made sure to import all modules that I used in my training kernel, so I am not sure what to do. Thank you in advance for your kind assistance.