当前位置:网站首页>Pytorch through load_ state_ Dict load weight
Pytorch through load_ state_ Dict load weight
2022-07-03 05:17:00 【Qianyu QY】
1、 If the pre training network is exactly the same as the current network
net = model(input_channels=input_channels, angle_cls=args.angle_bins)
# Load pre training model
pretrained_dict = torch.load(" Pre training weight path ")
net.load_state_dict(pretrained_dict)
2、 If the names of some network layers in the pre training network and the current network are different
Such as , There is a layer of convolution in the pre training network, which is defined as follows :
self.point_output = nn.Conv2d(input, output, kernel_size, ...)
But the current network has removed this layer . Load weights in the following ways
net = model(input_channels=input_channels, angle_cls=args.angle_bins)
# Load pre training model
pretrained_dict = torch.load(" Pre training weight path ")
model_dict = net.state_dict()
state_dict = {
k:v for k,v in pretrained_dict.items() if k in sgdn_dict.keys()}
model_dict .update(state_dict)
net.load_state_dict(model_dict)
3、 If the name of some network layers in the pre training network and the current network are the same , But the shape is different
For example, there is a network , Pre training with 4 The tunnel RGBD Image as input ; Now when training , Take the depth map of single channel as input , That is, the weight size of the first layer is different . Load weights in the following ways
net = model(input_channels=input_channels, angle_cls=args.angle_bins)
# Load pre training model
pretrained_dict = torch.load(" Pre training weight path ")
model_dict = net.state_dict()
state_dict = {
k:v for k,v in pretrained_dict.items() if k in sgdn_dict.keys() and v.shape == model_dict [k].shape}
model_dict .update(state_dict)
net.load_state_dict(model_dict)
边栏推荐
- 1086 tree traversals again (25 points)
- Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
- 穀歌 | 蛋白序列的深度嵌入和比對
- Progressive multi grasp detection using grasp path for rgbd images
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- 1099 build a binary search tree (30 points)
- Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
- [research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
- Skip table: principle introduction, advantages and disadvantages of skiplist
- Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
猜你喜欢
"Hands on deep learning" pytorch edition Chapter II exercise
[research materials] 2021 China's game industry brand report - Download attached
How to connect the network: Chapter 1 CSDN creation punch in
appium1.22.x 版本后的 appium inspector 需单独安装
Intégration profonde et alignement des séquences de protéines Google
leetcode435. Non overlapping interval
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Actual combat 8051 drives 8-bit nixie tube
Three representations of signed numbers: original code, inverse code and complement code
appium1.22. Appium inspector after X version needs to be installed separately
随机推荐
1118 birds in forest (25 points)
"Pthread.h" not found problem encountered in compiling GCC
Why is go language particularly popular in China
[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
Technical analysis of qianyuantong multi card aggregation router
Webapidom get page elements
Burp suite plug-in based on actual combat uses tips
ES7 easy mistakes in index creation
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
Go practice - gorilla / handlers used by gorilla web Toolkit
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
Problems encountered in fuzzy query of SQL statements
JS string and array methods
Deep embedding and alignment of Google | protein sequences
My first Smartphone
Class loading mechanism (detailed explanation of the whole process)
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Promise