Linear#
- class torch.nn.modules.linear.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])