class_docstr: Generates and loads a demo data set.
class_docstr_tok: ["Generates","and","loads","a","demo","data","set","."]
docstr: Downloads data and generates sharded TFRecords.
  
  Downloads the data files, generates metadata, and processes the metadata
  with MediaPipe to produce tf.SequenceExamples for training. The resulting
  files can be read with as_dataset(). After running this function the
  original data files can be deleted.
  
  Args:
    path_to_mediapipe_binary: Path to the compiled binary for the BUILD target
      mediapipe/examples/desktop/demo:media_sequence_demo.
    path_to_graph_directory: Path to the directory with MediaPipe graphs in
      mediapipe/graphs/media_sequence/.
docstr_tok: ["Downloads","data","and","generates","sharded","TFRecords",".","Downloads","the","data","files",",","generates","metadata",",","and","processes","the","metadata","with","MediaPipe","to","produce","tf.SequenceExamples","for","training",".","The","resulting","files","can","be","read","with","as_dataset","(",")",".","After","running","this","function","the","original","data","files","can","be","deleted",".","Args",":","path_to_mediapipe_binary",":","Path","to","the","compiled","binary","for","the","BUILD","target","mediapipe\/examples\/desktop\/demo",":","media_sequence_demo",".","path_to_graph_directory",":","Path","to","the","directory","with","MediaPipe","graphs","in","mediapipe\/graphs\/media_sequence\/","."]
code: def generate_examples(
      self, path_to_mediapipe_binary, path_to_graph_directory
  ):
      """Downloads data and generates sharded TFRecords.
  
      Downloads the data files, generates metadata, and processes the metadata
      with MediaPipe to produce tf.SequenceExamples for training. The resulting
      files can be read with as_dataset(). After running this function the
      original data files can be deleted.
  
      Args:
        path_to_mediapipe_binary: Path to the compiled binary for the BUILD target
          mediapipe/examples/desktop/demo:media_sequence_demo.
        path_to_graph_directory: Path to the directory with MediaPipe graphs in
          mediapipe/graphs/media_sequence/.
      """
      if not path_to_mediapipe_binary:
          raise ValueError(
              "You must supply the path to the MediaPipe binary for "
              "mediapipe/examples/desktop/demo:media_sequence_demo."
          )
      if not path_to_graph_directory:
          raise ValueError(
              "You must supply the path to the directory with MediaPipe graphs in "
              "mediapipe/graphs/media_sequence/."
          )
      logging.info("Downloading data.")
      tf.io.gfile.makedirs(self.path_to_data)
      if sys.version_info >= (3, 0):
          urlretrieve = urllib.request.urlretrieve
      else:
          urlretrieve = urllib.request.urlretrieve
      for split in SPLITS:
          reader = csv.DictReader(SPLITS[split].split("\n"))
          all_metadata = []
          for row in reader:
              url = row["url"]
              basename = url.split("/")[-1]
              local_path = os.path.join(self.path_to_data, basename)
              if not tf.io.gfile.exists(local_path):
                  urlretrieve(url, local_path)
  
              for start_time in range(
                  0, int(row["duration"]), SECONDS_PER_EXAMPLE
              ):
                  metadata = tf.train.SequenceExample()
                  ms.set_example_id(
                      bytes23(basename + "_" + str(start_time)),
                      metadata,
                  )
                  ms.set_clip_data_path(bytes23(local_path), metadata)
                  ms.set_clip_start_timestamp(
                      start_time * MICROSECONDS_PER_SECOND, metadata
                  )
                  ms.set_clip_end_timestamp(
                      (start_time + SECONDS_PER_EXAMPLE)
                      * MICROSECONDS_PER_SECOND,
                      metadata,
                  )
                  ms.set_clip_label_index(
                      (int(row["label index"]),), metadata
                  )
                  ms.set_clip_label_string(
                      (bytes23(row["label string"]),), metadata
                  )
                  all_metadata.append(metadata)
          random.seed(47)
          random.shuffle(all_metadata)
          shard_names = [
              self._indexed_shard(split, i) for i in range(NUM_SHARDS)
          ]
          writers = [
              tf.io.TFRecordWriter(shard_name)
              for shard_name in shard_names
          ]
          with _close_on_exit(writers) as writers:
              for i, seq_ex in enumerate(all_metadata):
                  for graph in GRAPHS:
                      graph_path = os.path.join(
                          path_to_graph_directory, graph
                      )
                      seq_ex = self._run_mediapipe(
                          path_to_mediapipe_binary, seq_ex, graph_path
                      )
                  writers[i % len(writers)].write(
                      seq_ex.SerializeToString()
                  )
  
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 3 for calling the DemoDataset obj's underlying member method code with example usage: obj.generate_examples(path_to_mediapipe_binary, path_to_graph_directory) without return types