code: def resnet_fpn_feature_extractor(
      backbone: resnet.ResNet,
      spatial_dims: int,
      pretrained_backbone: bool = False,
      returned_layers: Sequence[int] = (1, 2, 3),
      trainable_backbone_layers: int | None = None,
  ) -> BackboneWithFPN:
      """
      Constructs a feature extractor network with a ResNet-FPN backbone, used as feature_extractor in RetinaNet.
  
      Reference: `"Focal Loss for Dense Object Detection" <https://arxiv.org/abs/1708.02002>`_.
  
      The returned feature_extractor network takes an image tensor as inputs,
      and outputs a dictionary that maps string to the extracted feature maps (Tensor).
  
      The input to the returned feature_extractor is expected to be a list of tensors,
      each of shape ``[C, H, W]`` or ``[C, H, W, D]``,
      one for each image. Different images can have different sizes.
  
  
      Args:
          backbone: a ResNet model, used as backbone.
          spatial_dims: number of spatial dimensions of the images. We support both 2D and 3D images.
          pretrained_backbone: whether the backbone has been pre-trained.
          returned_layers: returned layers to extract feature maps. Each returned layer should be in the range [1,4].
              len(returned_layers)+1 will be the number of extracted feature maps.
              There is an extra maxpooling layer LastLevelMaxPool() appended.
          trainable_backbone_layers: number of trainable (not frozen) resnet layers starting from final block.
              Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable.
              When pretrained_backbone is False, this value is set to be 5.
              When pretrained_backbone is True, if ``None`` is passed (the default) this value is set to 3.
  
      Example:
  
          .. code-block:: python
  
              from monai.networks.nets import resnet
              spatial_dims = 3 # 3D network
              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 = (2,2,1),
                  conv1_t_size = (7,7,7),
              )
              # This feature_extractor outputs 4-level feature maps.
              # number of output feature maps is len(returned_layers)+1
              feature_extractor = resnet_fpn_feature_extractor(
                  backbone = backbone,
                  spatial_dims = spatial_dims,
                  pretrained_backbone = False,
                  trainable_backbone_layers = None,
                  returned_layers = [1,2,3],
              )
              model = RetinaNet(
                  spatial_dims = spatial_dims,
                  num_classes = 5,
                  num_anchors = 6,
                  feature_extractor=feature_extractor,
                  size_divisible = 32,
              ).to(device)
      """
      # If pretrained_backbone is False, valid_trainable_backbone_layers = 5.
      # If pretrained_backbone is True, valid_trainable_backbone_layers = trainable_backbone_layers or 3 if None.
      valid_trainable_backbone_layers: int = _validate_trainable_layers(
          pretrained_backbone,
          trainable_backbone_layers,
          max_value=5,
          default_value=3,
      )
  
      feature_extractor = _resnet_fpn_extractor(
          backbone,
          spatial_dims,
          valid_trainable_backbone_layers,
          returned_layers=list(returned_layers),
          extra_blocks=None,
      )
      return feature_extractor
  
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 for calling a global function with example usage: resnet_fpn_feature_extractor(backbone, spatial_dims, pretrained_backbone, returned_layers, trainable_backbone_layers) and returns: feature_extractor