docstr: Test single image input conversions.
  tf_model_path - the TF model
  coreml_model - converted CoreML model
  input_tensor_name - the input image tensor name
  output_tensor_name - the output tensor name
  img_size - size of the image
docstr_tok: ["Test","single","image","input","conversions",".","tf_model_path","-","the","TF","model","coreml_model","-","converted","CoreML","model","input_tensor_name","-","the","input","image","tensor","name","output_tensor_name","-","the","output","tensor","name","img_size","-","size","of","the","image"]
code: def _test_coreml_model_image_input(
      self,
      tf_model_path,
      coreml_model,
      input_tensor_name,
      output_tensor_name,
      img_size,
      useCPUOnly=False,
  ):
      """Test single image input conversions.
      tf_model_path - the TF model
      coreml_model - converted CoreML model
      input_tensor_name - the input image tensor name
      output_tensor_name - the output tensor name
      img_size - size of the image
      """
  
      img_np, img = _load_image(
          TEST_IMAGE, resize_to=(img_size, img_size)
      )
      img_tf = np.expand_dims(img_np, axis=0)
      img_tf[:, :, :, 0] = (
          self.image_scale * img_tf[:, :, :, 0] + self.red_bias
      )
      img_tf[:, :, :, 1] = (
          self.image_scale * img_tf[:, :, :, 1] + self.green_bias
      )
      img_tf[:, :, :, 2] = (
          self.image_scale * img_tf[:, :, :, 2] + self.blue_bias
      )
  
      # evaluate the TF model
      tf.reset_default_graph()
      graph_def = graph_pb2.GraphDef()
      with open(tf_model_path, "rb") as f:
          graph_def.ParseFromString(f.read())
      g = tf.import_graph_def(graph_def)
      with tf.Session(graph=g) as sess:
          image_input_tensor = sess.graph.get_tensor_by_name(
              "import/" + input_tensor_name
          )
          output = sess.graph.get_tensor_by_name(
              "import/" + output_tensor_name
          )
          tf_out = sess.run(
              output, feed_dict={image_input_tensor: img_tf}
          )
      if len(tf_out.shape) == 4:
          tf_out = np.transpose(tf_out, (0, 3, 1, 2))
      tf_out_flatten = tf_out.flatten()
  
      # evaluate CoreML
      coreml_input_name = input_tensor_name.replace(":", "__").replace(
          "/", "__"
      )
      coreml_output_name = output_tensor_name.replace(
          ":", "__"
      ).replace("/", "__")
      coreml_input = {coreml_input_name: img}
  
      # Test the default CoreML evaluation
      coreml_out = coreml_model.predict(
          coreml_input, useCPUOnly=useCPUOnly
      )[coreml_output_name]
      coreml_out_flatten = coreml_out.flatten()
      self._compare_tf_coreml_outputs(
          tf_out_flatten, coreml_out_flatten
      )
  
imports: import unittest
  import urllib
  import os
  import tarfile
  import zipfile
  import numpy
  import PIL.Image
  import tensorflow
  from tensorflow.core.framework import graph_pb2
  import tfcoreml
label_desc: Use image node_id 4 for calling the CorrectnessTest obj's underlying member method code with example usage: obj._test_coreml_model_image_input(tf_model_path, coreml_model, input_tensor_name, output_tensor_name, img_size, useCPUOnly) without return types