当前位置:网站首页>Named in pytoch_ parameters、named_ children、named_ Modules function
Named in pytoch_ parameters、named_ children、named_ Modules function
2022-04-23 15:43:00 【If you encounter a barrier, you have to step over it】
named_parameters function
- Returns... As an iterator model All the parameters in , The return value is one
Dictionaries: containName of parameterandValue size; - Used in internal implementation
A recursive algorithm, So for nested network parameters , MeetingRecursive traversal, OutputBottom layer parameters, See the following example ;
named_children() function
- This function is used to output the data in the network
Layer 1 module name and instance object, Only the top module name will be displayed ;
named_modules() function
- This function is used to recursively output the data in the network
Module name and instance object of each layer, The first mock exam will display the name of each module in all layers.
Example
import torch
import torch.nn as nn
class TestModel(nn.Module):
def __init__(self):
super(TestModel,self).__init__()
# Conventional convolution layer , The input channel is 3, The output channel is 12
self.conv1 = nn.Conv2d(3, 12, kernel_size=3, padding=1)
self.layer1 = nn.Sequential(
nn.Conv2d(12, 6, kernel_size=3, padding=1),
nn.Conv2d(6, 6, kernel_size=3, padding=1),
nn.ReLU(inplace=True)
)
def forward(self, x):
x = self.conv1(x)
x = self.layer1(x)
model = TestModel()
named_parameters = model.named_parameters()
print('------------parameters-----------------')
for name, parameter in named_parameters:
print(name)
named_children = model.named_children()
print('------------parameters-----------------')
for name, children in named_children:
print(name)
named_modules = model.named_modules()
print('------------modules-----------------')
for name, module in named_modules:
print(name)
------------ Output --------------------------
------------parameters-----------------
conv1.weight
conv1.bias
layer1.0.weight # You can see that for sequential The modules in the module are given a numeric number
layer1.0.bias
layer1.1.weight
layer1.1.bias
------------parameters-----------------
conv1
layer1
------------modules-----------------
conv1
layer1
layer1.0
layer1.1
layer1.2
版权声明
本文为[If you encounter a barrier, you have to step over it]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231532210552.html
边栏推荐
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
- 单体架构系统重新架构
- 【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
- Date date calculation in shell script
- 一刷313-剑指 Offer 06. 从尾到头打印链表(e)
- Special analysis of China's digital technology in 2022
- Modèle de Cluster MySQL et scénario d'application
- 提取不重复的整数
- How do you think the fund is REITs? Is it safe to buy the fund through the bank
- Upgrade MySQL 5.1 to 5.68
猜你喜欢

Sorting and replying to questions related to transformer

pgpool-II 4.3 中文手册 - 入门教程

时序模型:长短期记忆网络(LSTM)

c语言---指针进阶

Configuration of multi spanning tree MSTP

IronPDF for . NET 2022.4.5455

One brush 314 sword finger offer 09 Implement queue (E) with two stacks

网站压测工具Apache-ab,webbench,Apache-Jemeter

What if the server is poisoned? How does the server prevent virus intrusion?

现在做自媒体能赚钱吗?看完这篇文章你就明白了
随机推荐
fatal error: torch/extension.h: No such file or directory
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
Node.js ODBC连接PostgreSQL
Sorting and replying to questions related to transformer
Go language, array, pointer, structure
Mumu, go all the way
多级缓存使用
Large factory technology implementation | industry solution series tutorials
Application of Bloom filter in 100 million flow e-commerce system
Code live collection ▏ software test report template Fan Wen is here
Codejock Suite Pro v20.3.0
Why disable foreign key constraints
时序模型:门控循环单元网络(GRU)
Deeply learn the skills of parameter adjustment
What is CNAs certification? What are the software evaluation centers recognized by CNAs?
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
PHP classes and objects
PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
2022年中国数字科技专题分析
开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK