class_docstr: Multi-scale Deformable Attention used in Deformable DETR.
  
  Described in https://arxiv.org/abs/2010.04159.
class_docstr_tok: ["Multi-scale","Deformable","Attention","used","in","Deformable","DETR",".","Described","in","https",":","\/\/arxiv.org\/abs\/2010.04159","."]
code: def __init__(
      self,
      embed_dim: int,
      num_heads: int,
      num_levels: int,
      num_points: int,
  ) -> None:
      super().__init__()
      self.num_heads = num_heads
      self.num_levels = num_levels
      self.num_points = num_points
      self.total_points = num_heads * num_levels * num_points
  
      self.head_dim = embed_dim // num_heads
      # KORNIA_CHECK not working with onnx
      # assert self.head_dim * num_heads == embed_dim, "embed_dim must be divisible by num_heads"
  
      self.sampling_offsets = nn.Linear(
          embed_dim, self.total_points * 2
      )
      self.attention_weights = nn.Linear(embed_dim, self.total_points)
      self.value_proj = nn.Linear(embed_dim, embed_dim)
      self.output_proj = nn.Linear(embed_dim, embed_dim)
  
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 1 to create a new MultiScaleDeformableAttention object from inherited base classes: Module with example: obj = MultiScaleDeformableAttention(embed_dim, num_heads, num_levels, num_points)