Lesson2, part2 FileNotFoundError

I don’t understand why am getting error

FileNotFoundError: [Errno 2] No such file or directory: ‘/home/paperspace/fastai/courses/dl1/fastai/weights/resnext_101_64x4d.pth’

when I do

learn = ConvLearner.pretrained(arch, data, precompute=True)

in dog breed problem

PATH = 'data/dogbreed/'
sz = 224
arch = resnext101_64
bs=58
label_csv = PATH + 'labels.csv'
n = len(list(open(label_csv)))-1
val_idxs = get_cv_idxs(n)
def get_data(sz, bs):
    tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
    data = ImageClassifierData.from_csv(PATH, 'train', label_csv, test_name='test',
                                           val_idxs=val_idxs, suffix='.jpg', tfms=tfms, bs=bs)
    return data if sz > 300 else data.resize(340)
data = get_data(sz, bs)
learn = ConvLearner.pretrained(arch, data, precompute=True)

The full exception looks like this

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-20-bfd96ca26d21> in <module>()
----> 1 learn = ConvLearner.pretrained(arch, data, precompute=True)

~/fastai/courses/dl1/fastai/conv_learner.py in pretrained(cls, f, data, ps, xtra_fc, xtra_cut, custom_head, precompute, pretrained, **kwargs)
    111                    pretrained=True, **kwargs):
    112         models = ConvnetBuilder(f, data.c, data.is_multi, data.is_reg,
--> 113             ps=ps, xtra_fc=xtra_fc, xtra_cut=xtra_cut, custom_head=custom_head, pretrained=pretrained)
    114         return cls(data, models, precompute, **kwargs)
    115 

~/fastai/courses/dl1/fastai/conv_learner.py in __init__(self, f, c, is_multi, is_reg, ps, xtra_fc, xtra_cut, custom_head, pretrained)
     38         else: cut,self.lr_cut = 0,0
     39         cut-=xtra_cut
---> 40         layers = cut_model(f(pretrained), cut)
     41         self.nf = model_features[f] if f in model_features else (num_features(layers)*2)
     42         if not custom_head: layers += [AdaptiveConcatPool2d(), Flatten()]

~/fastai/courses/dl1/fastai/torch_imports.py in resnext101_64(pre)
     62 @_fastai_model('ResNeXt 101_64', 'Aggregated Residual Transformations for Deep Neural Networks',
     63                'https://arxiv.org/abs/1611.05431')
---> 64 def resnext101_64(pre): return load_pre(pre, resnext_101_64x4d, 'resnext_101_64x4d')
     65 
     66 @_fastai_model('Wide Residual Networks', 'Wide Residual Networks',

~/fastai/courses/dl1/fastai/torch_imports.py in load_pre(pre, f, fn)
     30     m = f()
     31     path = os.path.dirname(__file__)
---> 32     if pre: load_model(m, f'{path}/weights/{fn}.pth')
     33     return m
     34 

~/fastai/courses/dl1/fastai/torch_imports.py in load_model(m, p)
     25 def children(m): return m if isinstance(m, (list, tuple)) else list(m.children())
     26 def save_model(m, p): torch.save(m.state_dict(), p)
---> 27 def load_model(m, p): m.load_state_dict(torch.load(p, map_location=lambda storage, loc: storage))
     28 
     29 def load_pre(pre, f, fn):

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module)
    257             (sys.version_info[0] == 3 and isinstance(f, pathlib.Path)):
    258         new_fd = True
--> 259         f = open(f, 'rb')
    260     try:
    261         return _load(f, map_location, pickle_module)

FileNotFoundError: [Errno 2] No such file or directory: '/home/paperspace/fastai/courses/dl1/fastai/weights/resnext_101_64x4d.pth'

Thank you for any advice.

the same error I see with lesson1-rxt50

I too get the same exception.

1 Like

Nobody else has this issue?

You have to download the weights beforehand!

check these instructions: link