code: def _get_decoder_input(
      self,
      memory: Tensor,
      spatial_shapes: list[tuple[int, int]],
      denoising_class: Optional[Tensor] = None,
      denoising_bbox_unact: Optional[Tensor] = None,
  ) -> tuple[Tensor, Tensor, Tensor, Tensor]:
      # prepare input for decoder
      # TODO: cache anchors and valid_mask as buffers
      anchors, valid_mask = self._generate_anchors(
          spatial_shapes, device=memory.device, dtype=memory.dtype
      )
  
      # memory = torch.where(valid_mask, memory, 0)
      memory = (
          valid_mask.to(memory) * memory
      )  # TODO fix type error for onnx export
  
      output_memory = self.enc_output(memory)
  
      enc_outputs_class = self.enc_score_head(output_memory)
      enc_outputs_coord_unact = (
          self.enc_bbox_head(output_memory) + anchors
      )
  
      _, topk_ind = torch.topk(
          enc_outputs_class.max(-1).values, self.num_queries, dim=1
      )
  
      reference_points_unact = enc_outputs_coord_unact.gather(
          dim=1,
          index=topk_ind.unsqueeze(-1).repeat(
              1, 1, enc_outputs_coord_unact.shape[-1]
          ),
      )
  
      enc_topk_bboxes = torch.sigmoid(reference_points_unact)
      if denoising_bbox_unact is not None:
          reference_points_unact = torch.concat(
              [denoising_bbox_unact, reference_points_unact], 1
          )
  
      enc_topk_logits = enc_outputs_class.gather(
          dim=1,
          index=topk_ind.unsqueeze(-1).repeat(
              1, 1, enc_outputs_class.shape[-1]
          ),
      )
  
      # extract region features
      target = output_memory.gather(
          dim=1,
          index=topk_ind.unsqueeze(-1).repeat(
              1, 1, output_memory.shape[-1]
          ),
      )
  
      if denoising_class is not None:
          target = torch.concat([denoising_class, target], 1)
  
      return (
          target.detach(),
          reference_points_unact.detach(),
          enc_topk_bboxes,
          enc_topk_logits,
      )
  
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 4 for calling the RTDETRHead obj's underlying member method code with example usage: obj._get_decoder_input(memory, spatial_shapes, denoising_class, denoising_bbox_unact) and returns: target,  reference_points_unact,  enc_topk_bboxes,  enc_topk_logits