class_docstr: Abstraction for a graph that is used for computing and aggregating metrics.
  
  This abstract class contains methods and lays out the API to handle metrics
  computation and aggregation as part of the TFMA flow. Inheritors of this class
  are responsible for setting up the metrics graph and setting the class
  variables which are required to do metric calculations.
class_docstr_tok: ["Abstraction","for","a","graph","that","is","used","for","computing","and","aggregating","metrics",".","This","abstract","class","contains","methods","and","lays","out","the","API","to","handle","metrics","computation","and","aggregation","as","part","of","the","TFMA","flow",".","Inheritors","of","this","class","are","responsible","for","setting","up","the","metrics","graph","and","setting","the","class","variables","which","are","required","to","do","metric","calculations","."]
docstr: Initializes this class and attempts to create the graph.
  
  This method attempts to create the graph through _construct_graph and
  also creates all class variables that need to be populated by the override
  function _construct_graph.
docstr_tok: ["Initializes","this","class","and","attempts","to","create","the","graph",".","This","method","attempts","to","create","the","graph","through","_construct_graph","and","also","creates","all","class","variables","that","need","to","be","populated","by","the","override","function","_construct_graph","."]
code: def __init__(self):
      """Initializes this class and attempts to create the graph.
  
      This method attempts to create the graph through _construct_graph and
      also creates all class variables that need to be populated by the override
      function _construct_graph.
      """
      self._graph = tf.Graph()
      self._session = tf.compat.v1.Session(graph=self._graph)
  
      # This lock is for  multi-threaded contexts where multiple threads
      # share the same EvalSavedModel.
      #
      # Locking is required in the case where there are multiple threads using
      # the same EvalMetricsGraph. Because the metrics variables are part of the
      # session, and all threads share the same session, without a lock, the
      # "reset-update-get" steps may not be atomic and there can be races.
      #
      # Having each thread have its own session would also work, but would
      # require a bigger refactor.
      # TODO(b/131727905): Investigate whether it's possible / better to have
      # each thread have its own session.
      self._lock = threading.Lock()
  
      # Variables that need to be populated.
  
      # The names of the metric.
      self._metric_names = []
  
      # Ops associated with reading and writing the metric variables.
      self._metric_value_ops = []
      self._metric_update_ops = []
      self._metric_variable_assign_ops = []
  
      # Nodes associated with the metric variables.
      self._metric_variable_nodes = []
  
      # Placeholders and feed input for the metric variables.
      self._metric_variable_placeholders = []
      self._perform_metrics_update_fn_feed_list = []
      self._perform_metrics_update_fn_feed_list_keys = []
  
      # OrderedDicts that map features, predictions, and labels keys to their
      # tensors.
      self._features_map = {}
      self._predictions_map = {}
      self._labels_map = {}
  
      # Ops to set/update/reset all metric variables.
      self._all_metric_variable_assign_ops = None
      self._all_metric_update_ops = None
      self._reset_variables_op = None
  
      # Callable to perform metric update.
      self._perform_metrics_update_fn = None
  
      # OrderedDict produced by graph_ref's load_(legacy_)inputs, mapping input
      # key to tensor value.
      self._input_map = None
  
      self._batch_size = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "batch_size"
      )
      self._batch_size_failed = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "batch_size_failed"
      )
  
      try:
          self._construct_graph()
      except (
          RuntimeError,
          TypeError,
          ValueError,
          tf.errors.OpError,
      ) as exception:
          general_util.reraise_augmented(
              exception, "Failed to create graph."
          )
  
imports: import abc
  import itertools
  import threading
  from typing import Any, Dict, List, NamedTuple, Tuple
  import apache_beam
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import constants
  from tensorflow_model_analysis.eval_saved_model import util
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 to create a new EvalMetricsGraph object  with example: obj = EvalMetricsGraph()