class_docstr: This is a 2D attention module, which only returns the attention softmax (no multiplication by value)
class_docstr_tok: ["This","is","a","2D","attention","module",",","which","only","returns","the","attention","softmax","(","no","multiplication","by","value",")"]
code: def __init__(
      self, query_dim, hidden_dim, num_heads, dropout=0.0, bias=True
  ):
      super().__init__()
      self.num_heads = num_heads
      self.hidden_dim = hidden_dim
      self.dropout = nn.Dropout(dropout)
  
      self.q_linear = nn.Linear(query_dim, hidden_dim, bias=bias)
      self.k_linear = nn.Linear(query_dim, hidden_dim, bias=bias)
  
      nn.init.zeros_(self.k_linear.bias)
      nn.init.zeros_(self.q_linear.bias)
      nn.init.xavier_uniform_(self.k_linear.weight)
      nn.init.xavier_uniform_(self.q_linear.weight)
      self.normalize_fact = float(hidden_dim / self.num_heads) ** -0.5
  
imports: import io
  from collections import defaultdict
  from typing import List, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from PIL import Image
  import util.box_ops
  from util.misc import NestedTensor, interpolate, nested_tensor_from_tensor_list
label_desc: Use image node_id 1 to create a new MHAttentionMap object from inherited base classes: nn with example: obj = MHAttentionMap(query_dim, hidden_dim, num_heads, dropout, bias)