阅读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'
答案 0 :(得分:0)
您需要使用“ models.vgg16_bn”而不是“ models.vgg16”,这将起作用。
cnn_learner(data, models.vgg16_bn, metrics =accuracy)
有关更多信息,请参见documentation。