class_docstr: A generic data loader where the samples are arranged in this way: ::
  
      root/domain_a/class_1/xxx.ext
      root/domain_a/class_1/xxy.ext
      root/domain_a/class_2/xxz.ext
  
      root/domain_b/class_1/efg.ext
      root/domain_b/class_2/pqr.ext
      root/domain_b/class_2/lmn.ext
  
      root/domain_k/class_2/123.ext
      root/domain_k/class_1/abc3.ext
      root/domain_k/class_1/asd932_.ext
  
  Args:
      root (string): Root directory path.
      loader (callable): A function to load a sample given its path.
      extensions (tuple[string]): A list of allowed extensions. Either extensions or is_valid_file should be
          passed.
      transform (callable, optional): A function/transform that takes in a sample and returns a transformed
          version.  E.g, ``transforms.RandomCrop`` for images.
      target_transform (callable, optional): A function/transform that takes in the target and transforms it.
      sub_domain_set (list): A list of domain names, which should be a subset of domains (folders) under the root
          directory. If None, all available domains will be used. Defaults to None.
      sub_class_set (list): A list of class names, which should be a subset of classes (folders) under each
          domain's directory. If None, all available classes will be used. Defaults to None.
      is_valid_file (callable, optional): A function that takes path of a file and check if the file is a valid
          file (to check corrupt files). Either extensions or is_valid_file should be passed.
   Attributes:
      classes (list): List of the class names sorted alphabetically.
      class_to_idx (dict): Dict with items (class_name, class_index).
      samples (list): List of (sample path, class_index) tuples
      targets (list): The class_index value for each image in the dataset
      domains (list): List of the domain names sorted alphabetically.
      domain_to_idx (dict): Dict with items (domain_name, domain_index).
      domain_labels (list): The domain_index value for each image in the dataset
class_docstr_tok: ["A","generic","data","loader","where","the","samples","are","arranged","in","this","way",":",":",":","root\/domain_a\/class_1\/xxx.ext","root\/domain_a\/class_1\/xxy.ext","root\/domain_a\/class_2\/xxz.ext","root\/domain_b\/class_1\/efg.ext","root\/domain_b\/class_2\/pqr.ext","root\/domain_b\/class_2\/lmn.ext","root\/domain_k\/class_2\/123.ext","root\/domain_k\/class_1\/abc3.ext","root\/domain_k\/class_1\/asd932_.ext","Args",":","root","(","string",")",":","Root","directory","path",".","loader","(","callable",")",":","A","function","to","load","a","sample","given","its","path",".","extensions","(","tuple","[","string","]",")",":","A","list","of","allowed","extensions",".","Either","extensions","or","is_valid_file","should","be","passed",".","transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","a","sample","and","returns","a","transformed","version",".","E.g",",","``","transforms.RandomCrop","``","for","images",".","target_transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","the","target","and","transforms","it",".","sub_domain_set","(","list",")",":","A","list","of","domain","names",",","which","should","be","a","subset","of","domains","(","folders",")","under","the","root","directory",".","If","None",",","all","available","domains","will","be","used",".","Defaults","to","None",".","sub_class_set","(","list",")",":","A","list","of","class","names",",","which","should","be","a","subset","of","classes","(","folders",")","under","each","domain","'s","directory",".","If","None",",","all","available","classes","will","be","used",".","Defaults","to","None",".","is_valid_file","(","callable",",","optional",")",":","A","function","that","takes","path","of","a","file","and","check","if","the","file","is","a","valid","file","(","to","check","corrupt","files",")",".","Either","extensions","or","is_valid_file","should","be","passed",".","Attributes",":","classes","(","list",")",":","List","of","the","class","names","sorted","alphabetically",".","class_to_idx","(","dict",")",":","Dict","with","items","(","class_name",",","class_index",")",".","samples","(","list",")",":","List","of","(","sample","path",",","class_index",")","tuples","targets","(","list",")",":","The","class_index","value","for","each","image","in","the","dataset","domains","(","list",")",":","List","of","the","domain","names","sorted","alphabetically",".","domain_to_idx","(","dict",")",":","Dict","with","items","(","domain_name",",","domain_index",")",".","domain_labels","(","list",")",":","The","domain_index","value","for","each","image","in","the","dataset"]
code: def __init__(
      self,
      root: str,
      loader: Callable[[str], Any] = default_loader,
      extensions: Optional[Tuple[str, ...]] = IMG_EXTENSIONS,
      transform: Optional[Callable] = None,
      target_transform: Optional[Callable] = None,
      sub_domain_set=None,
      sub_class_set=None,
      is_valid_file: Optional[Callable[[str], bool]] = None,
      return_domain_label: Optional[bool] = False,
      split_train_test: Optional[bool] = False,
      split_ratio: float = 0.8,
  ) -> None:
      super(MultiDomainImageFolder, self).__init__(
          root, transform=transform, target_transform=target_transform
      )
      domains, domain_to_idx = self._find_classes(self.root)
      if isinstance(sub_domain_set, list):
          for domain_name in sub_domain_set:
              if domain_name not in domains:
                  raise ValueError(
                      "Domain %s not in the image directory"
                      % domain_name
                  )
          domains = sub_domain_set
          domain_to_idx = {
              domain_name: i
              for i, domain_name in enumerate(sub_domain_set)
          }
  
      classes, class_to_idx = self._find_classes(
          os.path.join(self.root, domains[0])
      )
      if isinstance(sub_class_set, list):
          for class_name in sub_class_set:
              if class_name not in classes:
                  raise ValueError(
                      "Class %s not in the image directory" % class_name
                  )
          classes = sub_class_set
          class_to_idx = {
              class_name: i
              for i, class_name in enumerate(sub_class_set)
          }
      samples = make_multi_domain_set(
          self.root,
          class_to_idx,
          domain_to_idx,
          extensions,
          is_valid_file,
      )
      if len(samples) == 0:
          msg = "Found 0 files in sub-folders of: {}\n".format(
              self.root
          )
          if extensions is not None:
              msg += "Supported extensions are: {}".format(
                  ",".join(extensions)
              )
          raise RuntimeError(msg)
  
      self.loader = loader
      self.extensions = extensions
  
      self.classes = classes
      self.class_to_idx = class_to_idx
      self.samples = samples
      self.targets = [s[1] for s in samples]
      self.domains = domains
      self.domain_to_idx = domain_to_idx
      self.domain_labels = [s[2] for s in samples]
      self.return_domain_label = return_domain_label
      self.split_train_test = split_train_test
      self.split_ratio = split_ratio
      if split_train_test and 0 < split_ratio < 1:
          self.train_idx, self.test_idx = _domain_stratified_split(
              self.domain_labels, 2, [split_ratio]
          )
      else:
          self.train_idx = None
          self.test_idx = None
  
imports: import logging
  import os
  from enum import Enum
  from typing import Any, Callable, cast, Dict, List, Optional, Tuple
  import numpy
  import torch.utils.data
  from sklearn.utils import check_random_state
  from torchvision.datasets import VisionDataset
  from torchvision.datasets.folder import default_loader, has_file_allowed_extension, IMG_EXTENSIONS
  from kale.loaddata.dataset_access import DatasetAccess, get_class_subset, split_by_ratios
  from kale.loaddata.sampler import FixedSeedSamplingConfig, get_labels, MultiDataLoader, SamplingConfig
label_desc: Use image node_id 1 to create a new MultiDomainImageFolder object from inherited base classes: VisionDataset with example: obj = MultiDomainImageFolder(root, loader, extensions, transform, target_transform, sub_domain_set, sub_class_set, is_valid_file, return_domain_label, split_train_test, split_ratio)