code: def _read_tfrecord_examples(filename, id_feature_name):
      """Returns a dict containing the Examples read from a TFRecord file.
  
      Args:
        filename: Name of the TFRecord file to read. Each `tf.train.Example` in the
          input is expected to have a feature named `id` that maps to a singleton
          `bytes_list` value.
        id_feature_name: Name of the singleton `bytes_list` feature in each input
          `tf.train.Example` whose value is the Example's ID.
  
      Returns:
        A dictionary that maps the ID of each Example to that Example.
      """
  
      def parse_example(raw_record):
          """Parses and returns a single record of a TFRecord file."""
          example = tf.train.Example()
          example.ParseFromString(raw_record.numpy())
          return example
  
      def get_id(tf_example):
          """Returns the (singleton) value of the Example's `id_feature_name` feature.
  
          Args:
            tf_example: The `tensorflow.Example` from which to extract the ID feature.
              This is expected to contain a singleton bytes_list value.
          Returns: The ID feature value as a (decoded) string.
          """
          id_feature = tf_example.features.feature[
              id_feature_name
          ].bytes_list
          return id_feature.value[0].decode("utf-8")
  
      start_time = time.time()
      logging.info(
          "Reading tf.train.Examples from TFRecord file: %s...",
          filename,
      )
      result = {}
      for raw_record in tf.data.TFRecordDataset([filename]):
          tf_example = parse_example(raw_record)
          result[get_id(tf_example)] = tf_example
      logging.info(
          "Done reading %d tf.train.Examples from: %s (%.2f seconds).",
          len(result),
          filename,
          (time.time() - start_time),
      )
      return result
  
file_path: neural-structured-learning/neural_structured_learning/tools/pack_nbrs.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import time
  from absl import app
  from absl import flags
  from absl import logging
  from neural_structured_learning.tools import graph_utils
  import six
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: _read_tfrecord_examples(filename, id_feature_name) and returns: result, example, id_feature