code: def compare_with_pytorch(
      self,
      pytorch_model,
      input_shape_with_batch,
      input_data_with_batch=None,
      compare_result=True,
      rtol=1e-5,
      atol=1e-5,
  ):
      input_shape_with_batch = to_list(input_shape_with_batch)
      if input_data_with_batch is not None:
          input_data_with_batch = to_list(input_data_with_batch)
      onnx_path = self.dump_pytorch_to_onnx(
          pytorch_model, input_shape_with_batch, input_data_with_batch
      )
      # TODO: we only consider single  output for now
      if input_data_with_batch is None:
          input_data_with_batch = [
              np.random.uniform(0, 1, shape).astype(np.float32)
              for shape in input_shape_with_batch
          ]
      else:
          input_data_with_batch = [
              np.array(data).astype(np.long)
              for data in input_data_with_batch
          ]
      # coutput = caffe2.python.onnx.backend.run_model(onnx_model, input_data_with_batch)[0]
  
      pytorch_model.eval()
      pytorch_out = pytorch_model.forward(
          self._convert_ndarray_to_tensor(input_data_with_batch)
      )
      zmodel = OnnxLoader.from_path(onnx_path, is_training=False)
      zoutput = zmodel.forward(
          input_data_with_batch[0]
          if len(input_data_with_batch) == 1
          else input_data_with_batch
      )
      if compare_result:
          self.assert_allclose(
              pytorch_out.detach().numpy(), zoutput, rtol, atol
          )
          assert (
              tuple(pytorch_out.size()[1:])
              == zmodel.get_output_shape()[1:]
          )
  
file_path: analytics-zoo/pyzoo/test/zoo/pipeline/utils/test_utils_onnx.py
imports: from __future__ import print_function
  import numpy
  import onnx
  import torch
  from zoo.pipeline.api.onnx.onnx_loader import OnnxLoader
  from .test_utils import ZooTestCase
  from bigdl.util.common import to_list
label_desc: Use image node_id 4 for calling the OnnxTestCase obj's underlying member method code with example usage: obj.compare_with_pytorch(pytorch_model, input_shape_with_batch, input_data_with_batch, compare_result, rtol, atol) without return types