Class VGGConfiguration
- Namespace
- AiDotNet.Configuration
- Assembly
- AiDotNet.dll
Configuration options for VGG neural network architectures.
public class VGGConfiguration
- Inheritance
-
VGGConfiguration
- Inherited Members
Remarks
This configuration class provides all the settings needed to instantiate a VGG network. It follows the AiDotNet pattern where users provide minimal configuration and the library supplies sensible defaults.
For Beginners: VGG networks are deep convolutional neural networks designed for image classification. This configuration lets you choose which VGG variant to use (VGG11, VGG13, VGG16, or VGG19), set the number of output classes for your classification task, and optionally customize the input image dimensions and other parameters.
Typical Usage:
var config = new VGGConfiguration(VGGVariant.VGG16_BN, numClasses: 10);
var architecture = config.ToArchitecture<float>();
var network = new VGGNetwork<float>(architecture);
Constructors
VGGConfiguration(VGGVariant, int, int, int, int, double, bool)
Initializes a new instance of the VGGConfiguration class.
public VGGConfiguration(VGGVariant variant, int numClasses, int inputHeight = 224, int inputWidth = 224, int inputChannels = 3, double dropoutRate = 0.5, bool includeClassifier = true)
Parameters
variantVGGVariantThe VGG variant to use.
numClassesintThe number of output classes for classification.
inputHeightintThe height of input images (default: 224).
inputWidthintThe width of input images (default: 224).
inputChannelsintThe number of input channels (default: 3 for RGB).
dropoutRatedoubleThe dropout rate for FC layers (default: 0.5).
includeClassifierboolWhether to include the classifier layers (default: true).
Exceptions
- ArgumentOutOfRangeException
Thrown when numClasses is less than or equal to 0, or when image dimensions are invalid.
Properties
BlockConfiguration
Gets the layer configuration for each VGG block.
public int[][] BlockConfiguration { get; }
Property Value
- int[][]
Remarks
Each inner array represents a block, containing the number of filters for each conv layer. Blocks are separated by max pooling layers.
DropoutRate
Gets the dropout rate applied to the fully connected layers.
public double DropoutRate { get; }
Property Value
Remarks
Default is 0.5, which is the original VGG dropout rate.
For Beginners: Dropout is a regularization technique that randomly "drops out" (sets to zero) a fraction of neurons during training. This helps prevent overfitting. A rate of 0.5 means 50% of neurons are dropped during each training step.
IncludeClassifier
Gets whether to include the fully connected classifier layers.
public bool IncludeClassifier { get; }
Property Value
Remarks
Default is true. Set to false when using VGG as a feature extractor for transfer learning.
For Beginners: The classifier is the final part of the network that produces class predictions. When using VGG for transfer learning or as a feature extractor, you may want to remove the classifier and add your own custom layers.
InputChannels
Gets the number of input channels.
public int InputChannels { get; }
Property Value
Remarks
Default is 3 for RGB images. Use 1 for grayscale images.
For Beginners: Color images typically have 3 channels (Red, Green, Blue). Grayscale images have 1 channel. Most pre-trained VGG models expect 3-channel inputs.
InputHeight
Gets the height of input images in pixels.
public int InputHeight { get; }
Property Value
Remarks
Default is 224, which is the standard ImageNet input size.
For Beginners: VGG networks were designed for 224x224 images. While you can use different sizes, 224x224 is recommended for best results, especially when using pre-trained weights.
InputShape
Gets the computed input shape as [channels, height, width].
public int[] InputShape { get; }
Property Value
- int[]
InputWidth
Gets the width of input images in pixels.
public int InputWidth { get; }
Property Value
Remarks
Default is 224, which is the standard ImageNet input size.
NumClasses
Gets the number of output classes for classification.
public int NumClasses { get; }
Property Value
Remarks
For Beginners: This is the number of categories your model will classify images into. For example, if you're classifying cats vs dogs, this would be 2. For ImageNet, it's 1000. For CIFAR-10, it's 10.
NumConvLayers
Gets the number of convolutional layers based on the variant.
public int NumConvLayers { get; }
Property Value
NumWeightLayers
Gets the total number of weight layers (conv + FC).
public int NumWeightLayers { get; }
Property Value
TotalInputSize
Gets the total number of input features (channels * height * width).
public int TotalInputSize { get; }
Property Value
UseAutodiff
Gets or sets whether to use automatic differentiation for backpropagation.
public bool UseAutodiff { get; set; }
Property Value
Remarks
Default is false, which uses the optimized manual backward implementation.
For Beginners: Backpropagation is how neural networks learn from their mistakes. Autodiff automatically computes gradients, which is more flexible but slightly slower. The manual implementation is optimized for VGG's specific architecture.
UseBatchNormalization
Gets whether to use batch normalization.
public bool UseBatchNormalization { get; }
Property Value
Remarks
This is automatically determined based on the selected variant (variants ending in "_BN").
For Beginners: Batch normalization normalizes the activations of each layer, which helps the network train faster and more stably. Variants with batch normalization typically achieve better accuracy.
Variant
Gets the VGG variant to use.
public VGGVariant Variant { get; }
Property Value
Remarks
For Beginners: The variant determines how deep the network is. VGG16 is the most commonly used. Variants with "_BN" suffix include batch normalization which usually improves training stability and final accuracy.
Methods
CreateForCIFAR(VGGVariant, int)
Creates a configuration optimized for CIFAR-10/CIFAR-100 datasets.
public static VGGConfiguration CreateForCIFAR(VGGVariant variant, int numClasses)
Parameters
variantVGGVariantThe VGG variant to use.
numClassesintThe number of output classes (10 for CIFAR-10, 100 for CIFAR-100).
Returns
- VGGConfiguration
A VGGConfiguration optimized for CIFAR datasets.
Remarks
For Beginners: CIFAR images are 32x32 pixels, which is smaller than ImageNet's 224x224. This configuration adjusts the input size accordingly while maintaining the VGG architecture.
CreateVGG16BN(int)
Creates a new configuration for VGG16 with batch normalization.
public static VGGConfiguration CreateVGG16BN(int numClasses)
Parameters
numClassesintThe number of output classes.
Returns
- VGGConfiguration
A VGGConfiguration for VGG16_BN.
Remarks
For Beginners: This is the recommended VGG configuration for most use cases. VGG16 with batch normalization provides a good balance of accuracy and training stability.