class_docstr: Deformable Transformer Decoder layer used in Deformable DETR.
  
  Described in: https://arxiv.org/abs/2010.04159.
class_docstr_tok: ["Deformable","Transformer","Decoder","layer","used","in","Deformable","DETR",".","Described","in",":","https",":","\/\/arxiv.org\/abs\/2010.04159","."]
code: def forward(
      self,
      tgt: Tensor,
      ref_points: Tensor,
      memory: Tensor,
      memory_spatial_shapes: list[tuple[int, int]],
      memory_level_start_index: Optional[list[int]] = None,
      attn_mask: Optional[Tensor] = None,
      memory_mask: Optional[Tensor] = None,
      query_pos_embed: Optional[Tensor] = None,
  ) -> Tensor:
      # TODO: rename variables because is confusing
      # self attention
      q = k = tgt + query_pos_embed
      out, _ = self.self_attn(q, k, value=tgt)
      tgt = self.norm1(tgt + self.dropout1(out))
  
      # cross attention
      out = self.cross_attn(
          tgt + query_pos_embed,
          ref_points,
          memory,
          memory_spatial_shapes,
      )
      tgt = self.norm2(tgt + self.dropout2(out))
  
      # ffn
      out = self.norm3(tgt + self.dropout4(self._ffn(tgt)))
  
      return out
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  from torch import nn
  from kornia.contrib.models.common import MLP, ConvNormAct
  from kornia.core import Module, Tensor, concatenate
label_desc: Use image node_id 3 for calling the TransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(tgt, ref_points, memory, memory_spatial_shapes, memory_level_start_index, attn_mask, memory_mask, query_pos_embed) and returns: out