code: def _validate_trainable_layers(
      is_trained: bool,
      trainable_backbone_layers: Optional[int],
      max_value: int,
      default_value: int,
  ) -> int:
      # don't freeze any layers if pretrained model or backbone is not used
      if not is_trained:
          if trainable_backbone_layers is not None:
              warnings.warn(
                  "Changing trainable_backbone_layers has no effect if "
                  "neither pretrained nor pretrained_backbone have been set to True, "
                  f"falling back to trainable_backbone_layers={max_value} so that all layers are trainable"
              )
          trainable_backbone_layers = max_value
  
      # by default freeze first blocks
      if trainable_backbone_layers is None:
          trainable_backbone_layers = default_value
      if (
          trainable_backbone_layers < 0
          or trainable_backbone_layers > max_value
      ):
          raise ValueError(
              f"Trainable backbone layers should be in the range [0,{max_value}], got {trainable_backbone_layers} "
          )
      return trainable_backbone_layers
  
file_path: vision/torchvision/models/detection/backbone_utils.py
imports: import warnings
  from typing import Callable, Dict, List, Optional, Union
  from torch import nn, Tensor
  from torchvision.ops import misc
  from torchvision.ops.feature_pyramid_network import ExtraFPNBlock, FeaturePyramidNetwork, LastLevelMaxPool
  from ..None import mobilenet, resnet
  from .._api import _get_enum_from_fn, WeightsEnum
  from .._utils import handle_legacy_interface, IntermediateLayerGetter
label_desc: Use image node_id 3 for calling a global function with example usage: _validate_trainable_layers(is_trained, trainable_backbone_layers, max_value, default_value) and returns: trainable_backbone_layers