detrium.nn.decoders.dfine_decoder

DEIM: DETR with Improved Matching for Fast Convergence Copyright (c) 2024 The DEIM Authors. All Rights Reserved. --------------------------------------------------------------------------------- Modified from D-FINE (https://github.com/Peterande/D-FINE/) Copyright (c) 2024 D-FINE Authors. All Rights Reserved.

导出符号 · DFINETransformer

class MSDeformableAttention(nn.Module)
名称类型默认值
embed_dim—256
num_heads—8
num_levels—4
num_points—4
method—'default'
offset_scale—0.5
forward(self, query: torch.Tensor, reference_points: torch.Tensor, value: torch.Tensor, value_spatial_shapes: List[int])

Args: query (Tensor): [bs, query_length, C] reference_points (Tensor): [bs, query_length, n_levels, 2], range in [0, 1], top-left (0,0), bottom-right (1, 1), including padding area value (Tensor): [bs, value_length, C] value_spatial_shapes (List): [n_levels, 2], [(H_0, W_0), (H_1, W_1), ..., (H_{L-1}, W_{L-1})] Returns: output (Tensor): [bs, Length_{query}, C]

名称类型默认值
querytorch.Tensor—
reference_pointstorch.Tensor—
valuetorch.Tensor—
value_spatial_shapesList[int]—
class TransformerDecoderLayer(nn.Module)
名称类型默认值
d_model—256
n_head—8
dim_feedforward—1024
dropout—0.0
activation—'relu'
n_levels—4
n_points—4
cross_attn_method—'default'
layer_scale—None
forward(self, target, reference_points, value, spatial_shapes, attn_mask=None, query_pos_embed=None)
名称类型默认值
target——
reference_points——
value——
spatial_shapes——
attn_mask—None
query_pos_embed—None
class Integral(nn.Module)

A static layer that calculates integral results from a distribution. This layer computes the target location using the formula: `sum{Pr(n) * W(n)}`, where Pr(n) is the softmax probability vector representing the discrete distribution, and W(n) is the non-uniform Weighting Function. Args: reg_max (int): Max number of the discrete bins. Default is 32. It can be adjusted based on the dataset or task requirements.

名称类型默认值
reg_max—32
class TransformerDecoder(nn.Module)

Transformer Decoder implementing Fine-grained Distribution Refinement (FDR). This decoder refines object detection predictions through iterative updates across multiple layers, utilizing attention mechanisms, location quality estimators, and distribution refinement techniques to improve bounding box accuracy and robustness.

名称类型默认值
hidden_dim——
decoder_layer——
decoder_layer_wide——
num_layers——
num_head——
reg_max——
reg_scale——
up——
eval_idx—-1
layer_scale—2
act—'relu'
value_op(self, memory, value_proj, value_scale, memory_mask, memory_spatial_shapes)

Preprocess values for MSDeformableAttention.

名称类型默认值
memory——
value_proj——
value_scale——
memory_mask——
memory_spatial_shapes——
forward(self, target, ref_points_unact, memory, spatial_shapes, bbox_head, score_head, query_pos_head, pre_bbox_head, integral, up, reg_scale, attn_mask=None, memory_mask=None, dn_meta=None)
名称类型默认值
target——
ref_points_unact——
memory——
spatial_shapes——
bbox_head——
score_head——
query_pos_head——
pre_bbox_head——
integral——
up——
reg_scale——
attn_mask—None
memory_mask—None
dn_meta—None
class DFINETransformer(nn.Module)
名称类型默认值
num_classes—80
hidden_dim—256
num_queries—300
feat_channels—[512, 1024, 2048]
feat_strides—[8, 16, 32]
num_levels—3
num_points—4
nhead—8
num_layers—6
dim_feedforward—1024
dropout—0.0
activation—'relu'
num_denoising—100
label_noise_ratio—0.5
box_noise_scale—1.0
learn_query_content—False
eval_spatial_size—None
eval_idx—-1
eps—0.01
aux_loss—True
cross_attn_method—'default'
query_select_method—'default'
reg_max—32
reg_scale—4.0
layer_scale—1
mlp_act—'relu'