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#
-
class Linear : public torch::nn::ModuleHolder<LinearImpl>#
A
ModuleHoldersubclass forLinearImpl.See the documentation for
LinearImplclass to learn what methods it provides, and examples of how to useLinearwithtorch::nn::LinearOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = LinearImpl#
-
using Impl = LinearImpl#
-
class LinearImpl : public torch::nn::Cloneable<LinearImpl>#
Applies a linear transformation with optional bias.
See https://pytorch.org/docs/main/generated/torch.nn.Linear.html to learn about the exact behavior of this module.
See the documentation for
torch::nn::LinearOptionsclass to learn what constructor arguments are supported for this module.Example:
Linear model(LinearOptions(5, 2).bias(false));
Public Functions
-
inline LinearImpl(int64_t in_features, int64_t out_features)#
-
explicit LinearImpl(const LinearOptions &options_)#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
-
void reset_parameters()#
-
inline LinearImpl(int64_t in_features, int64_t out_features)#
Example:
auto linear = torch::nn::Linear(torch::nn::LinearOptions(784, 256).bias(true));
auto output = linear->forward(input); // input: [N, 784]
Bilinear#
-
class Bilinear : public torch::nn::ModuleHolder<BilinearImpl>#
A
ModuleHoldersubclass forBilinearImpl.See the documentation for
BilinearImplclass to learn what methods it provides, and examples of how to useBilinearwithtorch::nn::BilinearOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = BilinearImpl#
-
using Impl = BilinearImpl#
-
class BilinearImpl : public torch::nn::Cloneable<BilinearImpl>#
Applies a billinear transformation with optional bias.
See https://pytorch.org/docs/main/generated/torch.nn.Bilinear.html to learn about the exact behavior of this module.
See the documentation for
torch::nn::BilinearOptionsclass to learn what constructor arguments are supported for this module.Example:
Bilinear model(BilinearOptions(3, 2, 4).bias(false));
Public Functions
-
inline BilinearImpl(int64_t in1_features, int64_t in2_features, int64_t out_features)#
-
explicit BilinearImpl(const BilinearOptions &options_)#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
-
void reset_parameters()#
-
inline BilinearImpl(int64_t in1_features, int64_t in2_features, int64_t out_features)#
Identity#
-
class Identity : public torch::nn::ModuleHolder<IdentityImpl>#
A
ModuleHoldersubclass forIdentityImpl.See the documentation for
IdentityImplclass to learn what methods it provides, or the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = IdentityImpl#
-
using Impl = IdentityImpl#
-
class IdentityImpl : public torch::nn::Cloneable<IdentityImpl>#
A placeholder identity operator that is argument-insensitive.
See https://pytorch.org/docs/main/generated/torch.nn.Identity.html to learn about the exact behavior of this module.
Flatten#
-
class Flatten : public torch::nn::ModuleHolder<FlattenImpl>#
A
ModuleHoldersubclass forFlattenImpl.See the documentation for
FlattenImplclass to learn what methods it provides, and examples of how to useFlattenwithtorch::nn::FlattenOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = FlattenImpl#
-
using Impl = FlattenImpl#
-
class FlattenImpl : public torch::nn::Cloneable<FlattenImpl>#
A placeholder for Flatten operator See https://pytorch.org/docs/main/generated/torch.nn.Flatten.html to learn about the exact behavior of this module.
See the documentation for
torch::nn::FlattenOptionsclass to learn what constructor arguments are supported for this module.Example:
Flatten model(FlattenOptions().start_dim(2).end_dim(4));
Public Functions
-
explicit FlattenImpl(const FlattenOptions &options_ = {})#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
Public Members
-
FlattenOptions options#
The options used to configure this module.
-
explicit FlattenImpl(const FlattenOptions &options_ = {})#
Unflatten#
-
class Unflatten : public torch::nn::ModuleHolder<UnflattenImpl>#
A
ModuleHoldersubclass forUnflattenImpl.See the documentation for
UnflattenImplclass to learn what methods it provides, and examples of how to useUnflattenwithtorch::nn::UnflattenOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = UnflattenImpl#
-
using Impl = UnflattenImpl#
-
class UnflattenImpl : public torch::nn::Cloneable<UnflattenImpl>#
A placeholder for unflatten operator See https://pytorch.org/docs/main/generated/torch.nn.Unflatten.html to learn about the exact behavior of this module.
See the documentation for
torch::nn::UnflattenOptionsclass to learn what constructor arguments are supported for this module.Example:
Unflatten model(UnflattenOptions(0, {2, 2})); Unflatten model(UnflattenOptions("B", {{"B1", 2}, {"B2", 2}}));
Public Functions
-
inline UnflattenImpl(int64_t dim, std::vector<int64_t> sizes)#
-
inline UnflattenImpl(std::string dimname, UnflattenOptions::namedshape_t namedshape)#
-
explicit UnflattenImpl(UnflattenOptions options_)#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
Public Members
-
UnflattenOptions options#
The options used to configure this module.
-
inline UnflattenImpl(int64_t dim, std::vector<int64_t> sizes)#