code: def test_crop_resize(self, cpu_only=False):
      if _macos_version()[0] == 12:
          pytest.xfail("rdar://110274216")
  
      def get_coreml_model_crop_resize(params):
          eval = True
          mlmodel = None
          batch, ch, n_roi = params["b_c_n"]
          H = params["H"]
          W = params["W"]
          try:
              input_features = [("data", datatypes.Array(ch, H, W))]
              input_features.append(("roi", datatypes.Array(4, 1, 1)))
              if batch != 1:
                  input_features.append(
                      ("box_ind", datatypes.Array(1, 1, 1))
                  )
              output_features = [("output", None)]
              builder = neural_network.NeuralNetworkBuilder(
                  input_features, output_features
              )
  
              if batch != 1:
                  builder.add_elementwise(
                      "concat", ["box_ind", "roi"], "roi_out", "CONCAT"
                  )
                  input_names = ["data", "roi_out"]
              else:
                  input_names = ["data", "roi"]
  
              builder.add_crop_resize(
                  "resize",
                  input_names,
                  "output",
                  target_height=params["Hnew"],
                  target_width=params["Wnew"],
                  mode="ALIGN_ENDPOINTS_MODE",
                  normalized_roi=True,
                  box_indices_mode="CORNERS_HEIGHT_FIRST",
                  spatial_scale=1.0,
              )
  
              if cpu_only:
                  compute_unit = ComputeUnit.CPU_ONLY
              else:
                  compute_unit = ComputeUnit.ALL
              mlmodel = MLModel(
                  builder.spec, compute_units=compute_unit
              )
          except RuntimeError as e:
              print(e)
              eval = False
  
          return mlmodel, eval
  
      def get_tf_predictions_crop_resize(X, boxes, box_ind, params):
          y = tf.image.crop_and_resize(
              X,
              boxes,
              box_ind,
              crop_size=[params["Hnew"], params["Wnew"]],
          )
          return y.numpy()
  
      """
          Define Params
          """
      params_dict = dict(
          H=[1, 3, 10],  # [1,2,3,6,10]
          W=[1, 3, 10],  # [1,2,3,6,10]
          Hnew=[1, 2, 3, 6],  # [1,2,3,6,12,20]
          Wnew=[1, 2, 3, 6],  # [1,2,3,6,12,20]
          b_c_n=[
              (1, 1, 1),
              (1, 2, 3),
              (3, 2, 1),
              (3, 4, 3),
          ],  # [(1,1,1),(1,2,3),(3,2,1),(3,4,3)]
      )
      params = [
          x for x in list(itertools.product(*params_dict.values()))
      ]
      valid_params = [dict(zip(params_dict.keys(), x)) for x in params]
      print("Total params to be tested: {}".format(len(valid_params)))
      """
          Test
          """
      failed_tests_compile = []
      for i in range(len(valid_params)):
          params = valid_params[i]
          batch, ch, n_roi = params["b_c_n"]
          X = np.round(
              255 * np.random.rand(batch, ch, params["H"], params["W"])
          )
          roi = np.zeros((n_roi, 4), dtype=np.float32)
          box_ind = np.zeros((n_roi))
          if batch != 1:
              box_ind = np.random.randint(
                  low=0, high=batch, size=(n_roi)
              )
          for ii in range(n_roi):
              r = np.random.rand(4)
              w_start = r[0]
              h_start = r[1]
              w_end = r[2] * (1 - w_start) + w_start
              h_end = r[3] * (1 - h_start) + h_start
              roi[ii, :] = [h_start, w_start, h_end, w_end]
              roi[ii, :] = np.round(100 * roi[ii, :]) / 100
              assert roi[ii, 0] <= roi[ii, 2]
              assert roi[ii, 1] <= roi[ii, 3]
  
          tf_preds = get_tf_predictions_crop_resize(
              np.transpose(X, [0, 2, 3, 1]), roi, box_ind, params
          )
          tf_preds = np.transpose(tf_preds, [0, 3, 1, 2])
          coreml_model, eval = get_coreml_model_crop_resize(params)
          if eval is False:
              failed_tests_compile.append(params)
          else:
              input_dict = {"data": np.expand_dims(X, axis=0)}
              input_dict["roi"] = np.reshape(roi, (n_roi, 1, 4, 1, 1))
              if batch != 1:
                  input_dict["box_ind"] = np.reshape(
                      box_ind.astype(np.float32), (n_roi, 1, 1, 1, 1)
                  )
              ref_output_dict = {
                  "output": np.expand_dims(tf_preds, axis=0)
              }
              self._test_model(
                  input_dict, ref_output_dict, coreml_model
              )
  
      self.assertEqual(failed_tests_compile, [])
  
imports: import itertools
  import unittest
  import numpy
  import pytest
  import coremltools.models.datatypes
  from coremltools import ComputeUnit
  from coremltools._deps import _HAS_TF_2, MSG_TF2_NOT_FOUND
  from coremltools.models import MLModel, neural_network
  from coremltools.models.utils import _is_macos, _macos_version
label_desc: Use image node_id 7 for calling the StressTest obj's underlying member method code with example usage: obj.test_crop_resize(cpu_only) and returns: mlmodel,  eval, y