Linear#
- class torch.nn.Linear(in_features, out_features, bias=True, device=None, dtype=None)[原始碼]#
將仿射線性變換應用於輸入資料: .
此模組支援 TensorFloat32。
在某些 ROCm 裝置上,當使用 float16 輸入時,此模組將對反向傳播使用不同精度。
- 引數
in_features (int) – 每個輸入樣本的大小
out_features (int) – 每個輸出樣本的大小
bias (bool) – 如果設定為
False,則該層將不學習加性偏置。預設值:True
- 形狀
輸入: ,其中 表示任意數量的維度(包括零個維度),並且 。
輸出: ,其中除最後一個維度以外的所有維度都與輸入形狀相同,並且 。
- 變數
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])