anchors
Anchor-based dense detection heads for the voxel detectors (PointPillars, SECOND).
A packed-format port of the anchor head from open-mmlab/OpenPCDet.
AnchorHead: the single-stage anchor head (per-anchor class logits, box residuals and a direction bin).MultiGroupAnchorHead: the multi-group separate-head variant (sincos + velocity box code) used by the nuScenes detectors.prediction_branch: the per-attributeSeparateHeadbranch builder, also used by the Voxel Mamba center head.
The anchors themselves come from generate_anchors and their training targets from assign_anchor_targets, in ops.anchors; residuals are decoded with decode_box_residuals.
Classes:
-
AnchorHeadOutputβRaw and decoded predictions of
AnchorHead. -
AnchorHeadβSingle-stage anchor head.
-
AnchorHeadMultiOutputβPredictions of
MultiGroupAnchorHead. -
AnchorGroupHeadβOne RPN head of
MultiGroupAnchorHead. -
MultiGroupAnchorHeadβMulti-group anchor head, one separate head per group of classes.
Functions:
-
prediction_branchβBuild a prediction branch: middle conv blocks, then a plain output conv.
AnchorHead [source] ΒΆ
AnchorHead(
input_channels: int,
num_classes: int,
grid_size: Tuple[int, int],
point_cloud_range: Sequence[float],
*,
anchor_sizes: Sequence[Sequence[float]],
anchor_bottom_heights: Sequence[float],
feature_map_stride: int,
anchor_rotations: Sequence[float] = (0.0, 1.57),
num_dir_bins: int = 2,
dir_offset: float = 0.78539,
dir_limit_offset: float = 0.0,
)
Bases: Module
Single-stage anchor head.
Three \(1\times1\) convs predict, per anchor, class logits, 7-DoF box residuals and a direction bin. At inference the residuals are decoded against the precomputed anchors and the predicted heading is snapped to the predicted direction bin (dir_offset / num_dir_bins).
Parameters:
-
input_channels(int) βChannels of the BEV feature map fed to the head.
-
num_classes(int) βNumber of foreground classes.
-
grid_size(Tuple[int, int]) βFull voxel grid size \((n_x, n_y)\) (before the head feature-map stride).
-
point_cloud_range(Sequence[float]) βRange \((x_\min, y_\min, z_\min, x_\max, y_\max, z_\max)\).
-
anchor_sizes(Sequence[Sequence[float]]) βPer-class box size \((d_x, d_y, d_z)\), shape \((\text{num\_classes}, 3)\).
-
anchor_bottom_heights(Sequence[float]) βPer-class anchor bottom \(z\), shape \((\text{num\_classes},)\).
-
anchor_rotations(Sequence[float], default:(0.0, 1.57)) βYaw angles (radians) shared by all classes.
-
feature_map_stride(int) βBEV feature-map stride of the head.
-
num_dir_bins(int, default:2) βNumber of direction bins.
-
dir_offset(float, default:0.78539) βDirection-classifier angle offset.
-
dir_limit_offset(float, default:0.0) βOffset used when wrapping the decoded heading before snapping.
Methods:
-
reset_parametersβStart the class logits at the focal-loss prior of \(1\%\) foreground anchors and the box residuals near zero.
-
generate_predicted_boxesβDecode raw head outputs into per-anchor class logits and absolute boxes.
-
decodeβDecode a forward output into raw per-anchor detections (no score threshold or NMS).
reset_parameters [source] ΒΆ
Start the class logits at the focal-loss prior of \(1\%\) foreground anchors and the box residuals near zero.
generate_predicted_boxes [source] ΒΆ
generate_predicted_boxes(
batch_size: int,
cls_preds: Tensor,
box_preds: Tensor,
dir_cls_preds: Tensor,
) -> Tuple[Tensor, Tensor]
Decode raw head outputs into per-anchor class logits and absolute boxes.
Returns:
-
TensorβA tuple
(batch_cls_preds, batch_box_preds)of shapes \((B, A, \text{num\_classes})\) -
Tensorβ(raw logits, not sigmoided) and \((B, A, 7)\) where \(A\) is the number of anchors.
decode [source] ΒΆ
decode(out: AnchorHeadOutput) -> Detection3D
Decode a forward output into raw per-anchor detections (no score threshold or NMS).
Scores each anchor by its top sigmoid class probability and labels it by the argmax class. The full per-anchor set is returned; the evaluation pipeline applies score thresholding and per-class 3D NMS via the torch_pointcloud.ops.box3d utilities (see the benchmark examples).
Returns:
-
Detection3DβPacked per-anchor detections `{"boxes": (B * A, 7), "scores": (B * A,), "labels": (B * A,),
-
Detection3Dβ"batch": (B * A,)}` (PyG layout).
AnchorGroupHead [source] ΒΆ
AnchorGroupHead(
input_channels: int,
num_classes: int,
num_anchors_per_location: int,
code_size: int,
reg_list: Sequence[str],
head_label_indices: Tensor,
*,
num_middle_conv: int = 1,
num_middle_filter: int = 64,
act: Union[str, Callable, None] = "relu",
act_kwargs: Optional[Dict[str, Any]] = None,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
)
Bases: Module
One RPN head of MultiGroupAnchorHead.
A SeparateHead-style head over the shared feature: a classification branch plus one regression branch per box-code group (reg, height, size, angle, velo), whose outputs are concatenated into the per-anchor box code. Predictions are reshaped to the multihead layout \((B, A, \cdot)\) with \(A\) the anchors of this head's class group.
Parameters:
-
input_channels(int) βChannels of the shared feature map.
-
num_classes(int) βNumber of classes handled by this head (separate-multihead).
-
num_anchors_per_location(int) βAnchors per BEV cell for this head.
-
code_size(int) βBox code size (e.g. 10 for sincos angle + velocity).
-
reg_list(Sequence[str]) βRegression-branch spec, e.g.
["reg:2", "height:1", "size:3", "angle:2", "velo:2"]. -
num_middle_conv(int, default:1) βNumber of middle convs per branch.
-
num_middle_filter(int, default:64) βMiddle-conv channel width.
-
act(Union[str, Callable, None], default:'relu') βActivation type or callable for the middle convs.
-
act_kwargs(Optional[Dict[str, Any]], default:None) βExtra activation arguments.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization type or callable for the middle convs.
-
norm_kwargs(Optional[Dict[str, Any]], default:None) βExtra normalization arguments.
Methods:
-
reset_parametersβStart the class logits at the focal-loss prior of \(1\%\) foreground anchors.
MultiGroupAnchorHead [source] ΒΆ
MultiGroupAnchorHead(
input_channels: int,
num_classes: int,
grid_size: Tuple[int, int],
point_cloud_range: Sequence[float],
*,
anchor_sizes: Sequence[Sequence[float]],
anchor_bottom_heights: Sequence[float],
head_class_groups: Sequence[Sequence[int]],
feature_map_stride: int,
anchor_rotations: Sequence[float] = (0.0, 1.57),
shared_conv_num_filter: int = 64,
reg_list: Sequence[str] = (
"reg:2",
"height:1",
"size:3",
"angle:2",
"velo:2",
),
num_middle_conv: int = 1,
num_middle_filter: int = 64,
code_size: int = 9,
encode_angle_by_sincos: bool = True,
act: Union[str, Callable, None] = "relu",
act_kwargs: Optional[Dict[str, Any]] = None,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
)
Bases: Module
Multi-group anchor head, one separate head per group of classes.
A shared conv feeds several AnchorGroupHeads, one per class group. Anchors (7-DoF, padded to the box-code size) are decoded with decode_box_residuals (sincos heading, velocity deltas); per-head class scores stay separate (with their global label mapping) for class-wise NMS downstream.
Parameters:
-
input_channels(int) βChannels of the BEV feature map fed to the head.
-
num_classes(int) βNumber of foreground classes.
-
grid_size(Tuple[int, int]) βFull voxel grid size \((n_x, n_y)\).
-
point_cloud_range(Sequence[float]) βRange \((x_\min, y_\min, z_\min, x_\max, y_\max, z_\max)\).
-
anchor_sizes(Sequence[Sequence[float]]) βPer-class box size \((d_x, d_y, d_z)\), shape \((\text{num\_classes}, 3)\).
-
anchor_bottom_heights(Sequence[float]) βPer-class anchor bottom \(z\), shape \((\text{num\_classes},)\).
-
head_class_groups(Sequence[Sequence[int]]) βClass-index groups, one per RPN head (e.g.
[[0], [1, 2], ...]); the classes in each group share oneSeparateHead. -
anchor_rotations(Sequence[float], default:(0.0, 1.57)) βYaw angles (radians) shared by all classes.
-
feature_map_stride(int) βBEV feature-map stride of the head.
-
shared_conv_num_filter(int, default:64) βChannels of the shared conv.
-
reg_list(Sequence[str], default:('reg:2', 'height:1', 'size:3', 'angle:2', 'velo:2')) βRegression-branch spec for each head.
-
num_middle_conv(int, default:1) βMiddle convs per branch.
-
num_middle_filter(int, default:64) βMiddle-conv channel width.
-
code_size(int, default:9) βBase box code size (9 for nuScenes; +1 internally for sincos).
-
encode_angle_by_sincos(bool, default:True) βEncode heading as \((\cos, \sin)\).
-
act(Union[str, Callable, None], default:'relu') βActivation type or callable for the shared conv and head middle convs.
-
act_kwargs(Optional[Dict[str, Any]], default:None) βExtra activation arguments.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization type or callable for the shared conv and head middle convs.
-
norm_kwargs(Optional[Dict[str, Any]], default:None) βExtra normalization arguments.
Methods:
-
decodeβDecode a multihead forward output into raw per-anchor detections (no score threshold or NMS).
decode [source] ΒΆ
decode(out: AnchorHeadMultiOutput) -> Detection3D
Decode a multihead forward output into raw per-anchor detections (no score threshold or NMS).
Each head scores its anchors by their top sigmoid class probability and maps the argmax to the global label; the per-head results are concatenated in head order (matching batch_box's anchor order). When the box code carries velocity deltas the decoded \((v_x, v_y)\) columns are returned under velocity. The full per-anchor set is returned; the evaluation pipeline applies score thresholding and per-class 3D NMS via the torch_pointcloud.ops.box3d utilities (see the benchmark examples).
Returns:
-
Detection3DβPacked per-anchor detections `{"boxes": (B * A, 7), "scores": (B * A,), "labels": (B * A,),
-
Detection3Dβ"batch": (B * A,)}
(PyG layout), plus"velocity"` \((B \cdot A, 2)\) when the head predicts it.
prediction_branch [source] ΒΆ
prediction_branch(
in_channels: int,
out_channels: int,
num_middle_conv: int,
num_middle_filter: int,
*,
act: Union[str, Callable, None] = "relu",
act_kwargs: Optional[Dict[str, Any]] = None,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
) -> Sequential
Build a prediction branch: middle conv blocks, then a plain output conv.
The per-attribute branch of the multi-head detectors: num_middle_conv blocks of (\(3\times3\) conv, norm, act) followed by a \(3\times3\) output conv.
Parameters:
-
in_channels(int) βInput channels.
-
out_channels(int) βOutput channels of the final conv.
-
num_middle_conv(int) βNumber of middle conv blocks.
-
num_middle_filter(int) βChannel width of the middle convs.
-
act(Union[str, Callable, None], default:'relu') βActivation of the middle conv blocks.
-
act_kwargs(Optional[Dict[str, Any]], default:None) βExtra activation arguments.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization of the middle conv blocks.
-
norm_kwargs(Optional[Dict[str, Any]], default:None) βExtra normalization arguments.
-
bias(bool, default:False) βWhether the middle convs carry a bias (the output conv always does).
Returns:
-
SequentialβThe branch as an
nn.Sequential.
Shape
- Input: \((B, C_\text{in}, H, W)\)
- Output: \((B, C_\text{out}, H, W)\)