class_docstr: Gated positional self-attention. This is what makes a ConViT a ConViT.
  The "gating" refers to lambda, the parameter that controls the relative
  contribution (i.e. gating) of positional vs. content-based attention in
  each head.
class_docstr_tok: ["Gated","positional","self-attention",".","This","is","what","makes","a","ConViT","a","ConViT",".","The","``","gating","''","refers","to","lambda",",","the","parameter","that","controls","the","relative","contribution","(","i.e",".","gating",")","of","positional","vs.","content-based","attention","in","each","head","."]
docstr: Used for visualizing and quantifying attention maps.
  Args:
      x: Input data
      return_map: Whether to return attention map or not
  
  Returns:
      dist: mean(attention distance weighted by attention magnitude)
      attn_map: heat map of attention values across input
docstr_tok: ["Used","for","visualizing","and","quantifying","attention","maps",".","Args",":","x",":","Input","data","return_map",":","Whether","to","return","attention","map","or","not","Returns",":","dist",":","mean","(","attention","distance","weighted","by","attention","magnitude",")","attn_map",":","heat","map","of","attention","values","across","input"]
code: def get_attention_map(self, x, return_map=False):
      """
      Used for visualizing and quantifying attention maps.
      Args:
          x: Input data
          return_map: Whether to return attention map or not
  
      Returns:
          dist: mean(attention distance weighted by attention magnitude)
          attn_map: heat map of attention values across input
  
      """
      attn_map = self.get_attention(x).mean(0)  # average over batch
      distances = self.rel_indices.squeeze()[:, :, -1] ** 0.5
      dist = torch.einsum(
          "nm,hnm->h", (distances, attn_map)
      ).mean()  # average over heads
      dist = dist.item() / distances.size(0)
      if return_map:
          return dist, attn_map
      else:
          return dist
  
imports: import copy
  import logging
  import math
  import torch
  import torch.nn
  from vissl.models.model_helpers import DropPath, to_2tuple, trunc_normal_
  from vissl.models.trunks import register_model_trunk
  from vissl.utils.hydra_config import AttrDict
label_desc: Use image node_id 5 for calling the GPSA obj's underlying member method code with example usage: obj.get_attention_map(x, return_map) and returns: dist,  attn_map, dist