class_docstr: Base Self Supervised Learning Dataset Class.
  
  The GenericSSLDataset class is defined to support reading data
  from multiple data sources. For example: data = [dataset1, dataset2]
  and the minibatches generated will have the corresponding data
  from each dataset.
  
  For this reason, we also support labels from multiple sources. For example
  targets = [dataset1 targets, dataset2 targets].
  
  In order to support multiple data sources, the dataset configuration
  always has list inputs.
      - DATA_SOURCES, LABEL_SOURCES, DATASET_NAMES, DATA_PATHS, LABEL_PATHS
  
  For several data sources, we also support specifying on what dataset the
  transforms should be applied. By default, apply the transforms
  on data from all datasets.
  
  Args:
      cfg (AttrDict): configuration defined by user
      split (str): the dataset split for which we are constructing the Dataset object
      dataset_source_map (Dict[str, Callable]): The dictionary that maps
                  what data sources are supported and what object to use to read
                  data from those sources. For example:
                  DATASET_SOURCE_MAP = {
                      "disk_filelist": DiskImageDataset,
                      "disk_folder": DiskImageDataset,
                      "synthetic": SyntheticImageDataset,
                  }
      data_sources_with_subset (Set[str]): the set of datasets for which the subset
                  operation is supported inside GenericSSLDataset
class_docstr_tok: ["Base","Self","Supervised","Learning","Dataset","Class",".","The","GenericSSLDataset","class","is","defined","to","support","reading","data","from","multiple","data","sources",".","For","example",":","data","=","[","dataset1",",","dataset2","]","and","the","minibatches","generated","will","have","the","corresponding","data","from","each","dataset",".","For","this","reason",",","we","also","support","labels","from","multiple","sources",".","For","example","targets","=","[","dataset1","targets",",","dataset2","targets","]",".","In","order","to","support","multiple","data","sources",",","the","dataset","configuration","always","has","list","inputs",".","-","DATA_SOURCES",",","LABEL_SOURCES",",","DATASET_NAMES",",","DATA_PATHS",",","LABEL_PATHS","For","several","data","sources",",","we","also","support","specifying","on","what","dataset","the","transforms","should","be","applied",".","By","default",",","apply","the","transforms","on","data","from","all","datasets",".","Args",":","cfg","(","AttrDict",")",":","configuration","defined","by","user","split","(","str",")",":","the","dataset","split","for","which","we","are","constructing","the","Dataset","object","dataset_source_map","(","Dict","[","str",",","Callable","]",")",":","The","dictionary","that","maps","what","data","sources","are","supported","and","what","object","to","use","to","read","data","from","those","sources",".","For","example",":","DATASET_SOURCE_MAP","=","{","``","disk_filelist","''",":","DiskImageDataset",",","``","disk_folder","''",":","DiskImageDataset",",","``","synthetic","''",":","SyntheticImageDataset",",","}","data_sources_with_subset","(","Set","[","str","]",")",":","the","set","of","datasets","for","which","the","subset","operation","is","supported","inside","GenericSSLDataset"]
docstr: Load the labels if the dataset has labels. In self-supervised
  pre-training task, we don't use labels. However, we use labels for the
  evaluations of the self-supervised models on the downstream tasks.
  
  For labels, two label sources are supported: disk_filelist and disk_folder
  
  In case of disk_filelist, we iteratively read labels for each specified file.
  See load_single_label_file().
  In case of disk_folder, we use the ImageFolder object created during the
  data loading itself.
docstr_tok: ["Load","the","labels","if","the","dataset","has","labels",".","In","self-supervised","pre-training","task",",","we","do","n't","use","labels",".","However",",","we","use","labels","for","the","evaluations","of","the","self-supervised","models","on","the","downstream","tasks",".","For","labels",",","two","label","sources","are","supported",":","disk_filelist","and","disk_folder","In","case","of","disk_filelist",",","we","iteratively","read","labels","for","each","specified","file",".","See","load_single_label_file","(",")",".","In","case","of","disk_folder",",","we","use","the","ImageFolder","object","created","during","the","data","loading","itself","."]
code: def load_labels(self):
      """
      Load the labels if the dataset has labels. In self-supervised
      pre-training task, we don't use labels. However, we use labels for the
      evaluations of the self-supervised models on the downstream tasks.
  
      For labels, two label sources are supported: disk_filelist and disk_folder
  
      In case of disk_filelist, we iteratively read labels for each specified file.
      See load_single_label_file().
      In case of disk_folder, we use the ImageFolder object created during the
      data loading itself.
      """
      local_rank, _ = get_machine_local_and_dist_rank()
      for idx, label_source in enumerate(self.label_sources):
          if label_source == "disk_filelist":
              paths = self.label_paths[idx]
              # in case of filelist, we support multiple label files.
              # we rely on the user to have a proper collator to handle
              # the multiple labels
              logging.info(f"Loading labels: {paths}")
              if isinstance(paths, list):
                  labels = []
                  for path in paths:
                      path_labels = self.load_single_label_file(path)
                      labels.append(path_labels)
              else:
                  labels = self.load_single_label_file(paths)
                  labels = self._convert_to_numeric_ids(labels)
          elif label_source == "disk_folder":
              # In this case we use the labels inferred from the directory structure
              # We enforce that the data source also be a disk folder in this case
              assert self.data_sources[idx] == self.label_sources[idx]
              if local_rank == 0:
                  logging.info(
                      f"Using {label_source} labels from {self.data_paths[idx]}"
                  )
              # Use the ImageFolder object created when loading images.
              # We do not create it again since it can be an expensive operation.
              labels = [
                  x[1]
                  for x in self.data_objs[idx].image_dataset.samples
              ]
              labels = np.array(labels).astype(np.int64)
              # we save the class-idx-map to the disk here for convenience
              # so that the prediction labels can be mapped to class names
              # easily.
              self._save_label_cls_idx_map(
                  cls_idx_map=self.data_objs[
                      idx
                  ].image_dataset.class_to_idx,
                  split=self.split,
              )
          elif label_source == "torchvision_dataset":
              labels = np.array(
                  self.data_objs[idx].get_labels()
              ).astype(np.int64)
          elif label_source == "synthetic":
              labels = np.array(
                  self.data_objs[idx].get_labels()
              ).astype(np.int64)
          else:
              raise ValueError(f"unknown label source: {label_source}")
          self.label_objs.append(labels)
  
      self.labels_init = True
  
imports: import logging
  from typing import Any, Callable, Dict, Set
  import numpy
  from classy_vision.generic.distributed_util import get_world_size
  from iopath.common.file_io import g_pathmgr
  from vissl.config import AttrDict
  from vissl.data import dataset_catalog
  from vissl.data.data_helper import balanced_sub_sampling, unbalanced_sub_sampling
  from vissl.data.ssl_transforms import get_transform
  from vissl.data.vissl_dataset_base import VisslDatasetBase
  from vissl.utils.checkpoint import get_checkpoint_folder
  from vissl.utils.env import get_machine_local_and_dist_rank
  from vissl.utils.io import save_file
label_desc: Use image node_id 8 for calling the GenericSSLDataset obj's underlying member method code with example usage: obj.load_labels() without return types