简体   繁体   中英

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM