code: def patch_nonscriptable_classes():
      """
      Apply patches on a few nonscriptable detectron2 classes.
      Should not have side-effects on eager usage.
      """
      # __prepare_scriptable__ can also be added to models for easier maintenance.
      # But it complicates the clean model code.
  
      from detectron2.modeling.backbone import ResNet, FPN
  
      # Due to https://github.com/pytorch/pytorch/issues/36061,
      # we change backbone to use ModuleList for scripting.
      # (note: this changes param names in state_dict)
  
      def prepare_resnet(self):
          ret = deepcopy(self)
          ret.stages = nn.ModuleList(ret.stages)
          for k in self.stage_names:
              delattr(ret, k)
          return ret
  
      ResNet.__prepare_scriptable__ = prepare_resnet
  
      def prepare_fpn(self):
          ret = deepcopy(self)
          ret.lateral_convs = nn.ModuleList(ret.lateral_convs)
          ret.output_convs = nn.ModuleList(ret.output_convs)
          for name, _ in self.named_children():
              if name.startswith("fpn_"):
                  delattr(ret, name)
          return ret
  
      FPN.__prepare_scriptable__ = prepare_fpn
  
      # Annotate some attributes to be constants for the purpose of scripting,
      # even though they are not constants in eager mode.
      from detectron2.modeling.roi_heads import StandardROIHeads
  
      if hasattr(StandardROIHeads, "__annotations__"):
          # copy first to avoid editing annotations of base class
          StandardROIHeads.__annotations__ = deepcopy(
              StandardROIHeads.__annotations__
          )
          StandardROIHeads.__annotations__["mask_on"] = torch.jit.Final[
              bool
          ]
          StandardROIHeads.__annotations__[
              "keypoint_on"
          ] = torch.jit.Final[bool]
  
file_path: detectron2/detectron2/export/torchscript_patch.py
imports: import os
  import sys
  import tempfile
  from contextlib import ExitStack, contextmanager
  from copy import deepcopy
  from unittest import mock
  import torch
  from torch import nn
  import detectron2
  from detectron2.structures import Boxes, Instances
  from detectron2.utils.env import _import_file
label_desc: Use image node_id 8 for calling a global function with example usage: patch_nonscriptable_classes() and returns: ret, ret