d8ahazard / sd_dreambooth_extension

Other
1.85k stars 281 forks source link

[Bug]: When Cache Latents is off I get: if img_path not in data_cache["captions"] and not self.debug_dataset: KeyError: 'captions' #1399

Closed morphinapg closed 7 months ago

morphinapg commented 7 months ago

Is there an existing issue for this?

What happened?

I recently updated the dreambooth extension to the most recent version, and started getting this error for every single image in my dataset. I tried 1.1.0 and it had the same issue, but 1.0.14 worked fine (although was further back than I was before I updated). I use [filewords] only for my prompt, and don't use any instance or class tokens. Don't use class images. Cache Latents is off.

If I turn Cache Latents on, it works, although I notice it seems to be a lot slower than the older version.

Steps to reproduce the problem

  1. Create a new model
  2. set dataset folder
  3. set prompt to [filewords]
  4. Cache Latents OFF
  5. save settings
  6. train

Commit and libraries

Initializing Dreambooth Dreambooth revision: c548ede6a3acb85d78650ff50ae583786b305f0e Checking xformers... Checking bitsandbytes... Checking bitsandbytes (Windows) Virtual environment path: C:\Stable Diffusion\venv Checking for C:\Stable Diffusion\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll Checking Dreambooth requirements... [Dreambooth] accelerate v0.21.0 is already installed. [Dreambooth] dadaptation v3.1 is already installed. [Dreambooth] diffusers v0.23.1 is already installed. [Dreambooth] discord-webhook v1.3.0 is already installed. [Dreambooth] fastapi is already installed. [Dreambooth] gitpython v3.1.40 is not installed. Successfully installed gitpython-3.1.40

[Dreambooth] pytorch_optimizer v2.12.0 is already installed. [Dreambooth] Pillow is already installed. [Dreambooth] tqdm is already installed. [Dreambooth] tomesd v0.1.2 is already installed. [Dreambooth] transformers v4.30.2 is already installed. [Dreambooth] tensorboard v2.13.0 is already installed. [!] xformers version 0.0.20 installed. [+] torch version 2.0.1+cu118 installed. [+] torchvision version 0.15.2+cu118 installed. [+] accelerate version 0.21.0 installed. [+] diffusers version 0.23.1 installed. [+] transformers version 4.30.2 installed. [+] bitsandbytes version 0.41.1 installed.

Command Line Arguments

--xformers

Console logs

Advanced elements visible: False
Advanced elements visible: True
Extracting config from C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\..\configs\v1-training-unfrozen.yaml
Extracting checkpoint from C:\Stable Diffusion\models\Stable-diffusion\realisticVisionV51_v51VAE.safetensors
C:\Stable Diffusion\venv\lib\site-packages\transformers\models\clip\feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use CLIPImageProcessor instead.
  warnings.warn(
Duration: 00:00:09
Updating scheduler name to: DDIM
Initializing dreambooth training...
                                                                                                                       Init dataset!set:   0%|                                                                           | 0/5 [00:00<?, ?it/s]
Preparing Dataset (Without Caching)
                                                                                                                       Traceback (most recent call last):                                                                | 0/4 [00:00<?, ?it/s]
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\db_dataset.py", line 398, in cache_images
    if img_path not in data_cache["captions"] and not self.debug_dataset:
KeyError: 'captions'
Exception caching: C:\Stable Diffusion\dataset\morph\A closeup photo of morphinapg with a black shirt, in front of a wall.png: 'captions'
Traceback (most recent call last):
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\db_dataset.py", line 398, in cache_images
    if img_path not in data_cache["captions"] and not self.debug_dataset:
KeyError: 'captions'
Exception caching: C:\Stable Diffusion\dataset\morph\A closeup photo of morphinapg with a white shirt, with sunlight hitting him from the side, sitting in front of a white wall.png: 'captions'
Traceback (most recent call last):
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\db_dataset.py", line 398, in cache_images
    if img_path not in data_cache["captions"] and not self.debug_dataset:
KeyError: 'captions'
Exception caching: C:\Stable Diffusion\dataset\morph\A professional headshot of morphinapg standing outside with trees behind him, backlit, with the camera tilted upwards.png: 'captions'
Traceback (most recent call last):
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\db_dataset.py", line 398, in cache_images
    if img_path not in data_cache["captions"] and not self.debug_dataset:
KeyError: 'captions'
Exception caching: C:\Stable Diffusion\dataset\morph\morphinapg with a serious face wearing a black shirt with a design, and standing in a living room with a painting behind him.png: 'captions'
Bucket 0 (512, 512, 0) - Instance Images: 4 | Class Images: 0 | Max Examples/batch: 4
Total Buckets 1 - Instance Images: 4 | Class Images: 0 | Max Examples/batch: 4

Total images / batch: 4, total examples: 4                                                       | 0/4 [00:00<?, ?it/s]
                  Initializing bucket counter!
Steps:   0%|                                                                                   | 0/364 [00:00<?, ?it/s]Traceback (most recent call last):
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 735, in start_training
    result = main(class_gen_method=class_gen_method)
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1830, in main
    return inner_loop()
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\memory.py", line 126, in decorator
    return function(batch_size, grad_size, prof, *args, **kwargs)
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1493, in inner_loop
    for step, batch in enumerate(train_dataloader):
  File "C:\Stable Diffusion\venv\lib\site-packages\accelerate\data_loader.py", line 384, in __iter__
    current_batch = next(dataloader_iter)
  File "C:\Stable Diffusion\venv\lib\site-packages\torch\utils\data\dataloader.py", line 633, in __next__
    data = self._next_data()
  File "C:\Stable Diffusion\venv\lib\site-packages\torch\utils\data\dataloader.py", line 676, in _next_data
    index = self._next_index()  # may raise StopIteration
  File "C:\Stable Diffusion\venv\lib\site-packages\torch\utils\data\dataloader.py", line 623, in _next_index
    return next(self._sampler_iter)  # may raise StopIteration
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\bucket_sampler.py", line 23, in __iter__
    batch = self.fill_batch()
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\bucket_sampler.py", line 77, in fill_batch
    img_index, img_repeats = self.dataset.get_example(current_res)
  File "C:\Stable Diffusion\extensions\sd_dreambooth_extension\dreambooth\dataset\db_dataset.py", line 525, in get_example
    image_index = self.sample_indices.index(image_path)
ValueError: 'C:\\Stable Diffusion\\dataset\\morph\\A professional headshot of morphinapg standing outside with trees behind him, backlit, with the camera tilted upwards.png' is not in list
Steps:   0%|                                                                                   | 0/364 [00:00<?, ?it/s]
Duration: 00:00:04
Duration: 00:00:05

Additional information

I just created a small folder with 4 image files with descriptive filenames to demonstrate what was happening.

d8ahazard commented 7 months ago

This should now be fixed.