code: def convert_plots_proto_to_dict(
      plots_for_slice: metrics_for_slice_pb2.PlotsForSlice,
      model_name: Optional[str] = None,
  ) -> Optional[
      Tuple[slicer.SliceKeyType, Optional[view_types.PlotsByOutputName]]
  ]:
      """Converts plots proto to dict."""
      model_plots_map = {}
      if plots_for_slice.plots:
          plot_dict = _convert_proto_map_to_dict(plots_for_slice.plots)
          keys = list(plot_dict)
          # If there is only one label, choose it automatically.
          plot_data = (
              plot_dict[keys[0]] if len(keys) == 1 else plot_dict
          )
          model_plots_map[""] = {"": {"": plot_data}}
      elif plots_for_slice.HasField("plot_data"):
          model_plots_map[""] = {
              "": {
                  "": {
                      json_format.MessageToDict(
                          plots_for_slice.plot_data
                      )
                  }
              }
          }
  
      if plots_for_slice.plot_keys_and_values:
          for kv in plots_for_slice.plot_keys_and_values:
              current_model_name = kv.key.model_name
              if current_model_name not in model_plots_map:
                  model_plots_map[current_model_name] = {}
              output_name = kv.key.output_name
              if output_name not in model_plots_map[current_model_name]:
                  model_plots_map[current_model_name][output_name] = {}
  
              sub_key_plots_map = model_plots_map[current_model_name][
                  output_name
              ]
              sub_key_id = (
                  str(metric_types.SubKey.from_proto(kv.key.sub_key))
                  if kv.key.HasField("sub_key")
                  else ""
              )
              sub_key_plots_map[sub_key_id] = json_format.MessageToDict(
                  kv.value
              )
  
      plots_map = None
      keys = list(model_plots_map)
      if model_name in model_plots_map:
          # Use the provided model name if there is a match.
          plots_map = model_plots_map[model_name]
      elif not model_name and len(keys) == 1:
          # Show result of the only model if no model name is specified.
          plots_map = model_plots_map[keys[0]]
      elif keys:
          # No match found.
          logging.warning(
              "Fail to find plots for model name: %s . "
              "Available model names are [%s]",
              model_name,
              ", ".join(keys),
          )
          return None
  
      return (
          slicer.deserialize_slice_key(plots_for_slice.slice_key),
          plots_map,
      )
  
imports: import json
  import os
  from typing import Any, Dict, List, Optional, Tuple, Union
  from absl import logging
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import weighted_example_count
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.view import view_types
  from google.protobuf import json_format
label_desc: Use image node_id 11 for calling a global function with example usage: convert_plots_proto_to_dict(plots_for_slice, model_name) and returns: slicer,  plots_map, None