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