class_docstr: The network used in RetinaNet.
  
  It takes an image tensor as inputs, and outputs either 1) a dictionary ``head_outputs``.
  ``head_outputs[self.cls_key]`` is the predicted classification maps, a list of Tensor.
  ``head_outputs[self.box_reg_key]`` is the predicted box regression maps, a list of Tensor.
  or 2) a list of 2N tensors ``head_outputs``, with first N tensors being the predicted
  classification maps and second N tensors being the predicted box regression maps.
  
  Args:
      spatial_dims: number of spatial dimensions of the images. We support both 2D and 3D images.
      num_classes: number of output classes of the model (excluding the background).
      num_anchors: number of anchors at each location.
      feature_extractor: a network that outputs feature maps from the input images,
          each feature map corresponds to a different resolution.
          Its output can have a format of Tensor, Dict[Any, Tensor], or Sequence[Tensor].
          It can be the output of ``resnet_fpn_feature_extractor(*args, **kwargs)``.
      size_divisible: the spatial size of the network input should be divisible by size_divisible,
          decided by the feature_extractor.
      use_list_output: default False. If False, the network outputs a dictionary ``head_outputs``,
          ``head_outputs[self.cls_key]`` is the predicted classification maps, a list of Tensor.
          ``head_outputs[self.box_reg_key]`` is the predicted box regression maps, a list of Tensor.
          If True, the network outputs a list of 2N tensors ``head_outputs``, with first N tensors being
          the predicted classification maps and second N tensors being the predicted box regression maps.
  
  Example:
  
      .. code-block:: python
  
          from monai.networks.nets import resnet
          spatial_dims = 3  # 3D network
          conv1_t_stride = (2,2,1)  # stride of first convolutional layer in backbone
          backbone = resnet.ResNet(
              spatial_dims = spatial_dims,
              block = resnet.ResNetBottleneck,
              layers = [3, 4, 6, 3],
              block_inplanes = resnet.get_inplanes(),
              n_input_channels= 1,
              conv1_t_stride = conv1_t_stride,
              conv1_t_size = (7,7,7),
          )
          # This feature_extractor outputs 4-level feature maps.
          # number of output feature maps is len(returned_layers)+1
          returned_layers = [1,2,3]  # returned layer from feature pyramid network
          feature_extractor = resnet_fpn_feature_extractor(
              backbone = backbone,
              spatial_dims = spatial_dims,
              pretrained_backbone = False,
              trainable_backbone_layers = None,
              returned_layers = returned_layers,
          )
          # This feature_extractor requires input image spatial size
          # to be divisible by (32, 32, 16).
          size_divisible = tuple(2*s*2**max(returned_layers) for s in conv1_t_stride)
          model = RetinaNet(
              spatial_dims = spatial_dims,
              num_classes = 5,
              num_anchors = 6,
              feature_extractor=feature_extractor,
              size_divisible = size_divisible,
          ).to(device)
          result = model(torch.rand(2, 1, 128,128,128))
          cls_logits_maps = result["classification"]  # a list of len(returned_layers)+1 Tensor
          box_regression_maps = result["box_regression"]  # a list of len(returned_layers)+1 Tensor
