小白学Pytorch系列–Torch.nn API Linear Layers(10)

| 方法 | 注释 |
|---|---|
| nn.Identity | 不区分参数的占位符标识操作符。 |
| nn.Linear | 对传入数据应用线性转换y=xAT+by=xA^T+by=xAT+b |
| nn.Bilinear | 对传入数据应用双线性转换y=x1TAx2+by=x_1^T A x_2+by=x1TAx2+b |
| nn.LazyLinear | 一个torch.nn.Linear模块,其中的特征被推断出来。 |
nn.Identity

>>> m = nn.Identity(54, unused_argument1=0.1, unused_argument2=False)
>>> input = torch.randn(128, 20)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 20])
nn.Linear
对传入数据应用线性转换y=xAT+by=x A^T+by=xAT+b


>>> m = nn.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 30])
nn.Bilinear


>>> m = nn.Bilinear(20, 30, 40)
>>> input1 = torch.randn(128, 20)
>>> input2 = torch.randn(128, 30)
>>> output = m(input1, input2)
>>> print(output.size())
torch.Size([128, 40])
nn.LazyLinear

Pytorch中的线性与双线性层(nn.Identity,nn.Linear,nn.Bilinear,nn.LazyLinear)
该文介绍了Pytorch中几个关键的神经网络层:nn.Identity作为一个无操作的占位符,nn.Linear执行基本的线性转换,nn.Bilinear则用于双线性转换,而nn.LazyLinear是线性层的一种延迟初始化版本。通过示例展示了各层如何处理输入数据并返回相应输出的形状。
1500

被折叠的 条评论
为什么被折叠?



