code-of-learn-deep-learning-with-pytorch icon indicating copy to clipboard operation
code-of-learn-deep-learning-with-pytorch copied to clipboard

麻烦写一下kaggle cat dog的注释以及代码的运行顺序,谢谢了

Open gittigxuy opened this issue 6 years ago • 7 comments

gittigxuy avatar Mar 06 '18 08:03 gittigxuy

好的,我会加到这一版的书中,这两天会写一个新的repo出来

L1aoXingyu avatar Mar 06 '18 09:03 L1aoXingyu

这段是猫狗大战当中的net.py文件当中的代码片段 if model == 'vgg': vgg = models.vgg19(pretrained=True) self.feature = nn.Sequential(*list(vgg.children())[:-1]) self.feature.add_module('global average', nn.AvgPool2d(9)) elif model == 'inceptionv3': inception = models.inception_v3(pretrained=True) self.feature = nn.Sequential(*list(inception.children())[:-1]) self.feature._modules.pop('13') self.feature.add_module('global average', nn.AvgPool2d(35)) elif model == 'resnet152': resnet = models.resnet152(pretrained=True) self.feature = nn.Sequential(*list(resnet.children())[:-1])

有如下2个问题: 1)nn.Sequential(list(vgg.children())[:-1]),list前面的代表什么意思呢? 2)为什么vgg当中最后面加入了平均池化,而inceptionv3前面还要加上self.feature._modules.pop('13') 这个pop('13')是什么意思呢?resnet152为什么不加上池化了呢? 谢谢作者

gittigxuy avatar Mar 06 '18 13:03 gittigxuy

我会把预训练的模型放到百度云上

L1aoXingyu avatar Mar 07 '18 04:03 L1aoXingyu

https://pan.baidu.com/s/1xBK8gFWfHcFrHu0LIcZP8Q 这是 resnet18 的模型下载百度云地址

L1aoXingyu avatar Mar 08 '18 05:03 L1aoXingyu

下载完成之后放在 .torch/models 里面

L1aoXingyu avatar Mar 08 '18 05:03 L1aoXingyu

同样的问题: 为什么vgg当中最后面加入了平均池化,而inceptionv3前面还要加上self.feature._modules.pop('13') 这个pop('13')是什么意思呢?resnet152为什么不加上池化了呢?

fengshi-cherish avatar Aug 14 '19 04:08 fengshi-cherish

@fengshi-cherish inceptionv3 里面有一个额外的中间分类loss image 这个loss对应于下面 image 所以要删掉13个模块,vgg是因为没有平均池化,所以加入,resnet有了平均池化,所以不需要加入

L1aoXingyu avatar Aug 14 '19 05:08 L1aoXingyu