class_docstr: Dataset that supports Tar archives (uncompressed).
  
  Args:
    archive (string or TarDataset): Path to the Tar file containing the dataset.
      Alternatively, pass in a TarDataset object to reuse its cached information;
      this is useful for loading different subsets within the same archive.
    extensions (tuple): Extensions (strings starting with a dot), only files
      with these extensions will be iterated. Default: png/jpg/jpeg.
    is_valid_file (callable): Optional function that takes file information as
      input (tarfile.TarInfo) and outputs True for files that need to be
      iterated; overrides extensions argument.
      Example: lambda m: m.isfile() and m.name.endswith('.png')
    transform (callable): Function applied to each image by __getitem__ (see
      torchvision.transforms). Default: ToTensor (convert PIL image to tensor).
  
  Attributes:
    members_by_name (dict): Members (files and folders) found in the Tar archive,
      with their names as keys and their tarfile.TarInfo structures as values.
    samples (list): Items to iterate (can be ignored by overriding __getitem__
      and __len__).
  
  Author: Joao F. Henriques
class_docstr_tok: ["Dataset","that","supports","Tar","archives","(","uncompressed",")",".","Args",":","archive","(","string","or","TarDataset",")",":","Path","to","the","Tar","file","containing","the","dataset",".","Alternatively",",","pass","in","a","TarDataset","object","to","reuse","its","cached","information",";","this","is","useful","for","loading","different","subsets","within","the","same","archive",".","extensions","(","tuple",")",":","Extensions","(","strings","starting","with","a","dot",")",",","only","files","with","these","extensions","will","be","iterated",".","Default",":","png\/jpg\/jpeg",".","is_valid_file","(","callable",")",":","Optional","function","that","takes","file","information","as","input","(","tarfile.TarInfo",")","and","outputs","True","for","files","that","need","to","be","iterated",";","overrides","extensions","argument",".","Example",":","lambda","m",":","m.isfile","(",")","and","m.name.endswith","(","'.png","'",")","transform","(","callable",")",":","Function","applied","to","each","image","by","__getitem__","(","see","torchvision.transforms",")",".","Default",":","ToTensor","(","convert","PIL","image","to","tensor",")",".","Attributes",":","members_by_name","(","dict",")",":","Members","(","files","and","folders",")","found","in","the","Tar","archive",",","with","their","names","as","keys","and","their","tarfile.TarInfo","structures","as","values",".","samples","(","list",")",":","Items","to","iterate","(","can","be","ignored","by","overriding","__getitem__","and","__len__",")",".","Author",":","Joao","F.","Henriques"]
code: def __init__(
      self,
      archive,
      transform=to_tensor,
      extensions=(".png", ".jpg", ".jpeg"),
      is_valid_file=None,
  ):
      if not isinstance(archive, TarDataset):
          # open tar file. in a multiprocessing setting (e.g. DataLoader workers), we
          # have to open one file handle per worker (stored as the tar_obj dict), since
          # when the multiprocessing method is 'fork', the workers share this TarDataset.
          # we want one file handle per worker because TarFile is not thread-safe.
          worker = get_worker_info()
          worker = worker.id if worker else None
          self.tar_obj = {worker: tarfile.open(archive)}
          self.archive = archive
  
          # store headers of all files and folders by name
          members = sorted(
              self.tar_obj[worker].getmembers(), key=lambda m: m.name
          )
          self.members_by_name = {m.name: m for m in members}
      else:
          # passed a TarDataset into the constructor, reuse the same tar contents.
          # no need to copy explicitly since this dict will not be modified again.
          self.members_by_name = archive.members_by_name
          self.archive = (
              archive.archive
          )  # the original path to the Tar file
          self.tar_obj = (
              {}
          )  # will get filled by get_file on first access
  
      # also store references to the iterated samples (a subset of the above)
      self.filter_samples(is_valid_file, extensions)
  
      self.transform = transform
  
file_path: zoo/src/datamodules/datasets/tardataset.py
imports: import tarfile
  from io import BytesIO
  from PIL import Image, ImageFile
  from torch.utils.data import Dataset, get_worker_info
label_desc: Use image node_id 1 to create a new TarDataset object from inherited base classes: Dataset with example: obj = TarDataset(archive, transform, extensions, is_valid_file)