code: def test_iteration_metrics(self, use_tpu, mode):
      with context.graph_mode():
          self.setup_graph()
          best_candidate_index = 3
          ensemble_metrics = []
          for i in range(10):
  
              def metric_fn(val=i):
                  metric = tf.keras.metrics.Mean()
                  metric.update_state(tf.constant(val))
                  return {
                      "ensemble_v1_metric": tf_compat.v1.metrics.mean(
                          tf.constant(val)
                      ),
                      "ensemble_keras_metric": metric,
                  }
  
              ensemble_metrics.append(
                  tu.create_ensemble_metrics(metric_fn)
              )
          metrics = tu.create_iteration_metrics(
              ensemble_metrics=ensemble_metrics
          )
  
          metrics_fn = (
              metrics.best_eval_metrics_tuple
              if use_tpu
              else metrics.best_eval_metric_ops
          )
          actual = self._run_metrics(
              metrics_fn(tf.constant(best_candidate_index), mode) or {}
          )
  
          if mode == tf.estimator.ModeKeys.EVAL:
              expected = {
                  "ensemble_v1_metric": best_candidate_index,
                  "ensemble_keras_metric": best_candidate_index,
                  "iteration": 1,
              }
              # We don't actually provide an architecture, so the default will be
              # inside.
              del actual["architecture/adanet/ensembles"]
          else:
              expected = {}
          self.assertEqual(actual, expected)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  from adanet import tf_compat
  from adanet.core.architecture import _Architecture
  from adanet.core.eval_metrics import _call_eval_metrics
  import adanet.core.testing_utils
  import tensorflow.compat.v2
  from tensorflow.python.eager import context
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 9 for calling the MetricsTest obj's underlying member method code with example usage: obj.test_iteration_metrics(use_tpu, mode) and returns: dict