code: def run_and_save_graph(
      predict_net, init_net, tensor_inputs, graph_save_path
  ):
      """
      Run the caffe2 model on given inputs, recording the shape and draw the graph.
  
      predict_net/init_net: caffe2 model.
      tensor_inputs: a list of tensors that caffe2 model takes as input.
      graph_save_path: path for saving graph of exported model.
      """
  
      logger.info(
          "Saving graph of ONNX exported model to {} ...".format(
              graph_save_path
          )
      )
      save_graph(predict_net, graph_save_path, op_only=False)
  
      # Run the exported Caffe2 net
      logger.info("Running ONNX exported model ...")
      with ScopedWS("__ws_tmp__", True) as ws:
          ws.RunNetOnce(init_net)
          initialized_blobs = set(ws.Blobs())
          uninitialized = [
              inp
              for inp in predict_net.external_input
              if inp not in initialized_blobs
          ]
          for name, blob in zip(uninitialized, tensor_inputs):
              ws.FeedBlob(name, blob)
  
          try:
              ws.RunNetOnce(predict_net)
          except RuntimeError as e:
              logger.warning(
                  "Encountered RuntimeError: \n{}".format(str(e))
              )
  
          ws_blobs = {b: ws.FetchBlob(b) for b in ws.Blobs()}
          blob_sizes = {
              b: ws_blobs[b].shape
              for b in ws_blobs
              if isinstance(ws_blobs[b], np.ndarray)
          }
  
          logger.info(
              "Saving graph with blob shapes to {} ...".format(
                  graph_save_path
              )
          )
          save_graph(
              predict_net,
              graph_save_path,
              op_only=False,
              blob_sizes=blob_sizes,
          )
  
          return ws_blobs
  
file_path: detectron2/detectron2/export/caffe2_export.py
imports: import copy
  import io
  import logging
  import numpy
  from typing import List
  import onnx
  import onnx.optimizer
  import torch
  from caffe2.proto import caffe2_pb2
  from caffe2.python import core
  from caffe2.python.onnx.backend import Caffe2Backend
  from tabulate import tabulate
  from termcolor import colored
  from torch.onnx import OperatorExportTypes
  from .shared import ScopedWS, construct_init_net_from_params, fuse_alias_placeholder, fuse_copy_between_cpu_and_gpu, get_params_from_init_net, group_norm_replace_aten_with_caffe2, infer_device_type, remove_dead_end_ops, remove_reshape_for_fc, save_graph
label_desc: Use image node_id 5 for calling a global function with example usage: run_and_save_graph(predict_net, init_net, tensor_inputs, graph_save_path) and returns: ws_blobs