docstr: Check the export_coreml() function.
docstr_tok: ["Check","the","export_coreml","(",")","function","."]
code: def test_export_coreml(self):
      """
      Check the export_coreml() function.
      """
      import coremltools
      import platform
  
      def get_psnr(x, y):
          # See: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
          # The higher the number the better.
          return 20 * np.log10(max(x.max(), y.max())) - 10 * np.log10(
              np.square(x - y).mean()
          )
  
      # Save the model as a CoreML model file
      filename = tempfile.NamedTemporaryFile(suffix=".mlmodel").name
      self.model.export_coreml(filename)
  
      # Load the model back from the CoreML model file
      coreml_model = coremltools.models.MLModel(filename)
      metadata = coreml_model.user_defined_metadata
  
      self.assertEqual(
          metadata["com.github.apple.turicreate.version"],
          tc.__version__,
      )
      self.assertEqual(
          metadata["com.github.apple.os.platform"], platform.platform()
      )
      self.assertEqual(metadata["type"], "ImageSimilarityModel")
      self.assertEqual(metadata["version"], "1")
  
      # Get model distances for comparison
      if self.feature == "awesome_image":
          # tc.image_classifier.create(...) was not called with deep features
          img = data[0:1][self.feature][0]
          img_fixed = tc.image_analysis.resize(
              img, *reversed(self.input_image_shape)
          )
          tc_ret = self.model.query(img_fixed, k=data.num_rows())
  
          if _mac_ver() >= (10, 13):
              from PIL import Image as _PIL_Image
  
              pil_img = _PIL_Image.fromarray(img_fixed.pixel_data)
              coreml_ret = coreml_model.predict(
                  {"awesome_image": pil_img}
              )
  
              # Compare distances
              coreml_distances = np.array(coreml_ret["distance"])
              tc_distances = tc_ret.sort("reference_label")[
                  "distance"
              ].to_numpy()
              psnr_value = get_psnr(coreml_distances, tc_distances)
              self.assertTrue(psnr_value > 50)
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import unittest
  import pytest
  import turicreate
  from turicreate.toolkits._internal_utils import _mac_ver
  import tempfile
  from .None import util
  from turicreate.toolkits._main import ToolkitError
  from turicreate.toolkits.image_analysis.image_analysis import MODEL_TO_FEATURE_SIZE_MAPPING, get_deep_features
  import numpy
label_desc: Use image node_id 16 for calling the ImageSimilarityTest obj's underlying member method code with example usage: obj.test_export_coreml() and returns: unknown