Skip to content

Conversation

@artemisp
Copy link

artemisp added 2 commits July 16, 2024 18:57
Quick patch to avoid index out of bounds error for some images.
Repeat pad logits in case there are not enough features.
Copy link

@kusstox kusstox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If missing is longer than topk_logits.shape[-1], you will run in the same issue again. To fix it, we should embed it into a while clause

@Parul-Gupta
Copy link

The following code snippet covers the case where missing is longer than topk_logits.shape[-1]

if topk > topk_logits.shape[-1]:
    missing =  topk-topk_logits.shape[-1]
    num_repeats = missing//topk_logits.shape[-1]
    if num_repeats>0:
        missing = missing - num_repeats*topk_logits.shape[-1]
        repeat_pad1 = topk_logits.clone().detach().repeat(1, num_repeats)
        repeat_pad = topk_logits.clone().detach()[:,-missing:]
        topk_logits = torch.cat([topk_logits, repeat_pad1, repeat_pad], dim=-1)

        repeat_pad1 = output_proposals.clone().detach().repeat(1, num_repeats, 1)
        repeat_pad = output_proposals.clone().detach()[:,-missing:, :]
        output_proposals = torch.cat([output_proposals, repeat_pad1, repeat_pad], dim=-2)

        repeat_pad1 = enc_outputs_coord_unselected.clone().detach().repeat(1, num_repeats, 1)
        repeat_pad = enc_outputs_coord_unselected.clone().detach()[:,-missing:, :]
        enc_outputs_coord_unselected = torch.cat([enc_outputs_coord_unselected, repeat_pad1, repeat_pad], dim=-2)

        repeat_pad1 = output_memory.clone().detach().repeat(1, num_repeats, 1)
        repeat_pad = output_memory.clone().detach()[:,-missing:, :]
        output_memory = torch.cat([output_memory, repeat_pad1, repeat_pad], dim=-2)
    else:
        repeat_pad = topk_logits.clone().detach()[:,-missing:]
        topk_logits = torch.cat([topk_logits, repeat_pad], dim=-1)

        repeat_pad = output_proposals.clone().detach()[:,-missing:, :]
        output_proposals = torch.cat([output_proposals, repeat_pad], dim=-2)

        repeat_pad = enc_outputs_coord_unselected.clone().detach()[:,-missing:, :]
        enc_outputs_coord_unselected = torch.cat([enc_outputs_coord_unselected, repeat_pad], dim=-2)

        repeat_pad = output_memory.clone().detach()[:,-missing:, :]
        output_memory = torch.cat([output_memory, repeat_pad], dim=-2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants