Back to Pytorch

Linear Layers

docs/cpp/source/api/nn/linear.md

2.12.01.4 KB
Original Source

Linear Layers

Linear layers apply affine transformations to input data: y = xW^T + b. They are the building blocks of fully-connected networks and are used for feature transformation, classification heads, and projection layers.

  • Linear: Standard fully-connected layer
  • Bilinear: Bilinear transformation of two inputs
  • Identity: Pass-through layer (useful for skip connections)
  • Flatten/Unflatten: Reshape tensors between convolutional and linear layers

Linear

{doxygenclass}
:members:
:undoc-members:
{doxygenclass}
:members:
:undoc-members:

Example:

cpp
auto linear = torch::nn::Linear(torch::nn::LinearOptions(784, 256).bias(true));
auto output = linear->forward(input);  // input: [N, 784]

Bilinear

{doxygenclass}
:members:
:undoc-members:
{doxygenclass}
:members:
:undoc-members:

Identity

{doxygenclass}
:members:
:undoc-members:
{doxygenclass}
:members:
:undoc-members:

Flatten

{doxygenclass}
:members:
:undoc-members:
{doxygenclass}
:members:
:undoc-members:

Unflatten

{doxygenclass}
:members:
:undoc-members:
{doxygenclass}
:members:
:undoc-members: