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
TThe 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
inChannelsintNumber of input feature channels.
hiddenDimintHidden dimension for the intermediate convolution.
anchorSizesint[]Sizes of anchors in pixels.
aspectRatiosdouble[]Aspect ratios for anchors.
featureLevelint?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
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
featuresTensor<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
objectnessTensor<T>Objectness logits [batch, num_anchors, 2].
bboxDeltasTensor<T>Bbox deltas [batch, num_anchors, 4].
anchorsList<BoundingBox<T>>Anchor boxes as list of BoundingBox.
imageHeightintOriginal image height.
imageWidthintOriginal image width.
preNmsTopKintMaximum proposals before NMS.
postNmsTopKintMaximum proposals after NMS.
nmsThresholddoubleIoU threshold for NMS.
Returns
GetParameterCount()
Gets the total parameter count for this RPN.
public long GetParameterCount()
Returns
ReadParameters(BinaryReader)
Reads the RPN parameters from a binary stream.
public void ReadParameters(BinaryReader reader)
Parameters
readerBinaryReader
WriteParameters(BinaryWriter)
Writes the RPN parameters to a binary stream.
public void WriteParameters(BinaryWriter writer)
Parameters
writerBinaryWriter