code: def _characterize_qmodel_perf_with_data_dir(fpmodel, qspec, data_dir):
      supported_image_exts = ["jpg", "bmp", "png", "jpeg"]
      test_image_paths = [
          "{}/{}".format(data_dir, fn)
          for fn in _listdir(data_dir)
          if any(fn.endswith(ext) for ext in supported_image_exts)
      ]
  
      if not test_image_paths:
          raise Exception(
              "{} contains no supported image files. "
              "Supported file types include jpg, bmp, png and jpeg.".format(
                  data_dir
              )
          )
  
      qmodel = _get_model(qspec, compute_units=_ComputeUnit.CPU_ONLY)
      model_metrics = ModelMetrics(qspec)
  
      input_name = qspec.description.input[0].name
      input_size = (
          qspec.description.input[0].type.imageType.width,
          qspec.description.input[0].type.imageType.height,
      )
  
      print("\n\n")
      print("Analyzing {} images".format(len(test_image_paths)))
      print("Running Analysis this may take a while ...")
      print("\n")
  
      analyzed = 0
      tried = 0
      if fpmodel.compute_unit != _ComputeUnit.CPU_ONLY:
          fpmodel = _MLModel(
              fpmodel.get_spec(), compute_units=_ComputeUnit.CPU_ONLY
          )
      for image in test_image_paths:
          try:
              input = {
                  input_name: _load_and_resize_image(image, input_size)
              }
              fp_pred = fpmodel.predict(input)
              q_pred = qmodel.predict(input)
              analyzed += 1
              model_metrics.add_metrics(fp_pred, q_pred)
  
          except Exception as e:
              print(e)
              continue
  
          # Update Progress
          tried += 1
          if tried % 10 == 0:
              _stdout.write("\r")
              _stdout.write(
                  "Analyzed {}/{}".format(tried, len(test_image_paths))
              )
              _stdout.flush()
  
      print("\n")
      model_metrics.display_metrics()
  
imports: from os import listdir
  from sys import stdout
  import numpy
  from coremltools import ComputeUnit, _logger
  from coremltools._deps import _HAS_KMEANS1D, _kmeans1d
  from coremltools.models import _QUANTIZATION_MODE_CUSTOM_LOOKUP_TABLE, _QUANTIZATION_MODE_DEQUANTIZE, _QUANTIZATION_MODE_LINEAR_QUANTIZATION, _QUANTIZATION_MODE_LINEAR_SYMMETRIC, _QUANTIZATION_MODE_LOOKUP_TABLE_KMEANS, _QUANTIZATION_MODE_LOOKUP_TABLE_LINEAR, _SUPPORTED_QUANTIZATION_MODES, MLModel
  from ...None import _MINIMUM_FP16_SPEC_VERSION, _MINIMUM_QUANTIZED_MODEL_SPEC_VERSION, _SPECIFICATION_VERSION_IOS_14
  from ..utils import _get_model, _macos_version, _wp_to_fp16wp
  from .optimization_utils import _optimize_nn
label_desc: Use image node_id 17 for calling a global function with example usage: _characterize_qmodel_perf_with_data_dir(fpmodel, qspec, data_dir) without return types