code: def _prepare(self):
      if self.data_root:
          self.root = os.path.join(self.data_root, self.NAME)
      else:
          cachedir = os.environ.get(
              "XDG_CACHE_HOME", os.path.expanduser("~/.cache")
          )
          self.root = os.path.join(
              cachedir, "autoencoders/data", self.NAME
          )
  
      self.datadir = os.path.join(self.root, "data")
      self.txt_filelist = os.path.join(self.root, "filelist.txt")
      self.expected_length = 1281167
      self.random_crop = retrieve(
          self.config, "ImageNetTrain/random_crop", default=True
      )
      if not tdu.is_prepared(self.root):
          # prep
          print(
              "Preparing dataset {} in {}".format(self.NAME, self.root)
          )
  
          datadir = self.datadir
          if not os.path.exists(datadir):
              path = os.path.join(self.root, self.FILES[0])
              if (
                  not os.path.exists(path)
                  or not os.path.getsize(path) == self.SIZES[0]
              ):
                  import academictorrents as at
  
                  atpath = at.get(self.AT_HASH, datastore=self.root)
                  assert atpath == path
  
              print("Extracting {} to {}".format(path, datadir))
              os.makedirs(datadir, exist_ok=True)
              with tarfile.open(path, "r:") as tar:
                  tar.extractall(path=datadir)
  
              print("Extracting sub-tars.")
              subpaths = sorted(
                  glob.glob(os.path.join(datadir, "*.tar"))
              )
              for subpath in tqdm(subpaths):
                  subdir = subpath[: -len(".tar")]
                  os.makedirs(subdir, exist_ok=True)
                  with tarfile.open(subpath, "r:") as tar:
                      tar.extractall(path=subdir)
  
          filelist = glob.glob(os.path.join(datadir, "**", "*.JPEG"))
          filelist = [
              os.path.relpath(p, start=datadir) for p in filelist
          ]
          filelist = sorted(filelist)
          filelist = "\n".join(filelist) + "\n"
          with open(self.txt_filelist, "w") as f:
              f.write(filelist)
  
          tdu.mark_prepared(self.root)
  
imports: import glob
  import os
  import pickle
  import shutil
  import tarfile
  from functools import partial
  import albumentations
  import cv2
  import numpy
  import PIL
  import taming.data.utils
  import torchvision.transforms.functional
  import yaml
  from ldm.modules.image_degradation import degradation_fn_bsr, degradation_fn_bsr_light
  from omegaconf import OmegaConf
  from PIL import Image
  from taming.data.imagenet import ImagePaths, download, give_synsets_from_indices, retrieve, str_to_indices
  from torch.utils.data import Dataset, Subset
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling the ImageNetTrain obj's underlying member method code with example usage: obj._prepare() without return types