code: def _indices_from_example_count(example_count):
      """Computes input indices from example count.
  
      Args:
        example_count: a 1-D tf.Tensor, representing a batch of inputs. Each element
          is the number of examples that input corresponds to.
  
      Returns:
        A tuple of input_index and intra_input_index. For an example,
        input_index = i means it came from the i-th input (i.e. example_count[i]).
        intra_input_index = i means it is the i-th among all the examples from
        the same input.
      """
      total_num_examples = tf.reduce_sum(input_tensor=example_count)
      example_indices = tf.range(total_num_examples)
      input_limits = tf.cumsum(example_count)
      index_less_than_limit = tf.expand_dims(
          example_indices, 0
      ) >= tf.expand_dims(input_limits, 1)
      input_index = tf.reduce_sum(
          input_tensor=tf.cast(index_less_than_limit, dtype=tf.int32),
          axis=0,
      )
  
      offset = tf.cumsum(
          tf.concat(
              [tf.constant([0], tf.int32), example_count], axis=0
          )[:-1]
      )
      intra_input_index = example_indices - tf.gather(
          offset, input_index
      )
      return input_index, intra_input_index
  
file_path: model-analysis/tensorflow_model_analysis/eval_saved_model/example_trainers/fake_multi_examples_per_input_estimator.py
imports: import tensorflow
  from tensorflow import estimator
  from tensorflow_model_analysis.eval_saved_model import export
  from tensorflow_model_analysis.eval_saved_model.example_trainers import util
  from tensorflow.python.estimator.canned import metric_keys
label_desc: Use image node_id 1 for calling a global function with example usage: _indices_from_example_count(example_count) and returns: input_index,  intra_input_index