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

yipeiwu_com6年前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通过tcp发送xml报文的方法

如下所示: # -*- coding: utf-8 -*- import socket # 使用tcp发送请求报文 def tcpsend(ip, port, xmlbw): ad...

深入了解Python中pop和remove的使用方法

Python关于删除list中的某个元素,一般有两种方法,pop()和remove()。 remove() 函数用于移除列表中某个值的第一个匹配项。 remove()方法语法: list...

浅谈python内置变量-reversed(seq)

1、简单解释就是:反转一个序列对象 例子1: def fun3(): x = [3,6,9] for i in reversed(x): print(i,end=',')...

python结合API实现即时天气信息

python结合API实现即时天气信息

python结合API实现即时天气信息 import urllib.request import urllib.parse import json """ 利用“最美天气”抓取...

在Python 不同级目录之间模块的调用方法

Python的模块有自带的也有第三方,还可以自定义然后引用 1、调用自带的模块,例如,sys 调用自带的模块只需要import sys 引入既可以使用 2、第三方的需要先安装模块然后再i...