docstr: Imagenet Superresolution Dataloader
  Performs following ops in order:
  1.  crops a crop of size s from image either as random or center crop
  2.  resizes crop to size with cv2.area_interpolation
  3.  degrades resized crop with degradation_fn
  
  :param size: resizing to size after cropping
  :param degradation: degradation_fn, e.g. cv_bicubic or bsrgan_light
  :param downscale_f: Low Resolution Downsample factor
  :param min_crop_f: determines crop size s,
    where s = c * min_img_side_len with c sampled from interval (min_crop_f, max_crop_f)
  :param max_crop_f: ""
  :param data_root:
  :param random_crop:
docstr_tok: ["Imagenet","Superresolution","Dataloader","Performs","following","ops","in","order",":","1.","crops","a","crop","of","size","s","from","image","either","as","random","or","center","crop","2.","resizes","crop","to","size","with","cv2.area_interpolation","3.","degrades","resized","crop","with","degradation_fn",":","param","size",":","resizing","to","size","after","cropping",":","param","degradation",":","degradation_fn",",","e.g",".","cv_bicubic","or","bsrgan_light",":","param","downscale_f",":","Low","Resolution","Downsample","factor",":","param","min_crop_f",":","determines","crop","size","s",",","where","s","=","c","*","min_img_side_len","with","c","sampled","from","interval","(","min_crop_f",",","max_crop_f",")",":","param","max_crop_f",":","``","''",":","param","data_root",":",":","param","random_crop",":"]
code: def __init__(
      self,
      size=None,
      degradation=None,
      downscale_f=4,
      min_crop_f=0.5,
      max_crop_f=1.0,
      random_crop=True,
  ):
      """
      Imagenet Superresolution Dataloader
      Performs following ops in order:
      1.  crops a crop of size s from image either as random or center crop
      2.  resizes crop to size with cv2.area_interpolation
      3.  degrades resized crop with degradation_fn
  
      :param size: resizing to size after cropping
      :param degradation: degradation_fn, e.g. cv_bicubic or bsrgan_light
      :param downscale_f: Low Resolution Downsample factor
      :param min_crop_f: determines crop size s,
        where s = c * min_img_side_len with c sampled from interval (min_crop_f, max_crop_f)
      :param max_crop_f: ""
      :param data_root:
      :param random_crop:
      """
      self.base = self.get_base()
      assert size
      assert (size / downscale_f).is_integer()
      self.size = size
      self.LR_size = int(size / downscale_f)
      self.min_crop_f = min_crop_f
      self.max_crop_f = max_crop_f
      assert max_crop_f <= 1.0
      self.center_crop = not random_crop
  
      self.image_rescaler = albumentations.SmallestMaxSize(
          max_size=size, interpolation=cv2.INTER_AREA
      )
  
      self.pil_interpolation = (
          False  # gets reset later if incase interp_op is from pillow
      )
  
      if degradation == "bsrgan":
          self.degradation_process = partial(
              degradation_fn_bsr, sf=downscale_f
          )
  
      elif degradation == "bsrgan_light":
          self.degradation_process = partial(
              degradation_fn_bsr_light, sf=downscale_f
          )
  
      else:
          interpolation_fn = {
              "cv_nearest": cv2.INTER_NEAREST,
              "cv_bilinear": cv2.INTER_LINEAR,
              "cv_bicubic": cv2.INTER_CUBIC,
              "cv_area": cv2.INTER_AREA,
              "cv_lanczos": cv2.INTER_LANCZOS4,
              "pil_nearest": PIL.Image.NEAREST,
              "pil_bilinear": PIL.Image.BILINEAR,
              "pil_bicubic": PIL.Image.BICUBIC,
              "pil_box": PIL.Image.BOX,
              "pil_hamming": PIL.Image.HAMMING,
              "pil_lanczos": PIL.Image.LANCZOS,
          }[degradation]
  
          self.pil_interpolation = degradation.startswith("pil_")
  
          if self.pil_interpolation:
              self.degradation_process = partial(
                  TF.resize,
                  size=self.LR_size,
                  interpolation=interpolation_fn,
              )
  
          else:
              self.degradation_process = albumentations.SmallestMaxSize(
                  max_size=self.LR_size, interpolation=interpolation_fn
              )
  
imports: import os, yaml, pickle, shutil, tarfile, glob
  import cv2
  import albumentations
  import PIL
  import numpy
  import torchvision.transforms.functional
  from omegaconf import OmegaConf
  from functools import partial
  from PIL import Image
  from tqdm import tqdm
  from torch.utils.data import Dataset, Subset
  import taming.data.utils
  from taming.data.imagenet import str_to_indices, give_synsets_from_indices, download, retrieve
  from taming.data.imagenet import ImagePaths
  from ldm.modules.image_degradation import degradation_fn_bsr, degradation_fn_bsr_light
label_desc: Use image node_id 1 to create a new ImageNetSR object from inherited base classes: Dataset with example: obj = ImageNetSR(size, degradation, downscale_f, min_crop_f, max_crop_f, random_crop)