简体   繁体   English

无法在 Fastai 中使用预训练的 VGG16 model

[英]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在阅读Pytorch Vision Model 中的文档后,我正在使用以下代码在 fastai 中调用 vgg16 预训练 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.您需要使用“models.vgg16_bn”而不是“models.vgg16”,它会起作用。

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

See documentation for more.有关更多信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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