code: def test_resnet50_core(self):
      N = 1
      repeat = 1
      print(
          "Batch size: {}, repeat inference {} times".format(N, repeat)
      )
      init_net, pred_net, _ = self.model_downloader.get_c2_model(
          "resnet50"
      )
      self._add_head_tail(pred_net, "real_data", "real_softmax")
      input_blob_dims = (N, 3, 224, 224)
      input_name = "real_data"
  
      device_option = core.DeviceOption(caffe2_pb2.CPU, 0)
      init_net.device_option.CopyFrom(device_option)
      pred_net.device_option.CopyFrom(device_option)
      for op in pred_net.op:
          op.device_option.CopyFrom(device_option)
      net_outputs = pred_net.external_output
      Y_c2 = None
      data = np.random.randn(*input_blob_dims).astype(np.float32)
      c2_time = 1
      workspace.SwitchWorkspace("onnxifi_test", True)
      with core.DeviceScope(device_option):
          workspace.FeedBlob(input_name, data)
          workspace.RunNetOnce(init_net)
          workspace.CreateNet(pred_net)
          start = time.time()
          for _ in range(repeat):
              workspace.RunNet(pred_net.name)
          end = time.time()
          c2_time = end - start
          output_values = [
              workspace.FetchBlob(name) for name in net_outputs
          ]
          Y_c2 = namedtupledict("Outputs", net_outputs)(*output_values)
      workspace.ResetWorkspace()
  
      # Fill the workspace with the weights
      with core.DeviceScope(device_option):
          workspace.RunNetOnce(init_net)
  
      # Cut the graph
      start = time.time()
      pred_net_cut = onnxifi_caffe2_net(
          pred_net, {input_name: input_blob_dims}, infer_shapes=True
      )
      del init_net, pred_net
      # _print_net(pred_net_cut)
  
      Y_trt = None
      input_name = pred_net_cut.external_input[0]
      print("C2 runtime: {}s".format(c2_time))
      with core.DeviceScope(device_option):
          workspace.FeedBlob(input_name, data)
          workspace.CreateNet(pred_net_cut)
          end = time.time()
          print("Conversion time: {:.2f}s".format(end - start))
  
          start = time.time()
          for _ in range(repeat):
              workspace.RunNet(pred_net_cut.name)
          end = time.time()
          trt_time = end - start
          print(
              "Onnxifi runtime: {}s, improvement: {}%".format(
                  trt_time, (c2_time - trt_time) / c2_time * 100
              )
          )
          output_values = [
              workspace.FetchBlob(name) for name in net_outputs
          ]
          Y_trt = namedtupledict("Outputs", net_outputs)(*output_values)
      np.testing.assert_allclose(Y_c2, Y_trt, rtol=1e-3)
  
imports: import numpy
  import time
  import unittest
  import onnx
  import onnx.defs
  from onnx.backend.base import namedtupledict
  from onnx.helper import make_node, make_graph, make_tensor_value_info, make_model
  from caffe2.proto import caffe2_pb2
  from caffe2.python import core, workspace
  from caffe2.python.models.download import ModelDownloader
  from caffe2.python.onnx.onnxifi import onnxifi_caffe2_net
  from caffe2.python.onnx.tests.test_utils import TestCase
label_desc: Use image node_id 3 for calling the OnnxifiTransformTest obj's underlying member method code with example usage: obj.test_resnet50_core() without return types