Forward() got an unexpected keyword argument 'pretrained'

I think that cnn_learner expects a function to construct a model and not a model architecture. If you want to change the model you need to build a function, to construct that changed model. This approach worked for me:

def get_model(model, pretrained=False, progress=True, **kwargs):
    """model: function to load the model, e.g. resnet18
        pretrained, progress: to be passed to the model function
    """
    m = model(pretrained=pretrained, progress=progress, **kwargs) # loads standard model
    m.avgpool = nn.AdaptiveAvgPool2d(output_size=(100,100)) # changes one layer
    return m

You can then pass this to the learner.

learn = cnn_learner(dls, partial(get_model, model=resnet18))

3 Likes