当前位置:网站首页>Pytoch freeze pre training weights (feature extraction and BN layer)
Pytoch freeze pre training weights (feature extraction and BN layer)
2022-06-13 01:45:00 【No change of name】
1. Read the pre training weight
pre_weights = torch.load(model_weights_path, map_location=device)
2. Read the weights of the same layer as the existing model parameter settings in the pre training weights , It can be used when the classification or the number of channels in some layers is modified
net = yourmodel()
pre_dict = {k: v for k, v in pre_weights.items()
if net.state_dict()[k].numel() == v.numel()}
# strict = False Indicates that only the matching weights are read
missing_keys, unexpected_keys = net.load_state_dict(pre_dict, strict = False)3. Freeze the pre training weight of feature extraction layer
for params in net.features.parameters():
params.requires_grad = False4. because BN Layer parameters are calculated from the values of each channel , stay forward In the automatic implementation of , Instead of updating through gradient calculation and back propagation , Additional freezing required BN Layer weight
def freeze_bn(ly):
classname = ly.__class__.__name__
if classname.find('BatchNorm') != -1:
ly.eval()
net.apply(freeze_bn)5. Related links
1. pytorch Medium BN Layer Introduction _lpj822 The column -CSDN Blog
2. model.load_state_dict(state_dict, strict=False)_t20134297 The blog of -CSDN Blog
边栏推荐
- 兴趣相似的受众群体
- Leetcode question 20
- Introduction to common ROS commands
- Delphi implements adding a column of serial number to the CXGRID list
- [从零开始学习FPGA编程-21]:进阶篇 - 架构 - VerilogHDL编码规范
- How do you use your own data to achieve your marketing goals?
- 5、 Improvement of inventory query function
- Delphi Google API text to speech MP3 file
- Workspace for ROS
- About inquirerjs
猜你喜欢

Devexpress implementation flow chart

指针链表的实现

Large end storage and small end storage

Explanation and application of prefix sum (one-dimensional, two-dimensional)

Design of distributed game server

(no plug-in) summary of vim basic shortcut keys

URI, URL and urn difference, relation and syntax diagram

3、 Upload fabric photos to SQL server and provide name to display fabric photos

Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)

Use koa to mock data and set cross domain issues
随机推荐
深度学习调参技巧详解
Service creation and operation example of ROS
Delphi Google API text to speech MP3 file
Anims of phaser3
Implementation of pointer linked list
【MathType】利用MathType输出LaTex样式的公式
谷歌的受众群体是如何发挥作用的?
How to solve the problems when using TV focusable to package APK in uni app
Machine learning basic SVM (support vector machine)
Delphi 10.4.2 release instructions and installation methods of three patches
服务器安装jupyterlab以及远程登录配置
Developer contributions amd Xilinx Chinese Forum sharing - wisdom of questioning
Unity jsonutility failed to serialize list
The second round of mesa
MySQL ---- where后使用字段别名
Stone from another mountain: Web3 investment territory of a16z
Stm32 3*3 matrix key (register version)
What is Google plus large text ads? How to use it?
leetcode743. Network latency (medium, Dijkstra)
How many smart bids does Google have?