PyTorch固定参数
2024-10-07 14:02:10
In situation of finetuning, parameters in backbone network need to be frozen. To achieve this target, there are two steps.
First, locate the layers and change their requires_grad attributes to be False.
for param in net.backbone.parameters():
param.requires_grad = False
for pname, param in net.named_parameters():
if(key_word in pname):
param.requires_grad = False
Here we use parameters() or named_parameters() method, it will give both bias and weight.
Second, filter out those parameters who need to be updated and pass them to the optimizer.
optimizer = torch.optim.SGD(filter(lambda p: p.requires_grad == True, net.parameters()), lr=learning_rate, momentum=mom)
最新文章
- CoffeeScript实现Python装潢器
- myString操作符重载
- ZOJ3774_Power of Fibonacci
- 一直都在说反射很有用 谈谈大型.NET ERP系统有哪些地方用到了反射
- Android中Service 使用详解(LocalService + RemoteService)
- JQuery-属性
- [原创]android使用代码生成LayerDrawable的方法和注意事项
- 无意中在sql日志中发现如下内容,
- head标签掉到body里的问题
- C++ 操作法重载
- textarea限制字符数
- 构建高性能WEB站点笔记三
- UNIX基础--Manual Pages
- if else 和switch case以及continue,break的区别
- multiset基础学习,可以有重复类型的多重集合容器
- html 微信video放大后无法返回问题
- kubernetes之管理容器的计算资源
- CF_#478_Div.2_Hag's Khashba
- kali在vbox上运行设置共享文件夹
- TCP建立与断开连接、socket通讯模板
热门文章
- 十八:使用JDBC进行批处理
- 一个double free相关问题的澄清
- 百闻不如一试——公式图片转Latex代码
- PS-头发丝抠图
- ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)
- RabbitMQ从零到集群高可用(.NetCore5.0) -高可用集群构建落地
- Spring(二)——IOC
- Echarts中Option属性设置
- Python中正则表达式简介
- HCNP Routing&;Switching之IS-IS报文结构和类型