code: def _eval_phase(mesh_context, config, master):
      """Handles input pipeline and evaluates the network."""
      if FLAGS.num_eval_iterations_per_loop <= 0:
          return
  
      def _run_eval_phase():
          """The real function that runs the evaluation phase."""
          # Setup input pipeline.
          ds_creator = unet.get_dataset_creator("eval")
          mtf_shapes = unet.get_input_mtf_shapes("eval")
  
          (
              model_eval_fn,
              eval_hooks,
              output_dtypes_shapes,
          ) = _get_model_fn("eval", mesh_context)
  
          if FLAGS.use_tpu:
              assert mesh_context.device_assignment
              assert mesh_context.num_cores
              simd_input_reader = input_reader.SimdMeshImplInputReader(
                  mesh_context.mesh_impl,
                  ds_creator,
                  mtf_shapes,
                  external_worker=(not FLAGS.on_gcp),
                  is_eval_mode=True,
              )
              eval_computation = tpu.replicate(
                  computation=model_eval_fn,
                  inputs=[[]] * mesh_context.num_cores,
                  infeed_queue=simd_input_reader.infeed_queue,
                  device_assignment=mesh_context.device_assignment,
              )
  
              output_dtypes, output_shapes = output_dtypes_shapes.get()
              outfeed_dequeue_ops = []
  
              # Create outfeed_dequeue_ops.
              for host_id in range(mesh_context.num_hosts):
                  # pylint: disable=protected-access
                  with ops.device(
                      input_reader._host_id_to_tf_device(
                          host_id, external_worker=(not FLAGS.on_gcp)
                      )
                  ):
                      for device_ordinal in range(
                          mesh_context.num_cores_per_host
                      ):
                          outfeed_dequeue_op = (
                              tpu_ops.outfeed_dequeue_tuple(
                                  dtypes=output_dtypes,
                                  shapes=output_shapes,
                                  device_ordinal=device_ordinal,
                              )
                          )
  
                          # We don't need output other than from core 0.
                          if outfeed_dequeue_ops:
                              outfeed_dequeue_ops.append(
                                  [
                                      tf.reduce_mean(x)
                                      for x in outfeed_dequeue_op
                                  ]
                              )
                          else:
                              outfeed_dequeue_ops.append(
                                  outfeed_dequeue_op
                              )
  
          else:
              placement_input_reader = (
                  input_reader.PlacementMeshImplInputReader(
                      mesh_context.mesh_impl,
                      ds_creator,
                      mtf_shapes,
                      is_eval_mode=False,
                  )
              )
              eval_computation = placement_input_reader.gpu_placement(
                  model_eval_fn
              )
  
          ###########################################################
          # Evaluation.
          master_to_slice_hook, _ = eval_hooks.get()
          ckpt_loader_hook = _CkptLoaderHook()
          all_hooks = [ckpt_loader_hook, master_to_slice_hook]
  
          if FLAGS.write_summary:
              flush_summary = contrib_summary.flush()
  
          with tf.train.MonitoredSession(
              session_creator=tf.train.ChiefSessionCreator(
                  master=master, config=config
              ),
              hooks=all_hooks,
          ) as sess:
              if FLAGS.write_summary:
                  contrib_summary.initialize(session=sess)
  
              if FLAGS.use_tpu:
                  simd_input_reader.start_infeed_thread(
                      sess, FLAGS.num_eval_iterations_per_loop
                  )
              else:
                  placement_input_reader.initialize(sess)
  
              pprocessor = unet.PostProcessor()
              for step in range(FLAGS.num_eval_iterations_per_loop):
                  # Only get results from the 0-th core.
                  if FLAGS.use_tpu:
                      sess.run(eval_computation)
                      results = sess.run(outfeed_dequeue_ops)[0]
                  else:
                      results = sess.run(eval_computation)
                  pprocessor.record(results, FLAGS.pred_output_dir)
  
                  if FLAGS.write_summary:
                      sess.run(flush_summary)
                  tf.logging.info("eval steps: {}".format(step))
              pprocessor.finish()
  
      with tf.Graph().as_default():
          if FLAGS.write_summary:
              summary_writer = contrib_summary.create_file_writer(
                  FLAGS.summary_dir
              )
              with summary_writer.as_default(), (
                  contrib_summary.always_record_summaries()
              ):
                  _run_eval_phase()
          else:
              _run_eval_phase()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import re
  import mesh_tensorflow
  import numpy
  import six
  from six.moves import range
  from six.moves import zip
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from mesh_tensorflow.experimental import input_reader
  from mesh_tensorflow.experimental import unet
  from tensorflow.contrib import summary
  from tensorflow.contrib import tpu
  from tensorflow.contrib.tpu.python.tpu import device_assignment
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.platform import flags
  from tensorflow.python.tpu.ops import tpu_ops
label_desc: Use image node_id 5 for calling a global function with example usage: _eval_phase(mesh_context, config, master) without return types