Pytorch中的VGG实现修改最后一层FC

yipeiwu_com5年前Python基础

https://discuss.pytorch.org/t/how-to-modify-the-final-fc-layer-based-on-the-torch-model/766/12

That's because vgg19 doesn't have a fc member variable. Instead, it has a

 (classifier): Sequential (
 (0): Dropout (p = 0.5)
 (1): Linear (25088 -> 4096)
 (2): ReLU (inplace)
 (3): Dropout (p = 0.5)
 (4): Linear (4096 -> 4096)
 (5): ReLU (inplace)
 (6): Linear (4096 -> 100)
 )

To replace the last linear layer, a temporary solution would be

vgg19.classifier._modules['6'] = nn.Linear(4096, 8)

以上这篇Pytorch中的VGG实现修改最后一层FC就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python实现数值积分方式

Python实现数值积分方式

原理: 利用复化梯形公式,复化Simpson公式,计算积分。 步骤: import math """测试函数""" def f(x,i): if i == 1: re...

Django model select的多种用法详解

Django model select的多种用法详解

《Django model update的各种用法介绍》文章介绍了Django model的各种update操作,这篇文章就是她的姊妹篇,详细介绍Django model select的...

python实现H2O中的随机森林算法介绍及其项目实战

python实现H2O中的随机森林算法介绍及其项目实战

H2O中的随机森林算法介绍及其项目实战(python实现) 包的引入:from h2o.estimators.random_forest import H2ORandomForestEs...

Python实现在线暴力破解邮箱账号密码功能示例【测试可用】

本文实例讲述了Python实现在线暴力破解邮箱账号密码功能。分享给大家供大家参考,具体如下: dic 字典格式如下(mail.txt) : username@gmail.com:pa...

python2 与 pyhton3的输入语句写法小结

什么是输入 咱们在银行ATM机器前取钱时,肯定需要输入密码,对不? 那么怎样才能让程序知道咱们刚刚输入的是什么呢?? 大家应该知道了,如果要完成ATM机取钱这件事情,需要先从键盘中输入一...