当前位置:网站首页>Transfer learning to freeze the network:
Transfer learning to freeze the network:
2022-08-01 11:05:00 【Wsyoneself】
Description: pytorch (1-3), TensorFlow (4)
fine tune is to freeze the front layers of the network, and then train the last layer
- Pass all parameters to the optimizer, but set the
requires_grad
of the parameters of the layer to be frozen toFalse:
optimizer = optim.SGD(model.parameters(), lr=1e-2) # All parameters are passed infor name, param in model.named_parameters():if the name of the network layer to be frozen (that is, the value of name):param.requires_grad = False
- The optimizer passes in the parameters of the unfrozen network layer:
optimizer = optim.SGD(model.name.parameters() of the unfrozen network layer, lr=1e-2) # The optimizer only passes in the parameters of fc2
- The best practice is: the optimizer only passes in the parameter of requires_grad=True, the memory occupied will be smaller, and the efficiency will be higher.Code and Combining 1 and 2
Save video memory: do not pass parameters that will not be updated to
optimizer
Increase the speed: set the
requires_grad
of the parameters that are not updated toFalse
, saving the time to calculate the gradient of these parameters
- The code is as follows:
#Define optimization operatoroptimizer = tf.train.AdamOptimizer(1e-3)#Select the parameters to be optimizedoutput_vars = tf.get_collection(tf.GraphKyes.TRAINABLE_VARIABLES, scope= 'outpt')train_step = optimizer.minimize(loss_score,var_list = output_vars)
Put the layer that needs to update the gradient in the tf.get_collection function, and do not put it in if it does not need to be updated.- The main function of the function: from a collectionretrieve variable
- is used to get all the elements in the key collection and return a list.The order of the list is based on the order in which the variables were placed in the set.scope is an optional parameter, indicating the namespace (namedomain), if specified, it will return a list of all variables put into 'key' in the name domain (for example, the outpt description in the sample code is the parameter to return the outpt layer), if not specified, it will return all variables.
边栏推荐
- 如何解决 chrome 浏览器标签过多无法查看到标题的情况
- 各位大拿,安装Solaris 11.4操作系统,在安装数据库依赖包的时候包这个错,目前无原厂支持,也无安装盘,联网下载后报这个错,请教怎么解决?
- EasyRecovery热门免费数据检测修复软件
- Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
- 小程序毕设作品之微信美食菜谱小程序毕业设计成品(4)开题报告
- CTFshow,命令执行:web32
- Golang内存分析工具gctrace和pprof实战
- Mysql index related knowledge review one
- Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (2) Mini Program Functions
- 数字化转型实践:世界级2B数字化营销的方法框架
猜你喜欢
判断JS数据类型的四种方法
STM32 Personal Notes - Watchdog
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
新一代超安全蜂窝电池, 思皓爱跑上市13.99万元起售
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
xss-labs靶场挑战
Promise learning (2) An article takes you to quickly understand the common APIs in Promise
石头科技打造硬核品牌力 持续出海拓展全球市场
Stone Technology builds hard-core brand power and continues to expand the global market
小程序毕设作品之微信美食菜谱小程序毕业设计成品(2)小程序功能
随机推荐
机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
Ts-Map 类的使用
深度学习 | MATLAB实现一维卷积神经网络convolution1dLayer参数设定
For small applications, which database is better to use?
大众碰到点评的一个字体反爬,落地技术也是绝了
Mysql index related knowledge review one
一文说明白ECDSA spec256k1 spec256r1 EdDSA ed25519千丝万缕的关系
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
How to find out hidden computer software (how to clean up the computer software hidden)
Online - GCeasy GC log analysis tools
gc的意义和触发条件
.NET analyzes the LINQ framework in depth (three: the elegant prelude of LINQ)
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
(ES6以上以及TS) Map对象转数组
跨域网络资源文件下载
RK3399 platform development series on introduction to (kernel) 1.52, printk function analysis - the function call will be closed
slice、splice、split傻傻分不清
回归预测 | MATLAB实现RNN循环神经网络多输入单输出数据预测
Hot review last week (7.25 7.31)
Jenkins安装插件遇到的问题