關於該類:
torch.nn.Linear(in_features, out_features, bias=True)
可以對輸入數據進行線性變換:
$y = x A^T + b$
in_features: 輸入數據的大小。
out_features: 輸出數據的大小。
bias: 是否添加一個可學習的 bias,即上式中的 $b$。
該線性變換,只對輸入的 tensor 的最后一維進行:
例如我們有一個Linear層如下:
m = nn.Linear(20, 30)
示例1:
input = torch.randn(2, 5, 8, 20) output = m(input) print(output.size())
結果:
torch.Size([2, 5, 8, 30])
示例2:
input = torch.randn(20) output = m(input) print(output.size())
結果:
torch.Size([30])