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)的模块中可学习的偏置

例子:

>>> m = nn.Linear(20, 30)>>> input = autograd.Variable(torch.randn(128, 20))>>> output = m(input)>>> print(output.size())

results matching ""

    No results matching ""