Table of Contents

Class BackboneBase<T>

Namespace
AiDotNet.ComputerVision.Detection.Backbones
Assembly
AiDotNet.dll

Base class for backbone networks used in object detection models.

public abstract class BackboneBase<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
BackboneBase<T>
Derived
Inherited Members

Remarks

For Beginners: A backbone network is the first part of a detection model. It takes an input image and extracts meaningful features at multiple scales. Think of it as the "eyes" of the detector that learns to recognize patterns like edges, textures, and shapes.

Common backbones include: - ResNet: Residual networks with skip connections - CSPDarknet: Used in YOLO models, efficient for real-time detection - Swin Transformer: Vision transformer with shifted windows - EfficientNet: Scalable and efficient convolutional network

Constructors

BackboneBase()

Creates a new backbone with numeric operations for type T.

protected BackboneBase()

Fields

IsTrainingMode

Whether the backbone is in training mode.

protected bool IsTrainingMode

Field Value

bool

NumOps

Numeric operations for type T.

protected readonly INumericOperations<T> NumOps

Field Value

INumericOperations<T>

Properties

IsFrozen

Whether the backbone weights are frozen (not updated during training).

public bool IsFrozen { get; protected set; }

Property Value

bool

Name

Name of this backbone architecture.

public abstract string Name { get; }

Property Value

string

OutputChannels

Number of output channels for each feature level.

public abstract int[] OutputChannels { get; }

Property Value

int[]

Remarks

Modern detectors use multi-scale features. This array contains the number of channels at each scale, typically from high resolution (small objects) to low resolution (large objects).

Strides

The stride (downsampling factor) at each feature level.

public abstract int[] Strides { get; }

Property Value

int[]

Remarks

A stride of 8 means the feature map is 1/8 the size of the input. Common strides are [8, 16, 32] for 3-level feature pyramids.

Methods

ExtractFeatures(Tensor<T>)

Extracts multi-scale features from an input image tensor.

public abstract List<Tensor<T>> ExtractFeatures(Tensor<T> input)

Parameters

input Tensor<T>

Input image tensor with shape [batch, channels, height, width].

Returns

List<Tensor<T>>

List of feature maps at different scales, from highest to lowest resolution.

Remarks

For Beginners: This method runs the input image through the backbone and returns feature maps at multiple scales. Small objects need high-resolution features, while large objects are detected in low-resolution features.

Freeze()

Freezes the backbone weights so they are not updated during training.

public virtual void Freeze()

Remarks

For Beginners: When fine-tuning a pre-trained model on a small dataset, it's often beneficial to freeze the backbone and only train the detection head. This prevents the backbone from "forgetting" its pre-trained features.

GetExpectedInputSize()

Gets the expected input size for this backbone.

public virtual (int Height, int Width) GetExpectedInputSize()

Returns

(int min, int max)

Tuple of (height, width) for optimal input size.

GetParameterCount()

Gets the total number of parameters in the backbone.

public abstract long GetParameterCount()

Returns

long

Number of trainable parameters.

ReadParameters(BinaryReader)

Reads parameters from a binary reader for deserialization.

public abstract void ReadParameters(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read from.

SetTrainingMode(bool)

Sets whether the backbone is in training mode.

public virtual void SetTrainingMode(bool training)

Parameters

training bool

True for training, false for inference.

Unfreeze()

Unfreezes the backbone weights for training.

public virtual void Unfreeze()

ValidateInput(Tensor<T>)

Validates that the input tensor has the correct shape.

protected void ValidateInput(Tensor<T> input)

Parameters

input Tensor<T>

Input tensor to validate.

Exceptions

ArgumentException

Thrown if the input shape is invalid.

WriteParameters(BinaryWriter)

Writes all parameters to a binary writer for serialization.

public abstract void WriteParameters(BinaryWriter writer)

Parameters

writer BinaryWriter

The binary writer to write to.