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)

最新文章

  1. CoffeeScript实现Python装潢器
  2. myString操作符重载
  3. ZOJ3774_Power of Fibonacci
  4. 一直都在说反射很有用 谈谈大型.NET ERP系统有哪些地方用到了反射
  5. Android中Service 使用详解(LocalService + RemoteService)
  6. JQuery-属性
  7. [原创]android使用代码生成LayerDrawable的方法和注意事项
  8. 无意中在sql日志中发现如下内容,
  9. head标签掉到body里的问题
  10. C++ 操作法重载
  11. textarea限制字符数
  12. 构建高性能WEB站点笔记三
  13. UNIX基础--Manual Pages
  14. if else 和switch case以及continue,break的区别
  15. multiset基础学习,可以有重复类型的多重集合容器
  16. html 微信video放大后无法返回问题
  17. kubernetes之管理容器的计算资源
  18. CF_#478_Div.2_Hag's Khashba
  19. kali在vbox上运行设置共享文件夹
  20. TCP建立与断开连接、socket通讯模板

热门文章

  1. 十八:使用JDBC进行批处理
  2. 一个double free相关问题的澄清
  3. 百闻不如一试——公式图片转Latex代码
  4. PS-头发丝抠图
  5. ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)
  6. RabbitMQ从零到集群高可用(.NetCore5.0) -高可用集群构建落地
  7. Spring(二)——IOC
  8. Echarts中Option属性设置
  9. Python中正则表达式简介
  10. HCNP Routing&Switching之IS-IS报文结构和类型