LocallyConnected2d#
- class radionets.architecture.LocallyConnected2d(in_channels, out_channels, output_size, kernel_size, stride, bias=False)[source]#
Bases:
ModuleA 2D locally connected layer implementation.
Unlike convolutional layers that share weights across spatial locations, locally connected layers use different weights for each spatial position. This allows the layer to learn location-specific features while maintaining the sliding window approach of convolutions.
- Parameters:
- in_channelsint
Number of input channels.
- out_channelsint
Number of output channels.
- output_sizetuple of int
Expected output spatial dimensions as (height, width).
- kernel_sizeint
Size of the sliding window (assumes square kernel).
- strideint
Stride of the sliding window (assumes same stride for both dimensions).
- biasbool, optional
If True, adds a learnable bias parameter. Default is False.
- Attributes:
- weightnn.Parameter
Learnable weights with shape (1, out_channels, in_channels, output_height, output_width, kernel_size²).
- biasnn.Parameter or None
Learnable bias with shape (1, out_channels, output_height, output_width) if bias=True, else None.
- kernel_sizetuple of int
Kernel size as (height, width).
- stridetuple of int
Stride as (height, width).
Methods Summary
forward(x)Define the computation performed at every call.
Methods Documentation
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.