py123d_detection.torch.models.bevformer.deformable_attention¶
Classes
|
Multi-scale deformable attention. |
Height-aware Multi-Scale Deformable Attention for BEVFormer SCA. |
- class py123d_detection.torch.models.bevformer.deformable_attention.MultiScaleDeformableAttention(embed_dims=256, num_heads=8, num_levels=1, num_points=4)[source]¶
Bases:
ModuleMulti-scale deformable attention.
Full attention over a feature map costs its area; this attends to a handful of learned locations instead. Each query predicts where to look, as offsets from its reference point, and how much to weight each of those samples. The features there are read by bilinear interpolation and summed.
- Parameters:
- forward(query, reference_points, value, spatial_shapes, level_start_index, key_padding_mask=None)[source]¶
- Parameters:
query (
Tensor) –(B, Q, C).reference_points (
Tensor) –(B, Q, num_levels, 2), normalised to[0, 1], one per query per level.value (
Tensor) –(B, S, C), every level’s features flattened and concatenated, soS = sum(H_l * W_l).spatial_shapes (
Tensor) –(num_levels, 2), each level’s(H, W).level_start_index (
Tensor) –(num_levels,), where each level begins invalue.key_padding_mask (
Tensor) –(B, S),Trueat padded positions.
- Return type:
Tensor- Returns:
(B, Q, C).
- class py123d_detection.torch.models.bevformer.deformable_attention.MultiScaleDeformableAttention3D(embed_dims=256, num_heads=8, num_levels=1, num_points=8, num_Z_anchors=4)[source]¶
Bases:
ModuleHeight-aware Multi-Scale Deformable Attention for BEVFormer SCA.
Unlike plain
MultiScaleDeformableAttention, each BEV query carriesnum_Z_anchors3D reference points (one per pillar height) that project to distinct 2D locations in each camera view. Thenum_pointssampling offsets predicted per query are shared across all height anchors, so only the 2D reference location changes with height, and the sampled features are averaged across heights before weighted-summing across points. This matchesMSDeformableAttention3Dinexternal/BEVFormer/projects/mmdet3d_plugin/bevformer/modules/spatial_cross_attention.py.- Parameters:
- forward(query, reference_points, value, spatial_shapes, level_start_index, key_padding_mask=None)[source]¶
- Parameters:
query (
Tensor) –(B, Q, C).reference_points (
Tensor) –(B, Q, num_Z_anchors, 2), normalised to[0, 1], one per pillar height.value (
Tensor) –(B, S, C), every level’s features flattened and concatenated.spatial_shapes (
Tensor) –(num_levels, 2), each level’s(H, W).level_start_index (
Tensor) –(num_levels,), where each level begins invalue.key_padding_mask (
Tensor) –(B, S),Trueat padded positions.
- Return type:
Tensor- Returns:
(B, Q, C).