class_docstr: Class to write a TFDS dataset sequentially.
  
  The SequentialWriter can be used to generate TFDS datasets by directly
  appending TF Examples to the desired splits.
  
  Once the user creates a SequentialWriter with a given DatasetInfo, they can
  create splits, append examples to them, and close them whenever they are
  finished.
  
  Note that:
  * Not closing a split may cause data to be lost.
  * The examples are written to disk in the same order that they are given to
    the writer.
  * Since the SequentialWriter doesn't know how many examples are going to be
    written, it can't estimate the optimal number of shards per split. Use the
    `max_examples_per_shard` parameter in the constructor to control how many
    elements there should be per shard.
  
  The datasets written with this writer can be read directly with
  `tfds.builder_from_directories`.
  
  Example:
  
  writer = SequentialWriter(ds_info=ds_info, max_examples_per_shard=1000)
  writer.initialize_splits(['train', 'test'])
  
  while (...):
    # Code that generates the examples
    writer.add_examples({'train': [example1, example2],
                         'test':  [example3]})
    ...
  
  writer.close_splits()
docstr: Creates a SequentialWriter.
  
  Args:
    ds_info: DatasetInfo for this dataset.
    max_examples_per_shard: maximum number of examples to write per shard.
    overwrite: if True, it ignores and overwrites any existing data.
      Otherwise, it loads the existing dataset and appends the new data (new
      data will always be created as new shards).
    file_format: An entry in file_adapters.FileFormat.
docstr_tok: ["Creates","a","SequentialWriter",".","Args",":","ds_info",":","DatasetInfo","for","this","dataset",".","max_examples_per_shard",":","maximum","number","of","examples","to","write","per","shard",".","overwrite",":","if","True",",","it","ignores","and","overwrites","any","existing","data",".","Otherwise",",","it","loads","the","existing","dataset","and","appends","the","new","data","(","new","data","will","always","be","created","as","new","shards",")",".","file_format",":","An","entry","in","file_adapters.FileFormat","."]
code: def __init__(
      self,
      ds_info: dataset_info.DatasetInfo,
      max_examples_per_shard: int,
      overwrite: bool = True,
      file_format: str = "tfrecord",
  ):
      """Creates a SequentialWriter.
  
      Args:
        ds_info: DatasetInfo for this dataset.
        max_examples_per_shard: maximum number of examples to write per shard.
        overwrite: if True, it ignores and overwrites any existing data.
          Otherwise, it loads the existing dataset and appends the new data (new
          data will always be created as new shards).
        file_format: An entry in file_adapters.FileFormat.
      """
  
      self._data_dir = ds_info.data_dir
      self._ds_name = ds_info.name
      self._ds_info = ds_info
      self._file_format = file_adapters.FileFormat.from_value(
          file_format
      )
      if not overwrite:
          try:
              self._ds_info.read_from_directory(self._data_dir)
              # read_from_directory does some checks but not on the dataset name.
              if self._ds_info.name != self._ds_name:
                  raise ValueError(
                      f"Trying to append a dataset with name {ds_info.name}"
                      f" to an existing dataset with name {self._ds_info.name}"
                  )
          except FileNotFoundError:
              self._ds_info.set_file_format(
                  file_format=self._file_format,
                  # if it was set, we want this to fail to warn the user
                  override=False,
              )
      else:
          self._ds_info.set_file_format(
              file_format=self._file_format,
              # if it was set, we want this to fail to warn the user
              override=False,
          )
  
      self._filetype_suffix = (
          ds_info.file_format or file_adapters.FileFormat.TFRECORD
      ).file_suffix
      self._max_examples_per_shard = max_examples_per_shard
      self._splits = {}
      if not overwrite:
          for split_name, split in ds_info.splits.items():
              self._splits[split_name] = _initialize_split(
                  split_name=split_name,
                  data_directory=self._data_dir,
                  ds_name=self._ds_name,
                  filetype_suffix=self._filetype_suffix,
                  shard_lengths=split.shard_lengths,
                  num_bytes=split.num_bytes,
                  file_format=self._file_format,
              )
      self._serializer = example_serializer.ExampleSerializer(
          self._ds_info.features.get_serialized_info()
      )
  
imports: from __future__ import annotations
  import dataclasses
  import os
  from typing import Any, Dict, List, Optional
  from tensorflow_datasets.core import dataset_info
  from tensorflow_datasets.core import example_serializer
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core.utils import py_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import array_record_module
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 1 to create a new SequentialWriter object  with example: obj = SequentialWriter(ds_info, max_examples_per_shard, overwrite, file_format)