ResNetNetwork<T>

Models & Types · AiDotNet.NeuralNetworks

Represents a ResNet (Residual Network) neural network architecture for image classification.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → ImageClassifierModelLayoutBase<T> → ResNetNetwork<T>

For Beginners

ResNet networks revolutionized deep learning by solving the “vanishing gradient” problem that made very deep networks hard to train. Key benefits include:

  • Can train networks with 100+ layers (compared to ~20 layers for earlier architectures)
  • Skip connections allow gradients to flow more easily during training
  • Each block learns the “residual” (difference) rather than the complete transformation
  • Winner of ImageNet 2015 competition with top-5 error of 3.57%

How It Works

ResNet networks are deep convolutional neural networks that introduced skip connections (residual connections) to enable training of very deep networks. They learn residual functions with reference to the layer inputs, rather than learning unreferenced functions directly.

Architecture Variants:

  • ResNet18/34: Use BasicBlock (2 conv layers per block)
  • ResNet50/101/152: Use BottleneckBlock (1x1-3x3-1x1 conv pattern) for efficiency

Typical Usage:

Constructors

Constructor Summary
ResNetNetwork() Initializes a new instance with default settings.
ResNetNetwork(NeuralNetworkArchitecture<T> architecture, ResNetConfiguration configuration, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, ResNetOptions options) Initializes a new instance of the ResNetNetwork class.

Properties

Property Summary
ResNetVariant Variant { get; } Gets the ResNet variant being used.
bool UsesBottleneck { get; } Gets whether this variant uses bottleneck blocks.
int NumClasses { get; } Gets the number of output classes for classification.

Methods

Method Summary
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input)
ModelMetadata<T> GetModelMetadata() Retrieves metadata about the ResNet network model.
ResNetNetwork<T> ForTesting(int numClasses, int inputChannels) Creates a minimal ResNet network optimized for fast test execution.
Tensor<T> Forward(Tensor<T> input) Performs a forward pass through the ResNet network with the given input tensor.
Tensor<T> ForwardForTraining(Tensor<T> input)
long GetParameterCount() Gets the total number of trainable parameters in the network.