当前位置:网站首页>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)
边栏推荐
- [set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
- Detailed explanation of yolov5 training own data set
- Interview question -- output the same characters in two character arrays
- Go practice -- use redis in golang (redis and go redis / redis)
- JS dynamic table creation
- 请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
- Differences among bio, NiO and AIO
- Go practice - gorilla / handlers used by gorilla web Toolkit
- [batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
- Messy change of mouse style in win system
猜你喜欢

JS scope

Principles of BTC cryptography

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

Overview of basic knowledge of C language

Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)

乾元通多卡聚合路由器的技术解析

Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
![[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached](/img/01/052928e7f20ca671cdc4c30ae55258.jpg)
[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached

Go practice -- design patterns in golang's singleton

大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
随机推荐
How to connect the network: Chapter 1 CSDN creation punch in
2022-02-12 daily clock in: problem fine brush
leetcode435. Non overlapping interval
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
【实战项目】自主web服务器
Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
2022-02-11 daily clock in: problem fine brush
Overview of basic knowledge of C language
Introduction to deep learning (II) -- univariate linear regression
1115 counting nodes in a BST (30 points)
Basic knowledge of reflection (detailed explanation)
Introduction to redis and explanation of data types
"Hands on deep learning" pytorch edition Chapter II exercise
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
Yolov5 model construction source code details | CSDN creation punch in
Go practice -- closures in golang (anonymous functions, closures)
leetcode452. Detonate the balloon with the minimum number of arrows
C language program ideas and several commonly used filters
乾元通多卡聚合路由器的技术解析