class_docstr: Module that generates anchors for a set of feature maps and
  image sizes, inherited from :py:class:`~monai.apps.detection.networks.utils.anchor_utils.AnchorGenerator`
  
  The module support computing anchors at multiple base anchor shapes
  per feature map.
  
  ``feature_map_scales`` should have the same number of elements with the number of feature maps.
  
  base_anchor_shapes can have an arbitrary number of elements.
  For 2D images, each element represents anchor width and height [w,h].
  For 2D images, each element represents anchor width, height, and depth [w,h,d].
  
  AnchorGenerator will output a set of ``len(base_anchor_shapes)`` anchors
  per spatial location for feature map ``i``.
  
  Args:
      feature_map_scales: scale of anchors for each feature map, i.e., each output level of
          the feature pyramid network (FPN). ``len(feature_map_scales)`` is the number of feature maps.
          ``scale[i]*base_anchor_shapes`` represents the anchor shapes for feature map ``i``.
      base_anchor_shapes: a sequence which represents several anchor shapes for one feature map.
          For N-D images, it is a Sequence of N value Sequence.
      indexing: choose from {'xy', 'ij'}, optional
          Cartesian ('xy') or matrix ('ij', default) indexing of output.
          Cartesian ('xy') indexing swaps axis 0 and 1, which is the setting inside torchvision.
          matrix ('ij', default) indexing keeps the original axis not changed.
          See also indexing in https://pytorch.org/docs/stable/generated/torch.meshgrid.html
  
  Example:
      .. code-block:: python
  
          # 2D example inputs for a 2-level feature maps
          feature_map_scales = (1, 2)
          base_anchor_shapes = ((10, 10), (6, 12), (12, 6))
          anchor_generator = AnchorGeneratorWithAnchorShape(feature_map_scales, base_anchor_shapes)
  
          # 3D example inputs for a 2-level feature maps
          feature_map_scales = (1, 2)
          base_anchor_shapes = ((10, 10, 10), (12, 12, 8), (10, 10, 6), (16, 16, 10))
          anchor_generator = AnchorGeneratorWithAnchorShape(feature_map_scales, base_anchor_shapes)
class_docstr_tok: ["Module","that","generates","anchors","for","a","set","of","feature","maps","and","image","sizes",",","inherited","from",":","py",":","class",":","`","~monai.apps.detection.networks.utils.anchor_utils.AnchorGenerator","`","The","module","support","computing","anchors","at","multiple","base","anchor","shapes","per","feature","map",".","``","feature_map_scales","``","should","have","the","same","number","of","elements","with","the","number","of","feature","maps",".","base_anchor_shapes","can","have","an","arbitrary","number","of","elements",".","For","2D","images",",","each","element","represents","anchor","width","and","height","[","w",",","h","]",".","For","2D","images",",","each","element","represents","anchor","width",",","height",",","and","depth","[","w",",","h",",","d","]",".","AnchorGenerator","will","output","a","set","of","``","len","(","base_anchor_shapes",")","``","anchors","per","spatial","location","for","feature","map","``","i","``",".","Args",":","feature_map_scales",":","scale","of","anchors","for","each","feature","map",",","i.e.",",","each","output","level","of","the","feature","pyramid","network","(","FPN",")",".","``","len","(","feature_map_scales",")","``","is","the","number","of","feature","maps",".","``","scale","[","i","]","*","base_anchor_shapes","``","represents","the","anchor","shapes","for","feature","map","``","i","``",".","base_anchor_shapes",":","a","sequence","which","represents","several","anchor","shapes","for","one","feature","map",".","For","N-D","images",",","it","is","a","Sequence","of","N","value","Sequence",".","indexing",":","choose","from","{","'xy","'",",","'ij","'","}",",","optional","Cartesian","(","'xy","'",")","or","matrix","(","'ij","'",",","default",")","indexing","of","output",".","Cartesian","(","'xy","'",")","indexing","swaps","axis","0","and","1",",","which","is","the","setting","inside","torchvision",".","matrix","(","'ij","'",",","default",")","indexing","keeps","the","original","axis","not","changed",".","See","also","indexing","in","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.meshgrid.html","Example",":","..","code-block",":",":","python","#","2D","example","inputs","for","a","2-level","feature","maps","feature_map_scales","=","(","1",",","2",")","base_anchor_shapes","=","(","(","10",",","10",")",",","(","6",",","12",")",",","(","12",",","6",")",")","anchor_generator","=","AnchorGeneratorWithAnchorShape","(","feature_map_scales",",","base_anchor_shapes",")","#","3D","example","inputs","for","a","2-level","feature","maps","feature_map_scales","=","(","1",",","2",")","base_anchor_shapes","=","(","(","10",",","10",",","10",")",",","(","12",",","12",",","8",")",",","(","10",",","10",",","6",")",",","(","16",",","16",",","10",")",")","anchor_generator","=","AnchorGeneratorWithAnchorShape","(","feature_map_scales",",","base_anchor_shapes",")"]
docstr: Compute cell anchor shapes at multiple sizes and aspect ratios for the current feature map.
  
  Args:
      anchor_shapes: [w, h] or [w, h, d], sized (N, spatial_dims),
          represents N anchor shapes for the current feature map.
      dtype: target data type of the output Tensor.
      device: target device to put the output Tensor data.
  
  Returns:
      For 2D images, returns [-w/2, -h/2, w/2, h/2];
      For 3D images, returns [-w/2, -h/2, -d/2, w/2, h/2, d/2]
