当前位置:网站首页>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
边栏推荐
- Why is IP direct connection prohibited in large-scale Internet
- PHP function
- Best practices of Apache APIs IX high availability configuration center based on tidb
- Calculate the number of occurrences of a character
- How to test mobile app?
- CVPR 2022 优质论文分享
- fatal error: torch/extension.h: No such file or directory
- CAP定理
- Go language slice, range, set
- Large factory technology implementation | industry solution series tutorials
猜你喜欢
随机推荐
字节面试 transformer相关问题 整理复盘
IronPDF for . NET 2022.4.5455
Go concurrency and channel
Mobile finance (for personal use)
Connectez PHP à MySQL via aodbc
utils.DeprecatedIn35 因升级可能取消,该如何办
【递归之数的拆分】n分k,限定范围的拆分
What if the package cannot be found
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
Upgrade MySQL 5.1 to 5.67
服务器中毒了怎么办?服务器怎么防止病毒入侵?
Redis master-slave replication process
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
fatal error: torch/extension.h: No such file or directory
GFS distributed file system (Theory)
自动化测试框架常见类型▏自动化测试就交给软件测评机构
Neodynamic Barcode Professional for WPF V11. 0
Deletes the least frequently occurring character in the string
Large factory technology implementation | industry solution series tutorials
c语言---指针进阶









