code: def testTFMetricsAccumulator(self):
      # This test uses strings as inputs, but it works similarly to how an
      # accumulator based on tf.Examples would work.
      acc = tf_metric_accumulators.TFMetricsAccumulator(
          input_counts=[1, 1],
          metric_counts=[1, 2],
          size_estimator_fn=len,
      )
  
      self.assertEqual(0, acc.len_inputs())
  
      acc.add_input(0, "output_1_input_1")
      acc.add_input(0, "output_1_input_2")
      acc.add_input(1, "output_2_input_1")
      acc.add_input(1, "output_2_input_2")
      acc.add_input(1, "output_2_input_3")
      self.assertEqual(
          acc.get_inputs(0), (["output_1_input_1", "output_1_input_2"],)
      )
      self.assertEqual(
          acc.get_inputs(1),
          (
              [
                  "output_2_input_1",
                  "output_2_input_2",
                  "output_2_input_3",
              ],
          ),
      )
  
      acc.clear_inputs()
      self.assertEqual(0, acc.len_inputs())
  
      acc.add_weights(0, 0, np.array([1.0, 2.0]))
      acc.add_weights(0, 0, np.array([3.0, 4.0]))
      acc.add_weights(1, 0, np.array([5.0, 6.0]))
      acc.add_weights(1, 1, np.array([7.0, 8.0]))
      acc.add_weights(1, 1, np.array([9.0, 10.0]))
      self.assertAllClose(acc.get_weights(0, 0), np.array([4.0, 6.0]))
      self.assertAllClose(acc.get_weights(1, 0), np.array([5.0, 6.0]))
      self.assertAllClose(acc.get_weights(1, 1), np.array([16.0, 18.0]))
  
file_path: model-analysis/tensorflow_model_analysis/metrics/tf_metric_accumulators_test.py
imports: import numpy
  import tensorflow
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.metrics import tf_metric_accumulators
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 1 for calling the TfMetricAccumulatorsTest obj's underlying member method code with example usage: obj.testTFMetricsAccumulator() without return types