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"]
code: def __init__(
      self,
      spatial_dims: int,
      num_classes: int,
      num_anchors: int,
      feature_extractor: nn.Module,
      size_divisible: Sequence[int] | int = 1,
      use_list_output: bool = False,
  ):
      super().__init__()
  
      self.spatial_dims = look_up_option(
          spatial_dims, supported=[1, 2, 3]
      )
      self.num_classes = num_classes
      self.size_divisible = ensure_tuple_rep(
          size_divisible, self.spatial_dims
      )
      self.use_list_output = use_list_output
  
      if not hasattr(feature_extractor, "out_channels"):
          raise ValueError(
              "feature_extractor should contain an attribute out_channels "
              "specifying the number of output channels (assumed to be the "
              "same for all the levels)"
          )
      self.feature_extractor = feature_extractor
  
      self.feature_map_channels: int = (
          self.feature_extractor.out_channels
      )
      self.num_anchors = num_anchors
      self.classification_head = RetinaNetClassificationHead(
          self.feature_map_channels,
          self.num_anchors,
          self.num_classes,
          spatial_dims=self.spatial_dims,
      )
      self.regression_head = RetinaNetRegressionHead(
          self.feature_map_channels,
          self.num_anchors,
          spatial_dims=self.spatial_dims,
      )
  
      self.cls_key: str = "classification"
      self.box_reg_key: str = "box_regression"
  
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 1 to create a new RetinaNet object from inherited base classes: nn with example: obj = RetinaNet(spatial_dims, num_classes, num_anchors, feature_extractor, size_divisible, use_list_output)