class_docstr: A dataset to prepare the instance and class images with the prompts for fine-tuning the model.
  It pre-processes the images.
code: def __init__(
      self,
      instance_data_root,
      instance_prompt,
      class_prompt,
      class_data_root=None,
      class_num=None,
      size=1024,
      repeats=1,
      center_crop=False,
  ):
      self.size = size
      self.center_crop = center_crop
  
      self.instance_prompt = instance_prompt
      self.custom_instance_prompts = None
      self.class_prompt = class_prompt
  
      # if --dataset_name is provided or a metadata jsonl file is provided in the local --instance_data directory,
      # we load the training data using load_dataset
      if args.dataset_name is not None:
          try:
              from datasets import load_dataset
          except ImportError:
              raise ImportError(
                  "You are trying to load your data using the datasets library. If you wish to train using custom "
                  "captions please install the datasets library: `pip install datasets`. If you wish to load a "
                  "local folder containing images only, specify --instance_data_dir instead."
              )
          # Downloading and loading a dataset from the hub.
          # See more about loading custom images at
          # https://huggingface.co/docs/datasets/v2.0.0/en/dataset_script
          dataset = load_dataset(
              args.dataset_name,
              args.dataset_config_name,
              cache_dir=args.cache_dir,
          )
          # Preprocessing the datasets.
          column_names = dataset["train"].column_names
  
          # 6. Get the column names for input/target.
          if args.image_column is None:
              image_column = column_names[0]
              logger.info(f"image column defaulting to {image_column}")
          else:
              image_column = args.image_column
              if image_column not in column_names:
                  raise ValueError(
                      f"`--image_column` value '{args.image_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
                  )
          instance_images = dataset["train"][image_column]
  
          if args.caption_column is None:
              logger.info(
                  "No caption column provided, defaulting to instance_prompt for all images. If your dataset "
                  "contains captions/prompts for the images, make sure to specify the "
                  "column as --caption_column"
              )
              self.custom_instance_prompts = None
          else:
              if args.caption_column not in column_names:
                  raise ValueError(
                      f"`--caption_column` value '{args.caption_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
                  )
              custom_instance_prompts = dataset["train"][
                  args.caption_column
              ]
              # create final list of captions according to --repeats
              self.custom_instance_prompts = []
              for caption in custom_instance_prompts:
                  self.custom_instance_prompts.extend(
                      itertools.repeat(caption, repeats)
                  )
      else:
          self.instance_data_root = Path(instance_data_root)
          if not self.instance_data_root.exists():
              raise ValueError("Instance images root doesn't exists.")
  
          instance_images = [
              Image.open(path)
              for path in list(Path(instance_data_root).iterdir())
          ]
          self.custom_instance_prompts = None
  
      self.instance_images = []
      for img in instance_images:
          self.instance_images.extend(itertools.repeat(img, repeats))
      self.num_instance_images = len(self.instance_images)
      self._length = self.num_instance_images
  
      if class_data_root is not None:
          self.class_data_root = Path(class_data_root)
          self.class_data_root.mkdir(parents=True, exist_ok=True)
          self.class_images_path = list(self.class_data_root.iterdir())
          if class_num is not None:
              self.num_class_images = min(
                  len(self.class_images_path), class_num
              )
          else:
              self.num_class_images = len(self.class_images_path)
          self._length = max(
              self.num_class_images, self.num_instance_images
          )
      else:
          self.class_data_root = None
  
      self.image_transforms = transforms.Compose(
          [
              transforms.Resize(
                  size,
                  interpolation=transforms.InterpolationMode.BILINEAR,
              ),
              transforms.CenterCrop(size)
              if center_crop
              else transforms.RandomCrop(size),
              transforms.ToTensor(),
              transforms.Normalize([0.5], [0.5]),
          ]
      )
  
imports: import argparse
  import gc
  import itertools
  import logging
  import math
  import os
  import shutil
  import warnings
  from pathlib import Path
  import numpy
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  import transformers
  from accelerate import Accelerator
  from accelerate.logging import get_logger
  from accelerate.utils import DistributedDataParallelKwargs, ProjectConfiguration, set_seed
  from huggingface_hub import create_repo, upload_folder
  from huggingface_hub.utils import insecure_hashlib
  from packaging import version
  from peft import LoraConfig, set_peft_model_state_dict
  from peft.utils import get_peft_model_state_dict
  from PIL import Image
  from PIL.ImageOps import exif_transpose
  from torch.utils.data import Dataset
  from torchvision import transforms
  from tqdm.auto import tqdm
  from transformers import AutoTokenizer, PretrainedConfig
  import diffusers
  from diffusers import AutoencoderKL, DDPMScheduler, DPMSolverMultistepScheduler, StableDiffusionXLPipeline, UNet2DConditionModel
  from diffusers.loaders import LoraLoaderMixin
  from diffusers.optimization import get_scheduler
  from diffusers.training_utils import _set_state_dict_into_text_encoder, cast_training_params, compute_snr
  from diffusers.utils import check_min_version, convert_state_dict_to_diffusers, convert_unet_state_dict_to_peft, is_wandb_available
  from diffusers.utils.import_utils import is_xformers_available
  from diffusers.utils.torch_utils import is_compiled_module
label_desc: Use image node_id 1 to create a new DreamBoothDataset object from inherited base classes: Dataset with example: obj = DreamBoothDataset(instance_data_root, instance_prompt, class_prompt, class_data_root, class_num, size, repeats, center_crop)