class_docstr: Endless Continual Leanring Simulator Dataset
class_docstr_tok: ["Endless","Continual","Leanring","Simulator","Dataset"]
docstr: Prepare video subsequence datasets.
  
  :param path: (str) Path to the root of the data to be loaded.
  :return: success (bool) Boolean wether the preparation was successfull.
code: def _prepare_video_subsequence_datasets(self, path) -> bool:
      """Prepare video subsequence datasets.
  
      :param path: (str) Path to the root of the data to be loaded.
      :return: success (bool) Boolean wether the preparation was successfull.
      """
      # Get sequence dirs
      sequence_paths = glob.glob(path + os.path.sep + "*" + os.path.sep)
  
      # For every sequence (train, test)
      for sequence_path in sequence_paths:
          # Get dir contents (data + files)
          data_contents = glob.glob(sequence_path + os.path.sep + "*")
  
          image_paths = []
          target_paths = []
          sequence_file = None
          segmentation_file = None
  
          # Get Color, Seg dirs
          for data_content in data_contents:
              # If directory
              if Path(data_content).is_dir():
                  dir_name = data_content.split(os.path.sep)[-1]
                  if "Color" == dir_name:
                      # Extend color path
                      color_path = (
                          data_content + os.path.sep + "0" + os.path.sep
                      )
                      # Get all files
                      for file_name in sorted(os.listdir(color_path)):
                          image_paths.append(color_path + file_name)
                  elif "Seg" == dir_name:
                      # Extend seg path
                      seg_path = (
                          data_content + os.path.sep + "0" + os.path.sep
                      )
                      # Get all files
                      for file_name in sorted(os.listdir(seg_path)):
                          target_paths.append(seg_path + file_name)
  
              # If file
              if Path(data_content).is_file():
                  if "Sequence.json" in data_content:
                      sequence_file = data_content
                  elif "Segmentation.json" in data_content:
                      segmentation_file = data_content
  
          # Final checks
          if not len(image_paths) == len(target_paths):
              print("Not equal number of images and targets!")
              return False
          if sequence_file is None:
              print("No Sequence.json found!")
              return False
          if segmentation_file is None:
              print("No Segmentation.json found!")
              return False
  
          if self.verbose:
              print("All metadata checks complete!")
  
          sequence_indices = self._load_sequence_indices(
              sequence_file=sequence_file
          )
  
          if self.verbose:
              print("Sequence file loaded..")
  
          for i in range(len(sequence_indices)):
              last_index = sequence_indices[i]
              if (i + 1) == len(sequence_indices):
                  next_index = len(image_paths)
              else:
                  next_index = sequence_indices[i + 1]
  
              image_subsequence_paths = image_paths[
                  last_index:next_index
              ]
              target_subsequence_paths = target_paths[
                  last_index:next_index
              ]
  
              assert len(image_subsequence_paths) == len(
                  target_subsequence_paths
              )
  
              # Create subsequence dataset
              subsequence_dataset = VideoSubSequence(
                  image_subsequence_paths,
                  target_subsequence_paths,
                  segmentation_file,
                  patch_size=self.patch_size,
                  transform=self.transform,
                  target_transform=self.target_transform,
              )
              if "train" in (sequence_path.lower()):
                  self.train_sub_sequence_datasets.append(
                      subsequence_dataset
                  )
              elif "test" in (sequence_path.lower()):
                  self.test_sub_sequence_datasets.append(
                      subsequence_dataset
                  )
              else:
                  raise ValueError(
                      "Sequence path contains neighter 'train' nor \
                               'test' identifiers!"
                  )
      return True
  
imports: from pathlib import Path
  import glob
  import os
  from typing import List, Optional, Union
  from warnings import warn
  import sys
  import json
  import numpy
  from PIL import Image
  from torch.utils.data import Dataset
  from avalanche.benchmarks.datasets import default_dataset_location
  from avalanche.benchmarks.datasets.endless_cl_sim import endless_cl_sim_data
  from avalanche.benchmarks.datasets.downloadable_dataset import DownloadableDataset
label_desc: Use image node_id 5 for calling the EndlessCLSimDataset obj's underlying member method code with example usage: obj._prepare_video_subsequence_datasets(path) and returns: True, False, False, False