【问题标题】:Not able to use pretrained VGG16 model in Fastai无法在 Fastai 中使用预训练的 VGG16 模型
【发布时间】:2020-08-25 07:11:07
【问题描述】:

阅读Pytorch Vision Model中的文档后,我正在使用以下代码在fastai中调用vgg16预训练模型

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')

但它会引发以下错误:

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'

【问题讨论】:

    标签: python deep-learning fast-ai


    【解决方案1】:

    您需要使用“models.vgg16_bn”而不是“models.vgg16”,它会起作用。

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

    请参阅documentation 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 2020-06-13
      • 2018-03-05
      • 2021-07-09
      • 1970-01-01
      • 2017-08-19
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多