docstr: anchors position in grid coordinate axis map into origin image
  计算预测特征图对应原始图像上的所有anchors的坐标
  Args:
      grid_sizes: 预测特征矩阵的height和width
      strides: 预测特征矩阵上一步对应原始图像上的步距
docstr_tok: ["anchors","position","in","grid","coordinate","axis","map","into","origin","image","\u8ba1\u7b97\u9884\u6d4b\u7279\u5f81\u56fe\u5bf9\u5e94\u539f\u59cb\u56fe\u50cf\u4e0a\u7684\u6240\u6709anchors\u7684\u5750\u6807","Args",":","grid_sizes",":","\u9884\u6d4b\u7279\u5f81\u77e9\u9635\u7684height\u548cwidth","strides",":","\u9884\u6d4b\u7279\u5f81\u77e9\u9635\u4e0a\u4e00\u6b65\u5bf9\u5e94\u539f\u59cb\u56fe\u50cf\u4e0a\u7684\u6b65\u8ddd"]
code: def grid_anchors(self, grid_sizes, strides):
      # type: (List[List[int]], List[List[Tensor]]) -> List[Tensor]
      """
      anchors position in grid coordinate axis map into origin image
      计算预测特征图对应原始图像上的所有anchors的坐标
      Args:
          grid_sizes: 预测特征矩阵的height和width
          strides: 预测特征矩阵上一步对应原始图像上的步距
      """
      anchors = []
      cell_anchors = self.cell_anchors
      assert cell_anchors is not None
  
      # 遍历每个预测特征层的grid_size，strides和cell_anchors
      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]
          # shape: [grid_width] 对应原图上的x坐标(列)
          shifts_x = (
              torch.arange(
                  0, grid_width, dtype=torch.float32, device=device
              )
              * stride_width
          )
          # shape: [grid_height] 对应原图上的y坐标(行)
          shifts_y = (
              torch.arange(
                  0, grid_height, dtype=torch.float32, device=device
              )
              * stride_height
          )
  
          # 计算预测特征矩阵上每个点对应原图上的坐标(anchors模板的坐标偏移量)
          # torch.meshgrid函数分别传入行坐标和列坐标，生成网格行坐标矩阵和网格列坐标矩阵
          # shape: [grid_height, grid_width]
          shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x)
          shift_x = shift_x.reshape(-1)
          shift_y = shift_y.reshape(-1)
  
          # 计算anchors坐标(xmin, ymin, xmax, ymax)在原图上的坐标偏移量
          # shape: [grid_width*grid_height, 4]
          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模板与原图上的坐标偏移量相加得到原图上所有anchors的坐标信息(shape不同时会使用广播机制)
          shifts_anchor = shifts.view(-1, 1, 4) + base_anchors.view(
              1, -1, 4
          )
          anchors.append(shifts_anchor.reshape(-1, 4))
  
      return anchors
  
imports: from typing import List, Optional, Dict, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  import torchvision
  from .None import det_utils
  from .None import boxes
  from .image_list import ImageList
label_desc: Use image node_id 5 for calling the AnchorsGenerator obj's underlying member method code with example usage: obj.grid_anchors(grid_sizes, strides) and returns: anchors