class_docstr_tok: ["The","network","used","in","RetinaNet",".","It","takes","an","image","tensor","as","inputs",",","and","outputs","either","1",")","a","dictionary","``","head_outputs","``",".","``","head_outputs","[","self.cls_key","]","``","is","the","predicted","classification","maps",",","a","list","of","Tensor",".","``","head_outputs","[","self.box_reg_key","]","``","is","the","predicted","box","regression","maps",",","a","list","of","Tensor",".","or","2",")","a","list","of","2N","tensors","``","head_outputs","``",",","with","first","N","tensors","being","the","predicted","classification","maps","and","second","N","tensors","being","the","predicted","box","regression","maps",".","Args",":","spatial_dims",":","number","of","spatial","dimensions","of","the","images",".","We","support","both","2D","and","3D","images",".","num_classes",":","number","of","output","classes","of","the","model","(","excluding","the","background",")",".","num_anchors",":","number","of","anchors","at","each","location",".","feature_extractor",":","a","network","that","outputs","feature","maps","from","the","input","images",",","each","feature","map","corresponds","to","a","different","resolution",".","Its","output","can","have","a","format","of","Tensor",",","Dict","[","Any",",","Tensor","]",",","or","Sequence","[","Tensor","]",".","It","can","be","the","output","of","``","resnet_fpn_feature_extractor","(","*","args",",","*","*","kwargs",")","``",".","size_divisible",":","the","spatial","size","of","the","network","input","should","be","divisible","by","size_divisible",",","decided","by","the","feature_extractor",".","use_list_output",":","default","False",".","If","False",",","the","network","outputs","a","dictionary","``","head_outputs","``",",","``","head_outputs","[","self.cls_key","]","``","is","the","predicted","classification","maps",",","a","list","of","Tensor",".","``","head_outputs","[","self.box_reg_key","]","``","is","the","predicted","box","regression","maps",",","a","list","of","Tensor",".","If","True",",","the","network","outputs","a","list","of","2N","tensors","``","head_outputs","``",",","with","first","N","tensors","being","the","predicted","classification","maps","and","second","N","tensors","being","the","predicted","box","regression","maps",".","Example",":","..","code-block",":",":","python","from","monai.networks.nets","import","resnet","spatial_dims","=","3","#","3D","network","conv1_t_stride","=","(","2,2,1",")","#","stride","of","first","convolutional","layer","in","backbone","backbone","=","resnet.ResNet","(","spatial_dims","=","spatial_dims",",","block","=","resnet.ResNetBottleneck",",","layers","=","[","3",",","4",",","6",",","3","]",",","block_inplanes","=","resnet.get_inplanes","(",")",",","n_input_channels=","1",",","conv1_t_stride","=","conv1_t_stride",",","conv1_t_size","=","(","7,7,7",")",",",")","#","This","feature_extractor","outputs","4-level","feature","maps",".","#","number","of","output","feature","maps","is","len","(","returned_layers",")","+1","returned_layers","=","[","1,2,3","]","#","returned","layer","from","feature","pyramid","network","feature_extractor","=","resnet_fpn_feature_extractor","(","backbone","=","backbone",",","spatial_dims","=","spatial_dims",",","pretrained_backbone","=","False",",","trainable_backbone_layers","=","None",",","returned_layers","=","returned_layers",",",")","#","This","feature_extractor","requires","input","image","spatial","size","#","to","be","divisible","by","(","32",",","32",",","16",")",".","size_divisible","=","tuple","(","2","*","s","*","2","*","*","max","(","returned_layers",")","for","s","in","conv1_t_stride",")","model","=","RetinaNet","(","spatial_dims","=","spatial_dims",",","num_classes","=","5",",","num_anchors","=","6",",","feature_extractor=feature_extractor",",","size_divisible","=","size_divisible",",",")",".to","(","device",")","result","=","model","(","torch.rand","(","2",",","1",",","128,128,128",")",")","cls_logits_maps","=","result","[","``","classification","''","]","#","a","list","of","len","(","returned_layers",")","+1","Tensor","box_regression_maps","=","result","[","``","box_regression","''","]","#","a","list","of","len","(","returned_layers",")","+1","Tensor"]
docstr: It takes an image tensor as inputs, and outputs predicted classification maps
  and predicted box regression maps in ``head_outputs``.
  
  Args:
      images: input images, sized (B, img_channels, H, W) or (B, img_channels, H, W, D).
  
  Return:
      1) If self.use_list_output is False, output a dictionary ``head_outputs`` with
      keys including self.cls_key and self.box_reg_key.
      ``head_outputs[self.cls_key]`` is the predicted classification maps, a list of Tensor.
      ``head_outputs[self.box_reg_key]`` is the predicted box regression maps, a list of Tensor.
      2) if self.use_list_output is True, outputs a list of 2N tensors ``head_outputs``, with first N tensors being
      the predicted classification maps and second N tensors being the predicted box regression maps.
docstr_tok: ["It","takes","an","image","tensor","as","inputs",",","and","outputs","predicted","classification","maps","and","predicted","box","regression","maps","in","``","head_outputs","``",".","Args",":","images",":","input","images",",","sized","(","B",",","img_channels",",","H",",","W",")","or","(","B",",","img_channels",",","H",",","W",",","D",")",".","Return",":","1",")","If","self.use_list_output","is","False",",","output","a","dictionary","``","head_outputs","``","with","keys","including","self.cls_key","and","self.box_reg_key",".","``","head_outputs","[","self.cls_key","]","``","is","the","predicted","classification","maps",",","a","list","of","Tensor",".","``","head_outputs","[","self.box_reg_key","]","``","is","the","predicted","box","regression","maps",",","a","list","of","Tensor",".","2",")","if","self.use_list_output","is","True",",","outputs","a","list","of","2N","tensors","``","head_outputs","``",",","with","first","N","tensors","being","the","predicted","classification","maps","and","second","N","tensors","being","the","predicted","box","regression","maps","."]
code: def forward(self, images: Tensor) -> Any:
      """
      It takes an image tensor as inputs, and outputs predicted classification maps
      and predicted box regression maps in ``head_outputs``.
  
      Args:
          images: input images, sized (B, img_channels, H, W) or (B, img_channels, H, W, D).
  
      Return:
          1) If self.use_list_output is False, output a dictionary ``head_outputs`` with
          keys including self.cls_key and self.box_reg_key.
          ``head_outputs[self.cls_key]`` is the predicted classification maps, a list of Tensor.
          ``head_outputs[self.box_reg_key]`` is the predicted box regression maps, a list of Tensor.
          2) if self.use_list_output is True, outputs a list of 2N tensors ``head_outputs``, with first N tensors being
          the predicted classification maps and second N tensors being the predicted box regression maps.
  
      """
      # compute features maps list from the input images.
      features = self.feature_extractor(images)
      if isinstance(features, Tensor):
          feature_maps = [features]
      elif torch.jit.isinstance(features, Dict[str, Tensor]):
          feature_maps = list(features.values())
      else:
          feature_maps = list(features)
  
      if not isinstance(feature_maps[0], Tensor):
          raise ValueError(
              "feature_extractor output format must be Tensor, Dict[str, Tensor], or Sequence[Tensor]."
          )
  
      # compute classification and box regression maps from the feature maps
      # expandable for mask prediction in the future
  
      if not self.use_list_output:
          # output dict
          head_outputs = {
              self.cls_key: self.classification_head(feature_maps)
          }
          head_outputs[self.box_reg_key] = self.regression_head(
              feature_maps
          )
          return head_outputs
      else:
          # output list of tensor, first half is classification, second half is box regression
          head_outputs_sequence = self.classification_head(
              feature_maps
          ) + self.regression_head(feature_maps)
          return head_outputs_sequence
  
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 RetinaNet obj's underlying member method code with example usage: obj.forward(images) and returns: head_outputs, head_outputs_sequence