我一直在学习fastai课程,那里的Jeremy使用过resnet34,所以我尝试了相同的方法,效果很好。但是,当我尝试将vgg16用于我的自定义数据集以及将其提供给ConvLearner时。错误弹出。我是一个纯粹的初学者。
我已经安装了Fastai库,并且当前版本是0.7.0。 我正在GPU服务器上的虚拟环境中运行它。
from torchvision import models
arch=models.vgg16
data=ImageClassifierData.from_paths(path,
tfms=tfms_from_model(arch,sz))
learn=ConvLearner.pretrained(models.vgg16,data,precompute=False)
TypeError Traceback (most recent
call last)
<ipython-input-11-7ca6121fb20f> in <module>
----> 1
learn=ConvLearner.pretrained(models.vgg16,data,precompute=False)
~/anaconda3/envs/img_cap/lib/python3.6/site-packages/fastai/conv_learner.py in pretrained(cls, f, data, ps, xtra_fc, xtra_cut, custom_head, precompute, pretrained, **kwargs)
111 pretrained=True, **kwargs):
112 models = ConvnetBuilder(f, data.c, data.is_multi, data.is_reg,
--> 113 ps=ps, xtra_fc=xtra_fc, xtra_cut=xtra_cut, custom_head=custom_head, pretrained=pretrained)
114 return cls(data, models, precompute, **kwargs)
115
~/anaconda3/envs/img_cap/lib/python3.6/site-packages/fastai/conv_learner.py in __init__(self, f, c, is_multi, is_reg, ps, xtra_fc, xtra_cut, custom_head, pretrained)
39 cut-=xtra_cut
40 layers = cut_model(f(pretrained), cut)
---> 41 self.nf = model_features[f] if f in model_features else (num_features(layers)*2)
42 if not custom_head: layers += [AdaptiveConcatPool2d(), Flatten()]
43 self.top_model = nn.Sequential(*layers)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'