Using Cadene pretrainedmodels library

I’m trying to determine the best way to create fastai learners from Cadene pretrained models. I’m able to get some of the models to work, but not others, and I’m not sure why this is the case. For example, resnet18 seems to work, but alexnet or vgg_16 do not. I think it has something to do with models that don’t allow variable input size not working, but I’m not sure.

import pretrainedmodels

data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(),
                                   size=224, bs=64).normalize(imagenet_stats)

model = pretrainedmodels.__dict__['resnet18'](pretrained=None)

learn = create_cnn(data, lambda x: model, metrics=error_rate)

As an example, would someone please explain to me how I would create a learner from pretrainedmodels alexnet?

I don’t have use for and would actually prefer to not use variable input size and adaptive pooling if it’s possible to create it without.

The notebook below should have everything you need to use the Cadene model library. It provides a bunch of great examples of importing models from other libraries as well, along with the methods of getting them to work for your own custom data set:

This forum post has some good discussion around the notebook too: