线性层¶
- class torch.nn.Linear(in_features, out_features, bias=True, device=None, dtype=None)[源代码][源代码]¶
对输入数据应用仿射线性变换:。
此模块支持 TensorFloat32。
在某些 ROCm 设备上,当使用 float16 输入时,此模块在反向传播时将使用不同的精度。
- 参数
- 形状
输入: 其中 表示任意数量的维度(包括零个),且 。
输出: 其中除最后一个维度外,所有维度的形状与输入相同,且 。
- 变量
weight (torch.Tensor) – 模块的可学习权重,形状为 。其值从 ,其中
bias – 模块的可学习偏置,形状为 。如果
bias
为True
,其值从 初始化,其中
示例
>>> m = nn.Linear(20, 30) >>> input = torch.randn(128, 20) >>> output = m(input) >>> print(output.size()) torch.Size([128, 30])