class_docstr: Generates and loads a demo data set.
class_docstr_tok: ["Generates","and","loads","a","demo","data","set","."]
docstr: Returns the dataset as a tf.data.Dataset.
  
  Args:
    split: either "train" or "test"
    shuffle: if true, shuffles both files and examples.
    repeat: if true, repeats the data set forever.
    serialized_prefetch_size: the buffer size for reading from disk.
    decoded_prefetch_size: the buffer size after decoding.
  
  Returns:
    A tf.data.Dataset object with the following structure: {
      "images": uint8 tensor, shape [time, height, width, channels]
      "labels": one hot encoded label tensor, shape [2]
      "id": a unique string id for each example, shape []
    }
docstr_tok: ["Returns","the","dataset","as","a","tf.data.Dataset",".","Args",":","split",":","either","``","train","''","or","``","test","''","shuffle",":","if","true",",","shuffles","both","files","and","examples",".","repeat",":","if","true",",","repeats","the","data","set","forever",".","serialized_prefetch_size",":","the","buffer","size","for","reading","from","disk",".","decoded_prefetch_size",":","the","buffer","size","after","decoding",".","Returns",":","A","tf.data.Dataset","object","with","the","following","structure",":","{","``","images","''",":","uint8","tensor",",","shape","[","time",",","height",",","width",",","channels","]","``","labels","''",":","one","hot","encoded","label","tensor",",","shape","[","2","]","``","id","''",":","a","unique","string","id","for","each","example",",","shape","[","]","}"]
code: def as_dataset(
      self,
      split,
      shuffle=False,
      repeat=False,
      serialized_prefetch_size=32,
      decoded_prefetch_size=32,
  ):
      """Returns the dataset as a tf.data.Dataset.
  
      Args:
        split: either "train" or "test"
        shuffle: if true, shuffles both files and examples.
        repeat: if true, repeats the data set forever.
        serialized_prefetch_size: the buffer size for reading from disk.
        decoded_prefetch_size: the buffer size after decoding.
  
      Returns:
        A tf.data.Dataset object with the following structure: {
          "images": uint8 tensor, shape [time, height, width, channels]
          "labels": one hot encoded label tensor, shape [2]
          "id": a unique string id for each example, shape []
        }
      """
  
      def parse_fn(sequence_example):
          """Parses a clip classification example."""
          context_features = {
              ms.get_example_id_key(): ms.get_example_id_default_parser(),
              ms.get_clip_label_index_key(): ms.get_clip_label_index_default_parser(),
              ms.get_clip_label_string_key(): ms.get_clip_label_string_default_parser(),
          }
          sequence_features = {
              ms.get_image_encoded_key(): ms.get_image_encoded_default_parser(),
          }
          (
              parsed_context,
              parsed_sequence,
          ) = tf.io.parse_single_sequence_example(
              sequence_example, context_features, sequence_features
          )
          example_id = parsed_context[ms.get_example_id_key()]
          classification_target = tf.one_hot(
              tf.sparse_tensor_to_dense(
                  parsed_context[ms.get_clip_label_index_key()]
              ),
              NUM_CLASSES,
          )
          images = tf.map_fn(
              tf.image.decode_jpeg,
              parsed_sequence[ms.get_image_encoded_key()],
              back_prop=False,
              dtype=tf.uint8,
          )
          return {
              "id": example_id,
              "labels": classification_target,
              "images": images,
          }
  
      if split not in SPLITS:
          raise ValueError("split '%s' is unknown." % split)
      all_shards = tf.io.gfile.glob(
          os.path.join(
              self.path_to_data, TF_RECORD_PATTERN % split + "-*-of-*"
          )
      )
      if shuffle:
          random.shuffle(all_shards)
      all_shards_dataset = tf.data.Dataset.from_tensor_slices(
          all_shards
      )
      cycle_length = min(16, len(all_shards))
      dataset = all_shards_dataset.apply(
          tf.data.experimental.parallel_interleave(
              tf.data.TFRecordDataset,
              cycle_length=cycle_length,
              block_length=1,
              sloppy=True,
              buffer_output_elements=serialized_prefetch_size,
          )
      )
      dataset = dataset.prefetch(serialized_prefetch_size)
      if shuffle:
          dataset = dataset.shuffle(serialized_prefetch_size)
      if repeat:
          dataset = dataset.repeat()
      dataset = dataset.map(parse_fn)
      dataset = dataset.prefetch(decoded_prefetch_size)
      return dataset
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import contextlib
  import csv
  import os
  import random
  import subprocess
  import sys
  import tempfile
  from absl import app
  from absl import flags
  from absl import logging
  from six.moves import range
  from six.moves import urllib
  import tensorflow.compat.v1
  from mediapipe.util.sequence import media_sequence
label_desc: Use image node_id 2 for calling the DemoDataset obj's underlying member method code with example usage: obj.as_dataset(split, shuffle, repeat, serialized_prefetch_size, decoded_prefetch_size) and returns: dataset, dict