class_docstr: Endless Continual Leanring Simulator Dataset
class_docstr_tok: ["Endless","Continual","Leanring","Simulator","Dataset"]
docstr: Creates an instance of the Endless-Continual-Leanring-Simulator
  Dataset.
  
  This dataset is able to download and prepare datasets derived from the
  Endless-Continual-Learning Simulator, including settings of incremental
  classes, decrasing illumination, and shifting weather conditions, as
  described in the paper `A Procedural World Generation Framework for
  Systematic Evaluation of Continual Learning
  <https://arxiv.org/abs/2106.02585>`__.
  Also custom datasets are supported
  when following the same structure. Such can be obtained from the
  `Endless-CL-Simulator standalone application
  <https://zenodo.org/record/4899294>`__.
  
  Please note:
  1) The EndlessCLSimDataset does not provide examples directly, but
  SubsequenceDatasets (ClassificationSubSequence, VideoSubSequence). Each
  SubSequenceDataset will contain the samples for one respective sub
  sequence.
  
  2) For video sequences currently only one sequence per dataset is
  supported!
  
  :param root: root for the datasets data. Defaults to None, which means
      that the default location for 'endless-cl-sim' will be used.
  :param scenario: identifier for the dataset to be used.
      Predefined options are 'Classes', for incremental classes scenario,
      'Illumination', for the decreasing lighting scenario,
      and 'Weather', for the scenario of shifting weather conditions.
      To load a custom (non-predefined/downloadable) dataset, the
      identifier needs to be set to None. Defaults to None.
  :param patch_size: optional size of image data to be loaded.
      For classification the patch_size is of type `int`, because we only
      consider quadratic input sizes. If the `semseg` flag is set,
      the patch_size type is `tuple`, with `(width, height)`.
  :param transform: optional transformations to be applied to the image
      data.
  :param target_transform: optional transformations to be applied to the
      targets.
  :param download: boolean to automatically download data.
      Defaults to True.
  :param semseg: boolean to indicate the use of targets for a
      semantic segmentation task. Defaults to False.
  :param labelmap_path: path (str) to a labelmap.json file,
      that provides a dictionary mapping 'class-names'(str) to
      class-labels(int). The 'class-names' are derived from the
      sub-directory names for each subsequence.
code: def __init__(
      self,
      root: Optional[Union[str, Path]] = None,
      *,
      scenario=None,
      patch_size=64,
      transform=None,
      target_transform=None,
      download=True,
      semseg=False,
      labelmap_path=None,
  ):
      """Creates an instance of the Endless-Continual-Leanring-Simulator
      Dataset.
  
      This dataset is able to download and prepare datasets derived from the
      Endless-Continual-Learning Simulator, including settings of incremental
      classes, decrasing illumination, and shifting weather conditions, as
      described in the paper `A Procedural World Generation Framework for
      Systematic Evaluation of Continual Learning
      <https://arxiv.org/abs/2106.02585>`__.
      Also custom datasets are supported
      when following the same structure. Such can be obtained from the
      `Endless-CL-Simulator standalone application
      <https://zenodo.org/record/4899294>`__.
  
      Please note:
      1) The EndlessCLSimDataset does not provide examples directly, but
      SubsequenceDatasets (ClassificationSubSequence, VideoSubSequence). Each
      SubSequenceDataset will contain the samples for one respective sub
      sequence.
  
      2) For video sequences currently only one sequence per dataset is
      supported!
  
      :param root: root for the datasets data. Defaults to None, which means
          that the default location for 'endless-cl-sim' will be used.
      :param scenario: identifier for the dataset to be used.
          Predefined options are 'Classes', for incremental classes scenario,
          'Illumination', for the decreasing lighting scenario,
          and 'Weather', for the scenario of shifting weather conditions.
          To load a custom (non-predefined/downloadable) dataset, the
          identifier needs to be set to None. Defaults to None.
      :param patch_size: optional size of image data to be loaded.
          For classification the patch_size is of type `int`, because we only
          consider quadratic input sizes. If the `semseg` flag is set,
          the patch_size type is `tuple`, with `(width, height)`.
      :param transform: optional transformations to be applied to the image
          data.
      :param target_transform: optional transformations to be applied to the
          targets.
      :param download: boolean to automatically download data.
          Defaults to True.
      :param semseg: boolean to indicate the use of targets for a
          semantic segmentation task. Defaults to False.
      :param labelmap_path: path (str) to a labelmap.json file,
          that provides a dictionary mapping 'class-names'(str) to
          class-labels(int). The 'class-names' are derived from the
          sub-directory names for each subsequence.
      """
  
      if root is None:
          root = default_dataset_location("endless-cl-sim")
  
      if scenario is None and download:
          raise ValueError("No scenario defined to download!")
  
      super(EndlessCLSimDataset, self).__init__(
          root, download=download, verbose=True
      )
  
      self.scenario = scenario
      self.patch_size = patch_size
      self.transform = transform
      self.target_transform = target_transform
      self.semseg = semseg
      self.labelmap_path = labelmap_path
  
      self.train_sub_sequence_datasets: List[
          ClassificationSubSequence
      ] = []
      self.test_sub_sequence_datasets: List[
          ClassificationSubSequence
      ] = []
  
      if self.semseg and self.patch_size == 64:
          self.patch_size = (240, 135)
  
      if self.semseg:
          assert isinstance(
              self.patch_size, tuple
          ), "If semseg is False, patch_size needs to be of type `int`"
      else:
          assert isinstance(
              self.patch_size, int
          ), "If semseg is True, patch_size needs to be of type `tuple`"
  
      # Download the dataset and initialize metadata
      self._load_dataset()
      return
  
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 1 to create a new EndlessCLSimDataset object from inherited base classes: DownloadableDataset with example: obj = EndlessCLSimDataset(root)