vis4d.op.detect3d.bevformer.temporal_self_attention¶
An attention module used in BEVFormer based on Deformable-Detr.
Classes
|
Temperal Self Attention. |
- class TemporalSelfAttention(embed_dims=256, num_heads=8, num_levels=4, num_points=4, num_bev_queue=2, im2col_step=64, dropout=0.1, batch_first=True)[source]¶
Temperal Self Attention.
Init.
- Parameters:
embed_dims (int) – The embedding dimension of Attention. Default: 256.
num_heads (int) – Parallel attention heads. Default: 64.
num_levels (int) – The number of feature map used in Attention. Default: 4.
num_points (int) – The number of sampling points for each query in each head. Default: 4.
num_bev_queue (int) – In this version, we only use one history BEV and one currenct BEV. The length of BEV queue is 2.
im2col_step (int) – The step used in image_to_column. Default: 64.
dropout (float) – A Dropout layer on inp_identity. Default: 0.1.
batch_first (bool) – Key, Query and Value are shape of (batch, n, embed_dim) or (n, batch, embed_dim). Default to True.
- forward(query, reference_points, value, spatial_shapes, level_start_index, key_padding_mask=None, identity=None, query_pos=None)[source]¶
Forward Function of MultiScaleDeformAttention.
- Parameters:
query (Tensor) – Query of Transformer with shape (num_query, bs, embed_dims).
reference_points (Tensor) – The normalized reference points with shape (bs, num_query, num_levels, 2), all elements is range in [0, 1], top-left (0,0), bottom-right (1, 1), including padding area. or (N, Length_{query}, num_levels, 4), add additional two dimensions is (w, h) to form reference boxes.
value (Tensor) – The value tensor with shape (num_key, bs, embed_dims).
spatial_shapes (Tensor) – Spatial shape of features in different levels. With shape (num_levels, 2), last dimension represents (h, w).
level_start_index (Tensor) – The start index of each level. A tensor has shape
(num_levels, )
and can be represented as [0, h_0*w_0, h_0*w_0+h_1*w_1, …].key_padding_mask (Tensor) – ByteTensor for value, with shape [bs, num_key].
identity (Tensor) – The tensor used for addition, with the same shape as query. Default None. If None, query will be used.
query_pos (Tensor, optional) – The positional encoding for query. Default: None.
- Returns:
forwarded results with shape [num_query, bs, embed_dims].
- Return type:
Tensor