Ayushman Koul
Ayushman Koul

Reputation: 5

Not able to use pretrained VGG16 model in Fastai

I am using following code to call vgg16 pretrained model in fastai after reading documentation in Pytorch Vision Model

import fastai
from fastai.vision import *
from fastai.callbacks import *
learn6= cnn_learner(data, models.vgg16, metrics =[accuracy])
from fastai.callbacks import *
EarlySC = EarlyStoppingCallback(learn=learn6, monitor='accuracy', min_delta=0.01, patience=20)
reduceLR = ReduceLROnPlateauCallback(learn=learn6, monitor = 'accuracy', patience = 20, factor = 0.2, min_delta = 0)
learn6.fit(100,0.001,callbacks=[reduceLR,EarlySC])
learn6.save('vgg16')

But it throws following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-38-e9aca7dabc9d> in <module>()
      5 from fastai.callbacks import *
      6 #model = torch.hub.load('pytorch/vision:v0.5.0', 'vgg16', pretrained=True)
----> 7 learn6= cnn_learner(data, models.vgg16, metrics =[accuracy])
      8 from fastai.callbacks import *
      9 EarlySC = EarlyStoppingCallback(learn=learn6, monitor='accuracy', min_delta=0.01, patience=20)

AttributeError: module 'fastai.vision.models' has no attribute 'vgg16'

Upvotes: 0

Views: 1191

Answers (1)

Harsh Panwar
Harsh Panwar

Reputation: 355

You need to use "models.vgg16_bn" instead of "models.vgg16" and it will work.

cnn_learner(data, models.vgg16_bn, metrics =accuracy)

See documentation for more.

Upvotes: 1

Related Questions