code: def testToComputations(self):
      computations = metric_specs.to_computations(
          metric_specs.specs_from_metrics(
              [
                  tf.keras.metrics.MeanSquaredError("mse"),
                  # Add a loss exactly same as metric
                  # (https://github.com/tensorflow/tfx/issues/1550)
                  tf.keras.losses.MeanSquaredError(name="loss"),
                  calibration.MeanLabel("mean_label"),
              ],
              model_names=["model_name"],
              output_names=["output_1", "output_2"],
              output_weights={"output_1": 1.0, "output_2": 1.0},
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True, class_weights={0: 1.0, 1: 1.0}
              ),
          ),
          config_pb2.EvalConfig(),
      )
  
      keys = []
      for m in computations:
          for k in m.keys:
              if not k.name.startswith("_"):
                  keys.append(k)
      self.assertLen(keys, 31)
      self.assertIn(
          metric_types.MetricKey(
              name="example_count", model_name="model_name"
          ),
          keys,
      )
      for output_name in ("output_1", "output_2", ""):
          self.assertIn(
              metric_types.MetricKey(
                  name="weighted_example_count",
                  model_name="model_name",
                  output_name=output_name,
                  example_weighted=True,
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mse",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=0),
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mse",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=1),
              ),
              keys,
          )
          aggregation_type = (
              metric_types.AggregationType(macro_average=True)
              if output_name
              else None
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mse",
                  model_name="model_name",
                  output_name=output_name,
                  aggregation_type=aggregation_type,
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="loss",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=0),
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="loss",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=1),
              ),
              keys,
          )
          aggregation_type = (
              metric_types.AggregationType(macro_average=True)
              if output_name
              else None
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="loss",
                  model_name="model_name",
                  output_name=output_name,
                  aggregation_type=aggregation_type,
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mean_label",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=0),
              ),
              keys,
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mean_label",
                  model_name="model_name",
                  output_name=output_name,
                  sub_key=metric_types.SubKey(class_id=1),
              ),
              keys,
          )
          aggregation_type = (
              metric_types.AggregationType(macro_average=True)
              if output_name
              else None
          )
          self.assertIn(
              metric_types.MetricKey(
                  name="mean_label",
                  model_name="model_name",
                  output_name=output_name,
                  aggregation_type=aggregation_type,
              ),
              keys,
          )
  
file_path: model-analysis/tensorflow_model_analysis/metrics/metric_specs_test.py
imports: import json
  import tensorflow
  from tensorflow_model_analysis.metrics import calibration
  from tensorflow_model_analysis.metrics import confusion_matrix_metrics
  from tensorflow_model_analysis.metrics import mean_regression_error
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 4 for calling the MetricSpecsTest obj's underlying member method code with example usage: obj.testToComputations() without return types