IDEA-Research / Lite-DETR

[CVPR 2023] Official implementation of the paper "Lite DETR : An Interleaved Multi-Scale Encoder for Efficient DETR"
Apache License 2.0
182 stars 14 forks source link

I just use the kda tranformer, but some bugs appear #12

Open Originlightwkp opened 9 months ago

Originlightwkp commented 9 months ago

i add a main to the deformable_transformer.py ,and use right shape of the input. When i test the transformer,the follwing are

Traceback (most recent call last): File "D:\pycharmcode\Lite-DETR-main\models\dino\deformable_transformer.py", line 1339, in out = model(srcs,masks,refpoint_embed,pos_embeds,tgt) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "D:\pycharmcode\Lite-DETR-main\models\dino\deformable_transformer.py", line 362, in forward print(level_start_index[4 - self.enc_scale]) IndexError: index 1 is out of bounds for dimension 0 with size 1

i use enc_scale==3,but the level_start_index shape is torch.Size([1]),so this error happens. The follwing are my scipts, there is no change in other codes:

def build_my_deformable_transformer(): decoder_query_perturber = None

use_detached_boxes_dec_out = False

return DeformableTransformer(
    d_model=256,
    dropout=0.1,
    nhead=8,
    num_queries=900,
    dim_feedforward_enc=2048,
    num_encoder_layers=6,
    num_unicoder_layers=0,
    num_decoder_layers=6,
    normalize_before=False,
    return_intermediate_dec=True,
    query_dim=4,
    activation='relu',
    num_patterns=0,
    modulate_hw_attn=True,

    deformable_encoder=True,
    deformable_decoder=True,
    num_feature_levels=4,
    enc_n_points=4,
    dec_n_points=4,
    use_deformable_box_attn=False,
    box_attn_type= 'roi_align',

    learnable_tgt_init=True,
    decoder_query_perturber=decoder_query_perturber,

    add_channel_attention=False,
    add_pos_value=False,
    random_refpoints_xy= False,

    # two stage
    two_stage_type='standard', # ['no', 'standard', 'early']
    two_stage_pat_embed= 0,
    two_stage_add_query_num= 0,
    two_stage_learn_wh=False,
    two_stage_keep_all_tokens=False,
    dec_layer_number=None,
    rm_self_attn_layers=None,
    key_aware_type=None,
    layer_share_type=None,

    rm_detach=None,
    decoder_sa_type='sa',
    module_seq=['sa', 'ca', 'ffn'],

    embed_init_tgt=True,
    use_detached_boxes_dec_out=False,
    enc_scale=3,
    dim_feedforward_dec=2048,
    use_pytorch_version=False,
    value_proj_after=False,
    small_expand=False,
    num_expansion=3,
    deformable_use_checkpoint=False,
    same_loc=True,
    proj_key=False,
    key_aware=True,
)

if name == 'main':

.cuda()

srcs = torch.rand((2, 256, 144, 80)).cuda()
masks = torch.rand((2,144,80)).to(torch.bool).cuda()
refpoint_embed = torch.rand((2,900,4)).cuda()
pos_embeds = torch.rand((2,256,144,80)).cuda()
tgt = torch.rand((2,900,256)).cuda()
"""
      Input:
          - srcs: List of multi features [bs, ci, hi, wi]
          - masks: List of multi masks [bs, hi, wi]
          - refpoint_embed: [bs, num_dn, 4]. None in infer
          - pos_embeds: List of multi pos embeds [bs, ci, hi, wi]
          - tgt: [bs, num_dn, d_model]. None in infer

"""

model = build_my_deformable_transformer().cuda()
out = model(srcs,masks,refpoint_embed,pos_embeds,tgt)
print(len(out))
print(out[0].shape)

how can i fix it?