code: def testMetricThresholdsFromMetricsSpecs(self):
      slice_specs = [
          config_pb2.SlicingSpec(feature_keys=["feature1"]),
          config_pb2.SlicingSpec(feature_values={"feature2": "value1"}),
      ]
  
      # For cross slice tests.
      baseline_slice_spec = config_pb2.SlicingSpec(
          feature_keys=["feature3"]
      )
  
      metrics_specs = [
          config_pb2.MetricsSpec(
              thresholds={
                  "auc": config_pb2.MetricThreshold(
                      value_threshold=config_pb2.GenericValueThreshold()
                  ),
                  "mean/label": config_pb2.MetricThreshold(
                      value_threshold=config_pb2.GenericValueThreshold(),
                      change_threshold=config_pb2.GenericChangeThreshold(),
                  ),
                  "mse": config_pb2.MetricThreshold(
                      change_threshold=config_pb2.GenericChangeThreshold()
                  ),
              },
              per_slice_thresholds={
                  "auc": config_pb2.PerSliceMetricThresholds(
                      thresholds=[
                          config_pb2.PerSliceMetricThreshold(
                              slicing_specs=slice_specs,
                              threshold=config_pb2.MetricThreshold(
                                  value_threshold=config_pb2.GenericValueThreshold()
                              ),
                          )
                      ]
                  ),
                  "mean/label": config_pb2.PerSliceMetricThresholds(
                      thresholds=[
                          config_pb2.PerSliceMetricThreshold(
                              slicing_specs=slice_specs,
                              threshold=config_pb2.MetricThreshold(
                                  value_threshold=config_pb2.GenericValueThreshold(),
                                  change_threshold=config_pb2.GenericChangeThreshold(),
                              ),
                          )
                      ]
                  ),
              },
              cross_slice_thresholds={
                  "auc": config_pb2.CrossSliceMetricThresholds(
                      thresholds=[
                          config_pb2.CrossSliceMetricThreshold(
                              cross_slicing_specs=[
                                  config_pb2.CrossSlicingSpec(
                                      baseline_spec=baseline_slice_spec,
                                      slicing_specs=slice_specs,
                                  )
                              ],
                              threshold=config_pb2.MetricThreshold(
                                  value_threshold=config_pb2.GenericValueThreshold(),
                                  change_threshold=config_pb2.GenericChangeThreshold(),
                              ),
                          )
                      ]
                  ),
                  "mse": config_pb2.CrossSliceMetricThresholds(
                      thresholds=[
                          config_pb2.CrossSliceMetricThreshold(
                              cross_slicing_specs=[
                                  config_pb2.CrossSlicingSpec(
                                      baseline_spec=baseline_slice_spec,
                                      slicing_specs=slice_specs,
                                  )
                              ],
                              threshold=config_pb2.MetricThreshold(
                                  change_threshold=config_pb2.GenericChangeThreshold()
                              ),
                          ),
                          # Test for duplicate cross_slicing_spec.
                          config_pb2.CrossSliceMetricThreshold(
                              cross_slicing_specs=[
                                  config_pb2.CrossSlicingSpec(
                                      baseline_spec=baseline_slice_spec,
                                      slicing_specs=slice_specs,
                                  )
                              ],
                              threshold=config_pb2.MetricThreshold(
                                  value_threshold=config_pb2.GenericValueThreshold()
                              ),
                          ),
                      ]
                  ),
              },
              model_names=["model_name"],
              output_names=["output_name"],
          ),
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="ExampleCount",
                      config=json.dumps({"name": "example_count"}),
                      threshold=config_pb2.MetricThreshold(
                          value_threshold=config_pb2.GenericValueThreshold()
                      ),
                  )
              ],
              model_names=["model_name1", "model_name2"],
              example_weights=config_pb2.ExampleWeightOptions(
                  unweighted=True
              ),
          ),
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="WeightedExampleCount",
                      config=json.dumps(
                          {"name": "weighted_example_count"}
                      ),
                      threshold=config_pb2.MetricThreshold(
                          value_threshold=config_pb2.GenericValueThreshold()
                      ),
                  )
              ],
              model_names=["model_name1", "model_name2"],
              output_names=["output_name1", "output_name2"],
              example_weights=config_pb2.ExampleWeightOptions(
                  weighted=True
              ),
          ),
          config_pb2.MetricsSpec(
              metrics=[
                  config_pb2.MetricConfig(
                      class_name="MeanSquaredError",
                      config=json.dumps({"name": "mse"}),
                      threshold=config_pb2.MetricThreshold(
                          change_threshold=config_pb2.GenericChangeThreshold()
                      ),
                  ),
                  config_pb2.MetricConfig(
                      class_name="MeanLabel",
                      config=json.dumps({"name": "mean_label"}),
                      threshold=config_pb2.MetricThreshold(
                          change_threshold=config_pb2.GenericChangeThreshold()
                      ),
                      per_slice_thresholds=[
                          config_pb2.PerSliceMetricThreshold(
                              slicing_specs=slice_specs,
                              threshold=config_pb2.MetricThreshold(
                                  change_threshold=config_pb2.GenericChangeThreshold()
                              ),
                          ),
                      ],
                      cross_slice_thresholds=[
                          config_pb2.CrossSliceMetricThreshold(
                              cross_slicing_specs=[
                                  config_pb2.CrossSlicingSpec(
                                      baseline_spec=baseline_slice_spec,
                                      slicing_specs=slice_specs,
                                  )
                              ],
                              threshold=config_pb2.MetricThreshold(
                                  change_threshold=config_pb2.GenericChangeThreshold()
                              ),
                          )
                      ],
                  ),
              ],
              model_names=["model_name"],
              output_names=["output_name"],
              binarize=config_pb2.BinarizationOptions(
                  class_ids={"values": [0, 1]}
              ),
              aggregate=config_pb2.AggregationOptions(
                  macro_average=True, class_weights={0: 1.0, 1: 1.0}
              ),
          ),
      ]
  
      thresholds = metric_specs.metric_thresholds_from_metrics_specs(
          metrics_specs, eval_config=config_pb2.EvalConfig()
      )
  
      expected_keys_and_threshold_counts = {
          metric_types.MetricKey(
              name="auc",
              model_name="model_name",
              output_name="output_name",
              is_diff=False,
              example_weighted=None,
          ): 4,
          metric_types.MetricKey(
              name="auc",
              model_name="model_name",
              output_name="output_name",
              is_diff=True,
              example_weighted=None,
          ): 1,
          metric_types.MetricKey(
              name="mean/label",
              model_name="model_name",
              output_name="output_name",
              is_diff=True,
              example_weighted=None,
          ): 3,
          metric_types.MetricKey(
              name="mean/label",
              model_name="model_name",
              output_name="output_name",
              is_diff=False,
              example_weighted=None,
          ): 3,
          metric_types.MetricKey(
              name="example_count", model_name="model_name1"
          ): 1,
          metric_types.MetricKey(
              name="example_count", model_name="model_name2"
          ): 1,
          metric_types.MetricKey(
              name="weighted_example_count",
              model_name="model_name1",
              output_name="output_name1",
              example_weighted=True,
          ): 1,
          metric_types.MetricKey(
              name="weighted_example_count",
              model_name="model_name1",
              output_name="output_name2",
              example_weighted=True,
          ): 1,
          metric_types.MetricKey(
              name="weighted_example_count",
              model_name="model_name2",
              output_name="output_name1",
              example_weighted=True,
          ): 1,
          metric_types.MetricKey(
              name="weighted_example_count",
              model_name="model_name2",
              output_name="output_name2",
              example_weighted=True,
          ): 1,
          metric_types.MetricKey(
              name="mse",
              model_name="model_name",
              output_name="output_name",
              sub_key=metric_types.SubKey(class_id=0),
              is_diff=True,
          ): 1,
          metric_types.MetricKey(
              name="mse",
              model_name="model_name",
              output_name="output_name",
              sub_key=metric_types.SubKey(class_id=1),
              is_diff=True,
          ): 1,
          metric_types.MetricKey(
              name="mse",
              model_name="model_name",
              output_name="output_name",
              is_diff=False,
              example_weighted=None,
          ): 1,
          metric_types.MetricKey(
              name="mse",
              model_name="model_name",
              output_name="output_name",
              is_diff=True,
              example_weighted=None,
          ): 2,
          metric_types.MetricKey(
              name="mse",
              model_name="model_name",
              output_name="output_name",
              aggregation_type=metric_types.AggregationType(
                  macro_average=True
              ),
              is_diff=True,
          ): 1,
          metric_types.MetricKey(
              name="mean_label",
              model_name="model_name",
              output_name="output_name",
              sub_key=metric_types.SubKey(class_id=0),
              is_diff=True,
          ): 4,
          metric_types.MetricKey(
              name="mean_label",
              model_name="model_name",
              output_name="output_name",
              sub_key=metric_types.SubKey(class_id=1),
              is_diff=True,
          ): 4,
          metric_types.MetricKey(
              name="mean_label",
              model_name="model_name",
              output_name="output_name",
              aggregation_type=metric_types.AggregationType(
                  macro_average=True
              ),
              is_diff=True,
          ): 4,
      }
      self.assertLen(
          thresholds, len(expected_keys_and_threshold_counts)
      )
      for key, count in expected_keys_and_threshold_counts.items():
          self.assertIn(key, thresholds)
          self.assertLen(
              thresholds[key], count, "failed for key {}".format(key)
          )
  
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 3 for calling the MetricSpecsTest obj's underlying member method code with example usage: obj.testMetricThresholdsFromMetricsSpecs() without return types