pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)
生活随笔
收集整理的這篇文章主要介紹了
pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linear layers
class torch.nn.Linear(in_features, out_features, bias=True)對輸入數據做線性變換:y=Ax+b
參數:
- in_features - 每個輸入樣本的大小
- out_features - 每個輸出樣本的大小
- bias - 若設置為False,這層不會學習偏置。默認值:True
形狀:
- 輸入: (N,in_features)
- 輸出: (N,out_features)
變量:
- weight -形狀為(out_features x in_features)的模塊中可學習的權值
- bias -形狀為(out_features)的模塊中可學習的偏置
例子:
import torch from torch import autograd from torch import nnm = nn.Linear(20, 30) # 20個神經元變30個神經元? input = autograd.Variable(torch.randn(128, 20))output = m(input) print(output.size()) # torch.Size([128, 30])參考文章:https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-nn/#linear-layers
總結
以上是生活随笔為你收集整理的pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pytorch zero_()函数(将t
- 下一篇: pytorch torch.nn.Seq