code: def dataset_to_examples(ds):
      """Converts a dataset to a dataset of tf.train.Example strings. Each Example is a single observation.
      WARNING: Only compatible with "dictionary-style" datasets {key: val, key2:val2,..., keyN, valN}.
      WARNING: Must run in eager mode!"""
      # TODO handle tuples and flat datasets as well.
      for x in ds:
          # Each individual tensor is converted to a known serializable type.
          features = {
              key: np_value_to_feature(value.numpy())
              for key, value in x.items()
          }
          # All features are then packaged into a single Example object.
          example = tf.train.Example(
              features=tf.train.Features(feature=features)
          )
  
          yield example.SerializeToString()
  
file_path: io/tensorflow_io/python/experimental/serial_ops.py
imports: import functools
  import os
  import tempfile
  import numpy
  import tensorflow
label_desc: Use image node_id 8 for calling a global function with example usage: dataset_to_examples(ds) without return types