当前位置:网站首页>print(net) vs. net.parameters vs. net.named_parameters
print(net) vs. net.parameters vs. net.named_parameters
2022-06-10 11:33:00 【MallocLu】
print(net)仅显示模型内部关于层的信息(不包括任何层的Paramter和自定义的Paramter)
import torch
from torch.nn.parameter import Parameter
from torch import nn
from torch.nn import functional as F
from torch import optim
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.linear = nn.Linear(2, 2)
self.parameter = Parameter(torch.tensor([2.0, 2.0]))
def forward(self, x):
x = F.relu(self.linear(x))
x = self.parameter * x
return x
net = Net()
print(net)
print()
# Net(
# (linear): Linear(in_features=2, out_features=2, bias=True)
# )
for parameter in net.parameters():
print(parameter.size())
print()
torch.Size([2])
torch.Size([2, 2])
torch.Size([2])
for name, parameter in net.named_parameters():
print(name, ':', parameter.size())
# parameter : torch.Size([2])
# linear.weight : torch.Size([2, 2])
# linear.bias : torch.Size([2])
边栏推荐
- 关于单向链表
- La poignée d'enseignement de la station B vous apprend à utiliser le masque yolov5 pour tester les éléments de l'enregistrement le plus complet (apprentissage profond / détection d'objets / pythorch)
- Source of concurrent bugs (I) - visibility
- 动态规划(mid)
- dell G7 电脑关闭小键盘
- The securities and futures industry meets the new data regulation, and IP guard helps improve data security management
- 浅谈分布式事务
- Flink CDC 在大健云仓的实践
- js通过递归实现树形数据操作
- In commemoration of the 16th day of the first month, the total number of visits to the studio exceeded one million
猜你喜欢

线性代数的本质6 逆矩阵、列空间与零空间

关于单向链表

如何才能把团队给带解散。。。

Essential 5 determinants of linear algebra

【万人独木桥】那个夏天—后高考生活该如何安排?

In commemoration of the 16th day of the first month, the total number of visits to the studio exceeded one million

Source of concurrent bugs (I) - visibility

360、清华|Zero和R2D2:一种大规模的中文跨模态基准测试和视觉语言框架

JS implements tree data operation through recursion

《浅谈数组》
随机推荐
线性代数的本质6 逆矩阵、列空间与零空间
LocalDateTime与String日期互相转换
Extract e-mail from POP3 server
Detailed explanation of wechat applet registration process
大型项目综合实训
String class and learning documents
牛客面经02
kubernetes 设置 Master 可调度与不可调度
Essential 5 determinants of linear algebra
期末考试——编译原理
Privilege application permission configuration
[signalr complete series] Implementation of signalr packet communication in net6
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
SqlSessionFactory和SqlSession详解
flutter SocketIO示例
你的下一台电脑何必是电脑,探索不一样的远程操作
关于单向链表
并发bug之源(一)-可见性
In commemoration of the 16th day of the first month, the total number of visits to the studio exceeded one million
【 ten thousand people single wooden bridge 】 how to arrange life in that summer after the college entrance examination?