Table of Contents

Class RPN<T>

Namespace
AiDotNet.ComputerVision.Detection.ObjectDetection.RCNN
Assembly
AiDotNet.dll

Region Proposal Network (RPN) - Generates object proposals for two-stage detectors.

public class RPN<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
RPN<T>
Inherited Members

Remarks

For Beginners: RPN is a neural network that scans an image and proposes regions that likely contain objects. It's the first stage in two-stage detectors like Faster R-CNN, enabling end-to-end training.

Key features: - Slides a small network over the feature map - Generates proposals at multiple scales and aspect ratios via anchors - Predicts objectness scores and bounding box refinements - Shared features with detection network for efficiency

Reference: Ren et al., "Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks", NeurIPS 2015

Constructors

RPN(int, int, int[]?, double[]?, int?)

Creates a new Region Proposal Network.

public RPN(int inChannels, int hiddenDim = 256, int[]? anchorSizes = null, double[]? aspectRatios = null, int? featureLevel = null)

Parameters

inChannels int

Number of input feature channels.

hiddenDim int

Hidden dimension for the intermediate convolution.

anchorSizes int[]

Sizes of anchors in pixels.

aspectRatios double[]

Aspect ratios for anchors.

featureLevel int?

Feature pyramid level to use (0-indexed). Determines stride and base size. Default is middle level.

Properties

AnchorGenerator

Gets the anchor generator used by this RPN.

public AnchorGenerator<T> AnchorGenerator { get; }

Property Value

AnchorGenerator<T>

Methods

Forward(Tensor<T>)

Forward pass through the RPN.

public (Tensor<T> objectness, Tensor<T> bboxDeltas, List<BoundingBox<T>> anchors) Forward(Tensor<T> features)

Parameters

features Tensor<T>

Feature map from backbone [batch, channels, height, width].

Returns

(Tensor<T> objectness, Tensor<T> bboxDeltas, List<BoundingBox<T>> anchors)

Tuple of (objectness logits, bbox deltas, anchors as list of BoundingBox).

GenerateProposals(Tensor<T>, Tensor<T>, List<BoundingBox<T>>, int, int, int, int, double)

Generates proposals from RPN outputs.

public List<(Tensor<T> boxes, Tensor<T> scores)> GenerateProposals(Tensor<T> objectness, Tensor<T> bboxDeltas, List<BoundingBox<T>> anchors, int imageHeight, int imageWidth, int preNmsTopK = 2000, int postNmsTopK = 1000, double nmsThreshold = 0.7)

Parameters

objectness Tensor<T>

Objectness logits [batch, num_anchors, 2].

bboxDeltas Tensor<T>

Bbox deltas [batch, num_anchors, 4].

anchors List<BoundingBox<T>>

Anchor boxes as list of BoundingBox.

imageHeight int

Original image height.

imageWidth int

Original image width.

preNmsTopK int

Maximum proposals before NMS.

postNmsTopK int

Maximum proposals after NMS.

nmsThreshold double

IoU threshold for NMS.

Returns

List<(Tensor<T> boxes, Tensor<T> scores)>

Proposal boxes [num_proposals, 4] as (x1, y1, x2, y2).

GetParameterCount()

Gets the total parameter count for this RPN.

public long GetParameterCount()

Returns

long

ReadParameters(BinaryReader)

Reads the RPN parameters from a binary stream.

public void ReadParameters(BinaryReader reader)

Parameters

reader BinaryReader

WriteParameters(BinaryWriter)

Writes the RPN parameters to a binary stream.

public void WriteParameters(BinaryWriter writer)

Parameters

writer BinaryWriter