Lesson3 IMDB - FileNotFoundError when create language model learner

Hi,
I was trying to rewrite IMDB code of Lesson 4 to satisfied updated fastai. But when I tried to create learner by runing this code:

learn = language_model_learner(data_lm, arch=AWD_LSTM, pretrained_fnames=URLs.WT103_1, drop_mult=0.3)

I got a ‘No such file or directory’ error:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-11-53e2b2d8b7cf> in <module>
----> 1 learn = language_model_learner(data_lm, arch=AWD_LSTM, pretrained_fnames=URLs.WT103_1, drop_mult=0.3)

~/.conda/envs/lcyVenv/lib/python3.7/site-packages/fastai/text/learner.py in language_model_learner(data, arch, config, drop_mult, pretrained, pretrained_fnames, **learn_kwargs)
    215     if pretrained_fnames is not None:
    216         fnames = [learn.path/learn.model_dir/f'{fn}.{ext}' for fn,ext in zip(pretrained_fnames, ['pth', 'pkl'])]
--> 217         learn.load_pretrained(*fnames)
    218         learn.freeze()
    219     return learn

~/.conda/envs/lcyVenv/lib/python3.7/site-packages/fastai/text/learner.py in load_pretrained(self, wgts_fname, itos_fname, strict)
     72     def load_pretrained(self, wgts_fname:str, itos_fname:str, strict:bool=True):
     73         "Load a pretrained model and adapts it to the data vocabulary."
---> 74         old_itos = pickle.load(open(itos_fname, 'rb'))
     75         old_stoi = {v:k for k,v in enumerate(old_itos)}
     76         wgts = torch.load(wgts_fname, map_location=lambda storage, loc: storage)

FileNotFoundError: [Errno 2] No such file or directory: '/home/user/.fastai/data/imdb/models/t.pkl'

so I entered my /.fastai/data/imdb/models folder and saw nothing.

Can you please let me know what I am doing wrong? Thanks a lot!

did the download part of the notebook succeed ?

Thanks for response!
yes, I saw the progress bar had done. But weird enough that I found 2 model files (wt103-1 and wt103-1.tgz) in my ~/.fastai/models folder, why these code try to load pretrained model from ~/.fastai/data/imdb/models? so I copy these 2 model files to ~/.fastai/data/imdb/models folder but it seems can’t help.

Finally, I moved itos_wt103.pkl and lstm_wt103.pth from .fastai/data/imdb/models/wt103-1 folder to ~/.fastai/data/imdb/models and renamed as t.pkl and h.pth , then it worked.

2 Likes