code: def test_convert_from_frozen_graph_file(tmpdir):
      # create the model to convert
      import tensorflow as tf
  
      # write a toy frozen graph
      # Note that we usually needs to run freeze_graph() on tf.Graph()
      # skipping here as this toy model does not contain any variables
      with tf.Graph().as_default() as graph:
          x = tf.placeholder(tf.float32, shape=(1, 2, 3), name="input")
          y = tf.nn.relu(x, name="output")
  
      save_path = str(tmpdir)
      tf.io.write_graph(
          graph, save_path, "frozen_graph.pb", as_text=False
      )
  
      # Create a test sample
      # -0.5 to have some negative values
      test_input = np.random.rand(1, 2, 3) - 0.5
      with tf.compat.v1.Session(graph=graph) as sess:
          expected_val = sess.run(y, feed_dict={x: test_input})
  
      # The input `.pb` file is a frozen graph format that usually
      # generated by TensorFlow's utility function `freeze_graph()`
      pb_path = os.path.join(save_path, "frozen_graph.pb")
  
      # 3 ways to specify inputs:
      # (1) Fully specify inputs
      mlmodel = ct.convert(
          pb_path,
          # We specify inputs with name matching the placeholder name.
          inputs=[ct.TensorType(name="input", shape=(1, 2, 3))],
          outputs=["output"],
      )
  
      # (2) Specify input TensorType without name (when there's only one
      # input)
      mlmodel = ct.convert(
          pb_path,
          # TensorType name is optional when there's only one input.
          inputs=[ct.TensorType(shape=(1, 2, 3))],
          outputs=["output"],
      )
  
      # (3) Not specify inputs at all. `inputs` is optional for TF. When
      # inputs is not specified, convert() infers inputs from Placeholder
      # nodes.
      mlmodel = ct.convert(pb_path, outputs=["output"])
  
      results = mlmodel.predict({"input": test_input})
      np.testing.assert_allclose(results["output"], expected_val)
      mlmodel_path = os.path.join(save_path, "model.mlmodel")
      # Save the converted model
      mlmodel.save(mlmodel_path)
  
      results = mlmodel.predict({"input": test_input})
      np.testing.assert_allclose(results["output"], expected_val)
  
imports: from os import getcwd, chdir
  from shutil import rmtree
  from os.path import exists
  from tempfile import mkdtemp
  import pytest
  import numpy
  import coremltools
  import os
  from coremltools._deps import _HAS_TF_1, _HAS_TF_2, _HAS_TORCH, MSG_TF1_NOT_FOUND, MSG_TF2_NOT_FOUND, MSG_TORCH_NOT_FOUND
label_desc: Use image node_id 2 for calling the TestTensorFlow1ConverterExamples obj's underlying member method code with example usage: obj.test_convert_from_frozen_graph_file(tmpdir) without return types