pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)
生活随笔
收集整理的這篇文章主要介紹了
pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Linear layers
class torch.nn.Linear(in_features, out_features, bias=True)對(duì)輸入數(shù)據(jù)做線性變換:y=Ax+b
參數(shù):
- in_features - 每個(gè)輸入樣本的大小
- out_features - 每個(gè)輸出樣本的大小
- bias - 若設(shè)置為False,這層不會(huì)學(xué)習(xí)偏置。默認(rèn)值:True
形狀:
- 輸入: (N,in_features)
- 輸出: (N,out_features)
變量:
- weight -形狀為(out_features x in_features)的模塊中可學(xué)習(xí)的權(quán)值
- bias -形狀為(out_features)的模塊中可學(xué)習(xí)的偏置
例子:
import torch from torch import autograd from torch import nnm = nn.Linear(20, 30) # 20個(gè)神經(jīng)元變30個(gè)神經(jīng)元? 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
總結(jié)
以上是生活随笔為你收集整理的pytorch nn.Linear(对输入数据做线性变换:y=Ax+b)(全连接层?)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: pytorch zero_()函数(将t
- 下一篇: pytorch torch.nn.Seq