To minimise code, I want to use load_learner(), instead of creating a new learner
every time.
with open()
works, but leaves me with setting up the large amount of learner code.
I get thrown this error on load_learner()
ModuleNotFoundError: No module named '__builtin__'
Supposedly, __builtins__
was renamed to builtins
in Python 3.
Source 1
Source 2
Versions
torch==1.7.1
fastai==2.7.7
fastcore==1.5.6
torch==1.7.1
torchvision==0.8.2
predict.py
if __name__ == '__main__':
file_path = project_params.file_path
learner = project_params.learner
model = load_learner(file_path.model, cpu=learner.cpu) # !
(venv) me@ubuntu-pcs:~/PycharmProjects/project$ python project_model/predict.py
'pdl1_lung_model/data/histology_tiles.dvc' didn't change, skipping
Running stage 'predict':
> python pdl1_lung_model/predict.py
/home/me/miniconda3/envs/venv/lib/python3.9/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0
Traceback (most recent call last):
File "/home/me/PycharmProjects/project/pdl1_lung_model/predict.py", line 35, in <module>
model = load_learner(file_path.model, cpu=learner.cpu)
File "/home/me/miniconda3/envs/venv/lib/python3.9/site-packages/fastai/learner.py", line 414, in load_learner
try: res = torch.load(fname, map_location=map_loc, pickle_module=pickle_module)
File "/home/me/miniconda3/envs/venv/lib/python3.9/site-packages/torch/serialization.py", line 595, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/home/me/miniconda3/envs/venv/lib/python3.9/site-packages/torch/serialization.py", line 764, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
ModuleNotFoundError: No module named '__builtin__'
ERROR: failed to reproduce 'predict': failed to run: python pdl1_lung_model/predict.py, exited with 1
params.yaml
learner:
cpu: False
# ...
file_path:
model: ./project_model/data/learner.pkl