Table of Contents

Class CSPDarknet<T>

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

CSP-Darknet backbone network used in YOLO family models (v5, v7, v8).

public class CSPDarknet<T> : BackboneBase<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
CSPDarknet<T>
Inherited Members

Remarks

For Beginners: CSP-Darknet is a specialized feature extraction network designed for real-time object detection. It uses Cross-Stage Partial connections to reduce computation while maintaining accuracy.

Key features: - Cross-Stage Partial (CSP) blocks to reduce redundant gradient information - Dark blocks with residual connections for gradient flow - Multi-scale feature extraction at different depths

Reference: Bochkovskiy et al., "YOLOv4: Optimal Speed and Accuracy of Object Detection"

Constructors

CSPDarknet(double, double, int)

Creates a new CSP-Darknet backbone.

public CSPDarknet(double depth = 1, double widthMultiplier = 1, int inChannels = 3)

Parameters

depth double

Depth multiplier for number of blocks (default 1.0 = medium).

widthMultiplier double

Width multiplier for channel counts (default 1.0 = medium).

inChannels int

Number of input channels (default 3 for RGB).

Properties

Name

Name of this backbone architecture.

public override string Name { get; }

Property Value

string

OutputChannels

Number of output channels for each feature level.

public override 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 override 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 override 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.

GetParameterCount()

Gets the total number of parameters in the backbone.

public override long GetParameterCount()

Returns

long

Number of trainable parameters.

ReadParameters(BinaryReader)

Reads parameters from a binary reader for deserialization.

public override void ReadParameters(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read from.

WriteParameters(BinaryWriter)

Writes all parameters to a binary writer for serialization.

public override void WriteParameters(BinaryWriter writer)

Parameters

writer BinaryWriter

The binary writer to write to.