DenseNetNetwork<T>

Models & Types · AiDotNet.NeuralNetworks

Implements the DenseNet (Densely Connected Convolutional Network) architecture.

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

For Beginners

DenseNet is designed to maximize information flow through the network by connecting each layer directly to all subsequent layers.

Key innovations:

  • Dense Connectivity: Each layer receives features from ALL previous layers
  • Feature Reuse: Reduces redundant feature learning, fewer parameters
  • Strong Gradient Flow: Direct connections help train very deep networks
  • Compact Models: Can achieve similar accuracy with fewer parameters than ResNet

The “growth rate” (k) determines how many new feature maps each layer adds. Typical values are 12, 24, or 32. Higher values increase capacity but also cost.

How It Works

DenseNet (Huang et al., 2017) connects each layer to every other layer in a feed-forward fashion. This creates strong gradient flow and feature reuse, enabling very deep networks with fewer parameters.

Architecture overview:

Constructors

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

Properties

Property Summary
DenseNetVariant Variant { get; } Gets the DenseNet variant.
int GrowthRate { get; } Gets the growth rate (k).
int NumClasses { get; } Gets the number of output classes.

Methods

Method Summary
DenseNetNetwork<T> DenseNet121(int numClasses, int inputChannels) Creates a DenseNet-121 network.
DenseNetNetwork<T> DenseNet169(int numClasses, int inputChannels) Creates a DenseNet-169 network.
DenseNetNetwork<T> DenseNet201(int numClasses, int inputChannels) Creates a DenseNet-201 network.
DenseNetNetwork<T> DenseNet264(int numClasses, int inputChannels) Creates a DenseNet-264 network.
DenseNetNetwork<T> ForTesting(int numClasses, int inputChannels) Creates a minimal DenseNet network optimized for fast test execution.
ILayer<T> GetLayer(int index) Gets the layer at the specified index.
ModelMetadata<T> GetModelMetadata()
Tensor<T> Forward(Tensor<T> input) Performs a forward pass through the network.