BasicBlock<T>

Layers · AiDotNet.NeuralNetworks.Layers

Implements the BasicBlock used in ResNet18 and ResNet34 architectures.

Inheritance: LayerBase<T> → BasicBlock<T>

Implements: IShapeContract

For Beginners

The BasicBlock is like a “learning module” with a shortcut.

The key insight is:

  • The two conv layers learn to predict what needs to be ADDED to the input (the “residual”)
  • The skip connection adds the original input back to this learned residual
  • This makes it easier to train very deep networks because gradients can flow directly through the skip connection

When the input and output have different dimensions (due to stride or channel changes), a downsample layer (1x1 conv + BN) is used to match the dimensions before adding.

How It Works

The BasicBlock contains two 3x3 convolutional layers with batch normalization and ReLU activation. A skip connection adds the input directly to the output, enabling gradient flow through very deep networks.

Architecture:

Constructors

Constructor Summary
BasicBlock(int outChannels, int stride, bool zeroInitResidual) Initializes a new instance of the BasicBlock class.

Properties

Property Summary
bool SupportsTraining { get; }

Methods

Method Summary
IReadOnlyList<ILayer<T>> GetSubLayers()
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
void ClearGradients()
void ResetState() Resets the internal state of the block.
void UpdateParameters(T learningRate) Updates the parameters of all internal layers.

Fields

Field Summary
int Expansion The expansion factor for BasicBlock.