当前位置:网站首页>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)
边栏推荐
- Go practice -- gorilla / websocket used by gorilla web Toolkit
- Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
- Redis expiration elimination mechanism
- 1118 birds in forest (25 points)
- leetcode860. Lemonade change
- Go practice -- closures in golang (anonymous functions, closures)
- 微服务常见面试题
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
猜你喜欢

Celebrate the new year together

ES7 easy mistakes in index creation

leetcode860. Lemonade change

Principles of BTC cryptography

Three representations of signed numbers: original code, inverse code and complement code

BIO、NIO、AIO区别

Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
![[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)](/img/c2/87358af6b2b2892a6eceb751b3b60c.jpg)
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)

XML配置文件

【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
随机推荐
Making coco datasets
1099 build a binary search tree (30 points)
JS dynamic table creation
请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
[basic grammar] Snake game written in C language
Introduction to redis and explanation of data types
1114 family property (25 points)
(完美解决)matplotlib图例(legend)如何自由设置其位置
Go practice - gorilla / handlers used by gorilla web Toolkit
Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
Interview question -- output the same characters in two character arrays
【实战项目】自主web服务器
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
50 practical applications of R language (36) - data visualization from basic to advanced
JS function algorithm interview case
Intégration profonde et alignement des séquences de protéines Google
谷歌 | 蛋白序列的深度嵌入和比对