ahoarfrost / fastBio

Deep learning library for biological sequences. Extension of Fastai and Pytorch.
MIT License
40 stars 6 forks source link

AttributeError: 'LSTM' object has no attribute '_flat_weights' #4

Open Tobulo opened 3 weeks ago

Tobulo commented 3 weeks ago

Hey, I am trying to follow the tutorial on my PC (with GPU) and I have encountered this error below when I try to load the trained models (as described at the end of the tutorial):

from fastai.text import load_learner oxido = load_learner(Path('./models').resolve(), 'OxidoreductaseClassifier_export.pkl') Traceback (most recent call last): File "", line 1, in File "/home/novo01/anaconda3/envs/myenv/lib/python3.9/site-packages/fastai/basic_train.py", line 598, in load_learner state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source) File "/home/novo01/anaconda3/envs/myenv/lib/python3.9/site-packages/torch/serialization.py", line 1040, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "/home/novo01/anaconda3/envs/myenv/lib/python3.9/site-packages/torch/serialization.py", line 1272, in _legacy_load result = unpickler.load() File "/home/novo01/anaconda3/envs/myenv/lib/python3.9/site-packages/torch/nn/modules/rnn.py", line 353, in setstate for w in self._flat_weights] File "/home/novo01/anaconda3/envs/myenv/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1709, in getattr raise AttributeError(f"'{type(self).name}' object has no attribute '{name}'") AttributeError: 'LSTM' object has no attribute '_flat_weights'

error

I am using conda env with python3.9, numpy-1.23.0 and pandas-1.3.5, the fastai-1.0.52 as default. I new to the machine learning and have little background of programming, would you please help me understand the issue and what should I do to correct the error?

P.S. after checking with the requirements, I found that only torch and torchvision have different version, but I tried to install older version of torch on my PC, it seems not compatible with the system. Is the error related to this?

torch torch_1

Thank you very much!

Best, Toby

Tobulo commented 3 weeks ago

okay, so I created another env with python3.6, and now I can install correct version of torch, and is seems to be working now!