線性層¶
- 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])