当前位置:网站首页>paddlepaddle 19 动态修改模型的最后一层
paddlepaddle 19 动态修改模型的最后一层
2022-06-27 01:58:00 【万里鹏程转瞬至】
在进行迁移学习时,通常需要修改模型的最后一层,按照需求重新进行定义。但是,迁移学习需要在众多的模型中进行对比实验,而定义最后一个layer时,需要知道layer的name,和layer输入数据的shape,也就是需要对model的layer进行遍历。
1、遍历model
通过以下代码可以遍历model
import paddle
#print('飞桨框架内置模型:', paddle.vision.models.__all__)
model=paddle.vision.resnet18()
layer_list=[(name,atom_layer) for name,atom_layer in model.named_sublayers()]
#print(model)
feature_layer_name,feature_layer=layer_list[-1]
feature_layer_shape=feature_layer.weight.shape
feature_layer_type=feature_layer.__class__
print("feature layer:",feature_layer_name,feature_layer_shape,feature_layer_type)代码执行输出如下所示:
feature layer: fc [512, 1000] <class 'paddle.nn.layer.common.Linear'>
2、动态修改模型的最后一层
动态修改模型的最后一层,支持语义分割模型和图像分类模型。但是需要注意的是,模型的最后一层必须是layer对象(如resnet系列,densenet系列,mobilenet系
边栏推荐
猜你喜欢

svg拖拽装扮Kitty猫

Binary tree OJ problem

Due to the invalidation of the prospectus of bori technology, CICC has stopped providing guidance to it and abandoned the listing on the Hong Kong stock exchange?

Browser cache

“所有专业都在劝退”,对大学生最友好的竟然是它?

Installing the Damon database using the command line

Flink学习4:flink技术栈

Canvas particles: mouse following JS effect

我靠副业一个月挣了3W块:你看不起的行业,真的很挣钱!

SQLite Reader 插件测试SQLite语法
随机推荐
I encountered some problems when connecting to the database. How can I solve them?
SQLite reader plug-in tests SQLite syntax
速看!2022年6月编程语言排行榜出炉!第一名太牛啦
Oracle/PLSQL: VSize Function
Oracle/PLSQL: Translate Function
numpy 数组运算机制浅探
Dameng database installation
Learn the most basic operation of discodiffusion
Oracle/PLSQL: Soundex Function
memcached基础12
Look! In June, 2022, the programming language ranking list was released! The first place is awesome
three. JS domino JS special effect
h5液体动画js特效代码
Precautions for using sneakemake
Reading a book in idea is too much!
"All majors are persuading them to quit." is it actually the most friendly to college students?
Oracle/PLSQL: Upper Function
谷歌开始卷自己,AI架构Pathways加持,推出200亿生成模型
get_ Usage Summary of sequencer
idea 插件开发一些异常处理