code: def testSpecsFromMetrics(self):
      metrics_specs = metric_specs.specs_from_metrics(
          {
              "output_name1": [
                  tf.keras.metrics.Precision(name="precision"),
                  tf.keras.metrics.MeanSquaredError("mse"),
                  tf.keras.losses.MeanAbsoluteError(name="mae"),
              ],
              "output_name2": [
                  confusion_matrix_metrics.Precision(name="precision"),
                  tf.keras.losses.MeanAbsolutePercentageError(
                      name="mape"
                  ),
                  calibration.MeanPrediction("mean_prediction"),
              ],
          },
          unweighted_metrics={
              "output_name1": [calibration.MeanLabel("mean_label")],
              "output_name2": [
                  tf.keras.metrics.RootMeanSquaredError("rmse")
              ],
          },
          model_names=["model_name1", "model_name2"],
          binarize=config_pb2.BinarizationOptions(
              class_ids={"values": [0, 1]}
          ),
          aggregate=config_pb2.AggregationOptions(macro_average=True),
      )
  
      self.assertLen(metrics_specs, 7)
      self.assertProtoEquals(
          metrics_specs[0],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="ExampleCount",
                      config=json.dumps({"name": "example_count"}),
                  ),
              ],
              model_names=["model_name1", "model_name2"],
              example_weights=config_pb2.ExampleWeightOptions(
                  unweighted=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[1],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="WeightedExampleCount",
                      config=json.dumps(
                          {"name": "weighted_example_count"}
                      ),
                  ),
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name1"],
              example_weights=config_pb2.ExampleWeightOptions(
                  weighted=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[2],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="Precision",
                      config=json.dumps(
                          {
                              "name": "precision",
                              "class_id": None,
                              "thresholds": None,
                              "top_k": None,
                          },
                          sort_keys=True,
                      ),
                  ),
                  config_pb2.MetricConfig(
                      class_name="MeanSquaredError",
                      config=json.dumps(
                          {
                              "name": "mse",
                          },
                          sort_keys=True,
                      ),
                  ),
                  config_pb2.MetricConfig(
                      class_name="MeanAbsoluteError",
                      config=json.dumps(
                          _maybe_add_fn_name(
                              {"name": "mae"}, "mean_absolute_error"
                          ),
                          sort_keys=True,
                      ),
                  ),
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name1"],
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[3],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="MeanLabel",
                      config=json.dumps({"name": "mean_label"}),
                  )
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name1"],
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True
              ),
              example_weights=config_pb2.ExampleWeightOptions(
                  unweighted=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[4],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="WeightedExampleCount",
                      config=json.dumps(
                          {"name": "weighted_example_count"}
                      ),
                  ),
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name2"],
              example_weights=config_pb2.ExampleWeightOptions(
                  weighted=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[5],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="Precision",
                      config=json.dumps(
                          {
                              "name": "precision",
                          },
                          sort_keys=True,
                      ),
                  ),
                  config_pb2.MetricConfig(
                      class_name="MeanAbsolutePercentageError",
                      config=json.dumps(
                          _maybe_add_fn_name(
                              {"name": "mape"},
                              "mean_absolute_percentage_error",
                          ),
                          sort_keys=True,
                      ),
                  ),
                  config_pb2.MetricConfig(
                      class_name="MeanPrediction",
                      config=json.dumps({"name": "mean_prediction"}),
                  ),
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name2"],
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True
              ),
          ),
      )
      self.assertProtoEquals(
          metrics_specs[6],
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="RootMeanSquaredError",
                      module="tf_keras.metrics.regression_metrics",
                      config=json.dumps(
                          {"name": "rmse", "dtype": "float32"},
                          sort_keys=True,
                      ),
                  )
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name2"],
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True
              ),
              example_weights=config_pb2.ExampleWeightOptions(
                  unweighted=True
              ),
          ),
      )
  
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 1 for calling the MetricSpecsTest obj's underlying member method code with example usage: obj.testSpecsFromMetrics() without return types