Loading a "resnext50_32x4d"

I am trying to load a trained FastAIv0.7 resnext50_32x4d model. Same way I can load other simpler models that I have trained.

Does anyone know what is this error about?

  File "/fastai/old/fastai/learner.py", line 105, in load
    load_model(self.model, self.get_model_path(name))
  File "/fastai/old/fastai/torch_imports.py", line 40, in load_model
    m.load_state_dict(sd)
  File "/root/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages/torch/nn/modules/module.py", line 522, in load_state_dict
    .format(name))
KeyError: 'unexpected key "4.0.0.0.0.0.weight" in state_dict

The solution is that I was not using the right arch = resnext50.

Here is how you do it.


!pip install pretrainedmodels
from fastai.vision import *
import pretrainedmodels
from fastai.callbacks import SaveModelCallback

path = untar_data(URLs.PETS)
path_anno = path/'annotations'
path_img = path/'images'
fnames = get_image_files(path_img)
pat = r'/([^/]+)_\d+.jpg$'

data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=32
                                  ).normalize(imagenet_stats)
								  
model =  pretrainedmodels.__dict__["se_resnext50_32x4d"](num_classes=1000,pretrained="imagenet")
model._fc = nn.Linear(1000,2)

learn = Learner(data,model,metrics=['accuracy'],model_dir = '/kaggle/working')

callbacks = SaveModelCallback(learn, every='improvement', monitor='accuracy', name='best_model')

learn.fit_one_cycle(10, slice(1e-2),callbacks = [callbacks])