docstr_tok: ["Compute","cell","anchor","shapes","at","multiple","sizes","and","aspect","ratios","for","the","current","feature","map",".","Args",":","anchor_shapes",":","[","w",",","h","]","or","[","w",",","h",",","d","]",",","sized","(","N",",","spatial_dims",")",",","represents","N","anchor","shapes","for","the","current","feature","map",".","dtype",":","target","data","type","of","the","output","Tensor",".","device",":","target","device","to","put","the","output","Tensor","data",".","Returns",":","For","2D","images",",","returns","[","-w\/2",",","-h\/2",",","w\/2",",","h\/2","]",";","For","3D","images",",","returns","[","-w\/2",",","-h\/2",",","-d\/2",",","w\/2",",","h\/2",",","d\/2","]"]
code: def generate_anchors_using_shape(
      anchor_shapes: torch.Tensor,
      dtype: torch.dtype = torch.float32,
      device: torch.device | None = None,
  ) -> torch.Tensor:
      """
      Compute cell anchor shapes at multiple sizes and aspect ratios for the current feature map.
  
      Args:
          anchor_shapes: [w, h] or [w, h, d], sized (N, spatial_dims),
              represents N anchor shapes for the current feature map.
          dtype: target data type of the output Tensor.
          device: target device to put the output Tensor data.
  
      Returns:
          For 2D images, returns [-w/2, -h/2, w/2, h/2];
          For 3D images, returns [-w/2, -h/2, -d/2, w/2, h/2, d/2]
      """
      half_anchor_shapes = anchor_shapes / 2.0
      base_anchors = torch.cat(
          [-half_anchor_shapes, half_anchor_shapes], dim=1
      )
      return base_anchors.round().to(dtype=dtype, device=device)
  
file_path: MONAI/monai/apps/detection/utils/anchor_utils.py
imports: from __future__ import annotations
  from typing import List, Sequence
  import torch
  from torch import Tensor, nn
  from monai.utils import ensure_tuple
  from monai.utils.misc import issequenceiterable
  from monai.utils.module import look_up_option
label_desc: Use image node_id 2 for calling the AnchorGeneratorWithAnchorShape obj's underlying member method code with example usage: obj.generate_anchors_using_shape(anchor_shapes, dtype, device) and returns: base_anchors