class_docstr: Module that generates anchors for a set of feature maps and
  image sizes.
  
  The module support computing anchors at multiple sizes and aspect ratios
  per feature map. This module assumes aspect ratio = height / width for
  each anchor.
  
  sizes and aspect_ratios should have the same number of elements, and it should
  correspond to the number of feature maps.
  
  sizes[i] and aspect_ratios[i] can have an arbitrary number of elements,
  and AnchorGenerator will output a set of sizes[i] * aspect_ratios[i] anchors
  per spatial location for feature map i.
  
  Args:
      sizes (Tuple[Tuple[int]]):
      aspect_ratios (Tuple[Tuple[float]]):
class_docstr_tok: ["Module","that","generates","anchors","for","a","set","of","feature","maps","and","image","sizes",".","The","module","support","computing","anchors","at","multiple","sizes","and","aspect","ratios","per","feature","map",".","This","module","assumes","aspect","ratio","=","height","\/","width","for","each","anchor",".","sizes","and","aspect_ratios","should","have","the","same","number","of","elements",",","and","it","should","correspond","to","the","number","of","feature","maps",".","sizes","[","i","]","and","aspect_ratios","[","i","]","can","have","an","arbitrary","number","of","elements",",","and","AnchorGenerator","will","output","a","set","of","sizes","[","i","]","*","aspect_ratios","[","i","]","anchors","per","spatial","location","for","feature","map","i.","Args",":","sizes","(","Tuple","[","Tuple","[","int","]","]",")",":","aspect_ratios","(","Tuple","[","Tuple","[","float","]","]",")",":"]
code: def generate_anchors(
      self,
      scales: List[int],
      aspect_ratios: List[float],
      dtype: torch.dtype = torch.float32,
      device: torch.device = torch.device("cpu"),
  ) -> Tensor:
      scales = torch.as_tensor(scales, dtype=dtype, device=device)
      aspect_ratios = torch.as_tensor(
          aspect_ratios, dtype=dtype, device=device
      )
      h_ratios = torch.sqrt(aspect_ratios)
      w_ratios = 1 / h_ratios
  
      ws = (w_ratios[:, None] * scales[None, :]).view(-1)
      hs = (h_ratios[:, None] * scales[None, :]).view(-1)
  
      base_anchors = torch.stack([-ws, -hs, ws, hs], dim=1) / 2
      return base_anchors.round()
  
imports: import math
  from typing import List, Optional
  import torch
  from torch import nn, Tensor
  from .image_list import ImageList
label_desc: Use image node_id 2 for calling the AnchorGenerator obj's underlying member method code with example usage: obj.generate_anchors(scales, aspect_ratios, dtype, device) and returns: base_anchors