当前位置:网站首页>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 parameter
andValue 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
边栏推荐
- utils.DeprecatedIn35 因升级可能取消,该如何办
- 导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
- 携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?
- 移动金融(自用)
- 移动app软件测试工具有哪些?第三方软件测评小编分享
- Upgrade MySQL 5.1 to 5.611
- Large factory technology implementation | industry solution series tutorials
- JVM-第2章-类加载子系统(Class Loader Subsystem)
- Node. JS ODBC connection PostgreSQL
- Multi level cache usage
猜你喜欢
c语言---字符串+内存函数
今日睡眠质量记录76分
How did the computer reinstall the system? The display has no signal
Sorting and replying to questions related to transformer
网站压测工具Apache-ab,webbench,Apache-Jemeter
IronPDF for . NET 2022.4.5455
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
pgpool-II 4.3 中文手册 - 入门教程
Neodynamic Barcode Professional for WPF V11. 0
Treatment of idempotency
随机推荐
Configuration of multi spanning tree MSTP
Upgrade MySQL 5.1 to 5.67
Explanation of redis database (I)
s16. One click installation of containerd script based on image warehouse
pgpool-II 4.3 中文手册 - 入门教程
IronPDF for .NET 2022.4.5455
Codejock Suite Pro v20. three
单体架构系统重新架构
深度学习调参的技巧
Neodynamic Barcode Professional for WPF V11.0
Upgrade MySQL 5.1 to 5.68
Mumu, go all the way
How did the computer reinstall the system? The display has no signal
Best practices of Apache APIs IX high availability configuration center based on tidb
How to test mobile app?
时序模型:长短期记忆网络(LSTM)
开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
Codejock Suite Pro v20.3.0
小程序知识点积累
mysql乐观锁解决并发冲突