当前位置:网站首页>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)
- Progressive multi grasp detection using grasp path for rgbd images
- How to connect the network: Chapter 1 CSDN creation punch in
- Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- leetcode860. Lemonade change
- 1115 counting nodes in a BST (30 points)
- Learn libcef together -- set cookies for your browser
- 1111 online map (30 points)
- [basic grammar] C language uses for loop to print Pentagram
猜你喜欢

联想R7000显卡的拆卸与安装
![[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology](/img/f1/d0dc4dc3fe49a2d2cd9e452a0ce31e.jpg)
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology

JS dynamic table creation

XML配置文件

Compile and decompile GCC common instructions
![[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)](/img/c2/87358af6b2b2892a6eceb751b3b60c.jpg)
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)

Without 50W bride price, my girlfriend was forcibly dragged away. What should I do

RT thread flow notes I startup, schedule, thread

Handler understands the record

The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
随机推荐
Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)
My first Smartphone
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
3dslam with 16 line lidar and octomap
Disassembly and installation of Lenovo r7000 graphics card
appium1.22.x 版本後的 appium inspector 需單獨安裝
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Three representations of signed numbers: original code, inverse code and complement code
Redis expiration elimination mechanism
JS scope
Redis 入門和數據類型講解
1115 counting nodes in a BST (30 points)
ES7 easy mistakes in index creation
Introduction to deep learning (II) -- univariate linear regression
1119 pre- and post order traversals (30 points)
[basic grammar] Snake game written in C language
Transferring images using flask
编译GCC遇到的“pthread.h” not found问题
请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
JS dynamic table creation