code: def _to_proto(
      thresholds: List[float],
      histogram: calibration_histogram.Histogram,
  ) -> metrics_for_slice_pb2.CalibrationHistogramBuckets:
      """Converts histogram into CalibrationHistogramBuckets proto.
  
      Args:
        thresholds: Thresholds associated with histogram buckets.
        histogram: Calibration histogram.
  
      Returns:
        A histogram in CalibrationHistogramBuckets proto format.
      """
      pb = metrics_for_slice_pb2.CalibrationHistogramBuckets()
      lower_threshold = float("-inf")
      for i, bucket in enumerate(histogram):
          if i >= len(thresholds) - 1:
              upper_threshold = float("inf")
          else:
              upper_threshold = thresholds[i + 1]
          pb.buckets.add(
              lower_threshold_inclusive=lower_threshold,
              upper_threshold_exclusive=upper_threshold,
              total_weighted_label={"value": bucket.weighted_labels},
              total_weighted_refined_prediction={
                  "value": bucket.weighted_predictions
              },
              num_weighted_examples={"value": bucket.weighted_examples},
          )
          lower_threshold = upper_threshold
      return pb
  
file_path: model-analysis/tensorflow_model_analysis/metrics/calibration_plot.py
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  from tensorflow_model_analysis.metrics import calibration_histogram
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 3 for calling a global function with example usage: _to_proto(thresholds, histogram) and returns: pb