docstr: compute anchor sizes
  Arguments:
      scales: sqrt(anchor_area)
      aspect_ratios: h/w ratios
      dtype: float32
      device: cpu/gpu
docstr_tok: ["compute","anchor","sizes","Arguments",":","scales",":","sqrt","(","anchor_area",")","aspect_ratios",":","h\/w","ratios","dtype",":","float32","device",":","cpu\/gpu"]
code: def generate_anchors(
      self,
      scales,
      aspect_ratios,
      dtype=torch.float32,
      device=torch.device("cpu"),
  ):
      # type: (List[int], List[float], torch.dtype, torch.device) -> Tensor
      """
      compute anchor sizes
      Arguments:
          scales: sqrt(anchor_area)
          aspect_ratios: h/w ratios
          dtype: float32
          device: cpu/gpu
      """
      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.0 / h_ratios
  
      # [r1, r2, r3]' * [s1, s2, s3]
      # number of elements is len(ratios)*len(scales)
      ws = (w_ratios[:, None] * scales[None, :]).view(-1)
      hs = (h_ratios[:, None] * scales[None, :]).view(-1)
  
      # left-top, right-bottom coordinate relative to anchor center(0, 0)
      # 生成的anchors模板都是以（0, 0）为中心的, shape [len(ratios)*len(scales), 4]
      base_anchors = torch.stack([-ws, -hs, ws, hs], dim=1) / 2
  
      return base_anchors.round()
  
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 2 for calling the AnchorsGenerator obj's underlying member method code with example usage: obj.generate_anchors(scales, aspect_ratios, dtype, device) and returns: base_anchors