当前位置:网站首页>NN in pytorch Modulelist and nn.sequential
NN in pytorch Modulelist and nn.sequential
2022-07-23 09:40:00 【Mick..】
nn.ModuleList() and nn.Sequential() Can be used to build neural networks .nn.ModuleList() Function is used to store various modules , The front and back modules are not related .
class net(nn.Module):
def __init__(self):
super(net6, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(3)])
def forward(self, x):
for layer in self.linears:
x = layer(x)
return x
net = net()
print(net)
# net(
# (linears): ModuleList(
# (0): Linear(in_features=10, out_features=10, bias=True)
# (1): Linear(in_features=10, out_features=10, bias=True)
# (2): Linear(in_features=10, out_features=10, bias=True)
# )
# )* You can unpack the list
class net(nn.Module):
def __init__(self):
super(net7, self).__init__()
self.linear_list = [nn.Linear(10, 10) for i in range(3)]
self.linears = nn.Sequential(*self.linear_list) ### * You can unpack the list
def forward(self, x):
self.x = self.linears(x)
return x
net = net()
print(net)
# net(
# (linears): Sequential(
# (0): Linear(in_features=10, out_features=10, bias=True)
# (1): Linear(in_features=10, out_features=10, bias=True)
# (2): Linear(in_features=10, out_features=10, bias=True)
# )
# )边栏推荐
猜你喜欢

FPGA出错的积累

pna肽核酸定制服务|肽核酸钳制-PCR(PNA-PCR)|cGAPPNA多价肽核酸配体

A ConvNet for the 2020s 论文阅读

ADAS测试方案

【Jailhouse 文章】Virtualization over Multiprocessor System-on-Chip an Enabling Paradigm for...

Wallys/DR4019S/IPQ4019/11ABGN/802.11AC/high power

PNA polypeptide suc ala ala Pro AAA PNA suc ala3 PNA Pyr Phe Leu PNA

1、 Buildreoot directory structure

向后量子密码学迁移!美国NIST公布12家合作伙伴

【洛谷】P1318 积水面积
随机推荐
PNA PNA modified polypeptide Pro Phe Arg PNA (s-2302) | DNP Gly x l Pro Gly PNA
DNS and DHCP of network security foundation
PNA specification information | soybean peroxidase labeled PNA (peptide nucleic acid, PNA)
READ-COMMITTED没有区间锁
[ssm] exception handling
Teach you how to set up Alibaba cloud DDNS in Qunhui
1057 Stack
【Jailhouse 文章】Virtualization over Multiprocessor System-on-Chip an Enabling Paradigm for...
Repeat: the difference between Pearson Pearson correlation coefficient and Spearman Spearman correlation coefficient
AIRIOT答疑第5期|如何使用低代码业务流引擎?
qml-使用 listView 构筑三级树形(treeView)架构
idea 的 gradle项目中文乱码
Notifyicondata tray used by BCG
【HLS】流水线仿真之排队函数的调用
PNA肽核酸修饰多肽Pro-Phe-Arg-pNA (S-2302)|Dnp-Gly-X-L-Pro-Gly-pNA
Repeatable-read RR mode interval lock
多肽修饰PNA肽核酸Bz-D-Phe-Val-Arg-pNA|L-Phe-Val-Arg-pNA
Program environment and pretreatment
PNA peptide nucleic acid modified peptide suc ala PNA | 2-ala ala leupna | AC Phe Gly PNA
使用递归字符串反转和全排列