code: def _test_model(
      self,
      model,
      inputs,
      inference_func=None,
      opset_version=STABLE_ONNX_OPSET_VERSION,
      save_onnx_graph_path=None,
      **export_kwargs,
  ):
      # Not imported in the beginning of file to prevent runtime errors
      # for environments without ONNX.
      # This testcase checks dependencies before running
      import onnx  # isort:skip
  
      f = io.BytesIO()
      adapter_model = TracingAdapter(model, inputs, inference_func)
      adapter_model.eval()
      with torch.no_grad():
          try:
              torch.onnx.enable_log()
          except AttributeError:
              # Older ONNX versions does not have this API
              pass
          torch.onnx.export(
              adapter_model,
              adapter_model.flattened_inputs,
              f,
              training=torch.onnx.TrainingMode.EVAL,
              opset_version=opset_version,
              verbose=True,
              **export_kwargs,
          )
      onnx_model = onnx.load_from_string(f.getvalue())
      assert onnx_model is not None
      if save_onnx_graph_path:
          onnx.save(onnx_model, save_onnx_graph_path)
      return onnx_model
  
imports: import io
  import unittest
  import warnings
  import torch
  from torch.hub import _check_module_exists
  from detectron2 import model_zoo
  from detectron2.config import get_cfg
  from detectron2.export import STABLE_ONNX_OPSET_VERSION
  from detectron2.export.flatten import TracingAdapter
  from detectron2.export.torchscript_patch import patch_builtin_len
  from detectron2.layers import ShapeSpec
  from detectron2.modeling import build_model
  from detectron2.modeling.roi_heads import KRCNNConvDeconvUpsampleHead
  from detectron2.structures import Boxes, Instances
  from detectron2.utils.testing import _pytorch1111_symbolic_opset9_repeat_interleave, _pytorch1111_symbolic_opset9_to, get_sample_coco_image, has_dynamic_axes, random_boxes, register_custom_op_onnx_export, skipIfOnCPUCI, skipIfUnsupportedMinOpsetVersion, skipIfUnsupportedMinTorchVersion, unregister_custom_op_onnx_export
label_desc: Use image node_id 10 for calling the TestONNXTracingExport obj's underlying member method code with example usage: obj._test_model(model, inputs, inference_func, opset_version, save_onnx_graph_path) and returns: onnx_model