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 grid_anchors(
      self, grid_sizes: List[List[int]], strides: List[List[Tensor]]
  ) -> List[Tensor]:
      anchors = []
      cell_anchors = self.cell_anchors
      torch._assert(
          cell_anchors is not None, "cell_anchors should not be None"
      )
      torch._assert(
          len(grid_sizes) == len(strides) == len(cell_anchors),
          "Anchors should be Tuple[Tuple[int]] because each feature "
          "map could potentially have different sizes and aspect ratios. "
          "There needs to be a match between the number of "
          "feature maps passed and the number of sizes / aspect ratios specified.",
      )
  
      for size, stride, base_anchors in zip(
          grid_sizes, strides, cell_anchors
      ):
          grid_height, grid_width = size
          stride_height, stride_width = stride
          device = base_anchors.device
  
          # For output anchor, compute [x_center, y_center, x_center, y_center]
          shifts_x = (
              torch.arange(
                  0, grid_width, dtype=torch.int32, device=device
              )
              * stride_width
          )
          shifts_y = (
              torch.arange(
                  0, grid_height, dtype=torch.int32, device=device
              )
              * stride_height
          )
          shift_y, shift_x = torch.meshgrid(
              shifts_y, shifts_x, indexing="ij"
          )
          shift_x = shift_x.reshape(-1)
          shift_y = shift_y.reshape(-1)
          shifts = torch.stack(
              (shift_x, shift_y, shift_x, shift_y), dim=1
          )
  
          # For every (base anchor, output anchor) pair,
          # offset each zero-centered base anchor by the center of the output anchor.
          anchors.append(
              (
                  shifts.view(-1, 1, 4) + base_anchors.view(1, -1, 4)
              ).reshape(-1, 4)
          )
  
      return anchors
  
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 5 for calling the AnchorGenerator obj's underlying member method code with example usage: obj.grid_anchors(grid_sizes, strides) and returns: anchors