code: def save_dataset(dataset, tfrecord_path, header_path):
      """Saves a flat dataset as a tfrecord file, and builds a header file for reloading as dataset.
      Must run in eager mode because it depends on dataset iteration and element_spec.
      """
      import yaml
  
      if not tf.executing_eagerly():
          raise ValueError("save_dataset() must run in eager mode!")
  
      # Header
      header = build_header(dataset)
      header_file = open(header_path, "w")
      yaml.dump(header, stream=header_file)
  
      # Dataset
      ds_examples = tf.data.Dataset.from_generator(
          lambda: dataset_to_examples(dataset), output_types=tf.string
      )
      writer = tf.data.experimental.TFRecordWriter(tfrecord_path)
      writer.write(ds_examples)
  
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 9 for calling a global function with example usage: save_dataset(dataset, tfrecord_path, header_path) without return types