InvertedResidualBlock<T>

Layers · AiDotNet.NeuralNetworks.Layers

Implements an Inverted Residual Block (MBConv) used in MobileNetV2 and MobileNetV3.

Inheritance: LayerBase<T> → InvertedResidualBlock<T>

Implements: IShapeContract

For Beginners

The Inverted Residual Block is designed for efficient mobile inference.

Key innovations:

  • Expansion: First EXPANDS the channels (opposite of traditional bottlenecks)
  • Depthwise separable convolution: Filters each channel independently, then mixes
  • Linear bottleneck: The final projection has NO activation (preserves information)
  • Skip connection: Only when input and output dimensions match

This design reduces computational cost while maintaining model accuracy.

How It Works

The Inverted Residual Block is the core building block for MobileNet architectures. Unlike traditional residual blocks that narrow then widen, inverted residual blocks expand then narrow, hence the name “inverted.”

Architecture:

Constructors

Constructor Summary
InvertedResidualBlock(int outChannels, int expansionRatio, int stride, bool useSE, int seRatio, IActivationFunction<T> activationFunction) Initializes a new instance of the InvertedResidualBlock class.

Properties

Property Summary
bool SupportsTraining { get; } Gets a value indicating whether this layer supports training.
int ExpansionRatio { get; } Gets the expansion ratio.
int InChannels { get; set; } Gets the number of input channels.
int OutChannels { get; } Gets the number of output channels.
int Stride { get; } Gets the stride used in the depthwise convolution.

Methods

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