message: Update metrics_utils_test.py
diff: @@ -23,16 +23,17 @@ from absl.testing import parameterized
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  +from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.keras import combinations
  +from tensorflow.python.keras import metrics
  from tensorflow.python.keras.utils import metrics_utils
  from tensorflow.python.ops import script_ops
  +from tensorflow.python.ops import variables
  from tensorflow.python.ops.ragged import ragged_factory_ops
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.platform import googletest
  from tensorflow.python.platform import test
  -from tensorflow.python.keras import metrics
  -from tensorflow.python.ops import init_ops
  @combinations.generate(combinations.combine(mode=['graph', 'eager']))
  @@ -254,33 +255,30 @@ class RaggedSizeOpTest(test_util.TensorFlowTestCase, parameterized.TestCase):
  metrics_utils.ragged_assert_compatible_and_get_flat_values([x, y])
  +@combinations.generate(combinations.combine(mode=['eager']))
  class TestUpdateConfusionMatrixVariables(test.TestCase):
  - def _get_test_data(self):
  + def test_sample_weights_slicing(self):
  + tp = metrics.TruePositives()
  + self.evaluate(variables.variables_initializer(tp.variables))
  variables_to_update = {
  - metrics_utils.ConfusionMatrix.TRUE_POSITIVES:
  - metrics.TruePositives().add_weight(
  - 'accumulator',
  - shape=(1,),
  - initializer=init_ops.zeros_initializer)
  + metrics_utils.ConfusionMatrix.TRUE_POSITIVES: tp.accumulator
  }
  y_true = np.array([[[1, 0], [0, 1]], [[0, 1], [1, 1]]])
  y_pred = np.array([[[1, 1], [0, 1]], [[0, 0], [1, 1]]])
  sample_weights = np.array([[1, 0], [1, 0]])
  - return variables_to_update, y_true, y_pred, sample_weights
  - def test_sample_weights_slicing(self):
  - variables_to_update, y_true, y_pred, sample_weights = self._get_test_data()
  - metrics_utils.update_confusion_matrix_variables(
  + ret = metrics_utils.update_confusion_matrix_variables(
  variables_to_update,
  y_true,
  y_pred,
  thresholds=[0.5],
  class_id=0,
  sample_weight=sample_weights)
  + with ops.control_dependencies([ret]):
  self.assertAlmostEqual(
  - variables_to_update[
  - metrics_utils.ConfusionMatrix.TRUE_POSITIVES].numpy(), 1.0)
  + self.evaluate(variables_to_update[
  + metrics_utils.ConfusionMatrix.TRUE_POSITIVES])[0], 1.0)
  @combinations.generate(combinations.combine(mode=['graph', 'eager']))
  