class_docstr: A regression head for use in RetinaNet.
  
  This head takes a list of feature maps as inputs, and outputs a list of box regression maps.
  Each output box regression map has same spatial size with the corresponding input feature map,
  and the number of output channel is num_anchors * 2 * spatial_dims.
  
  Args:
      in_channels: number of channels of the input feature
      num_anchors: number of anchors to be predicted
      spatial_dims: spatial dimension of the network, should be 2 or 3.
class_docstr_tok: ["A","regression","head","for","use","in","RetinaNet",".","This","head","takes","a","list","of","feature","maps","as","inputs",",","and","outputs","a","list","of","box","regression","maps",".","Each","output","box","regression","map","has","same","spatial","size","with","the","corresponding","input","feature","map",",","and","the","number","of","output","channel","is","num_anchors","*","2","*","spatial_dims",".","Args",":","in_channels",":","number","of","channels","of","the","input","feature","num_anchors",":","number","of","anchors","to","be","predicted","spatial_dims",":","spatial","dimension","of","the","network",",","should","be","2","or","3","."]
docstr: It takes a list of feature maps as inputs, and outputs a list of box regression maps.
  Each output box regression map has same spatial size with the corresponding input feature map,
  and the number of output channel is num_anchors * 2 * spatial_dims.
  
  Args:
      x: list of feature map, x[i] is a (B, in_channels, H_i, W_i) or (B, in_channels, H_i, W_i, D_i) Tensor.
  
  Return:
      box_regression_maps, list of box regression map. cls_logits_maps[i] is a
      (B, num_anchors * 2 * spatial_dims, H_i, W_i) or (B, num_anchors * 2 * spatial_dims, H_i, W_i, D_i) Tensor.
docstr_tok: ["It","takes","a","list","of","feature","maps","as","inputs",",","and","outputs","a","list","of","box","regression","maps",".","Each","output","box","regression","map","has","same","spatial","size","with","the","corresponding","input","feature","map",",","and","the","number","of","output","channel","is","num_anchors","*","2","*","spatial_dims",".","Args",":","x",":","list","of","feature","map",",","x","[","i","]","is","a","(","B",",","in_channels",",","H_i",",","W_i",")","or","(","B",",","in_channels",",","H_i",",","W_i",",","D_i",")","Tensor",".","Return",":","box_regression_maps",",","list","of","box","regression","map",".","cls_logits_maps","[","i","]","is","a","(","B",",","num_anchors","*","2","*","spatial_dims",",","H_i",",","W_i",")","or","(","B",",","num_anchors","*","2","*","spatial_dims",",","H_i",",","W_i",",","D_i",")","Tensor","."]
code: def forward(self, x: list[Tensor]) -> list[Tensor]:
      """
      It takes a list of feature maps as inputs, and outputs a list of box regression maps.
      Each output box regression map has same spatial size with the corresponding input feature map,
      and the number of output channel is num_anchors * 2 * spatial_dims.
  
      Args:
          x: list of feature map, x[i] is a (B, in_channels, H_i, W_i) or (B, in_channels, H_i, W_i, D_i) Tensor.
  
      Return:
          box_regression_maps, list of box regression map. cls_logits_maps[i] is a
          (B, num_anchors * 2 * spatial_dims, H_i, W_i) or (B, num_anchors * 2 * spatial_dims, H_i, W_i, D_i) Tensor.
  
      """
      box_regression_maps = []
  
      if isinstance(x, Tensor):
          feature_maps = [x]
      else:
          feature_maps = x
  
      for features in feature_maps:
          box_regression = self.conv(features)
          box_regression = self.bbox_reg(box_regression)
  
          box_regression_maps.append(box_regression)
  
          if (
              torch.isnan(box_regression).any()
              or torch.isinf(box_regression).any()
          ):
              if torch.is_grad_enabled():
                  raise ValueError("box_regression is NaN or Inf.")
              else:
                  warnings.warn("box_regression is NaN or Inf.")
  
      return box_regression_maps
  
imports: from __future__ import annotations
  import math
  import warnings
  from collections.abc import Callable, Sequence
  from typing import Any, Dict
  import torch
  from torch import Tensor, nn
  from monai.networks.blocks.backbone_fpn_utils import BackboneWithFPN, _resnet_fpn_extractor
  from monai.networks.layers.factories import Conv
  from monai.networks.nets import resnet
  from monai.utils import ensure_tuple_rep, look_up_option, optional_import
label_desc: Use image node_id 2 for calling the RetinaNetRegressionHead obj's underlying member method code with example usage: obj.forward(x) and returns: box_regression_maps