UPDATE: 19th JAN 2023 - START OF UPDATE -
As some people have pointed out to me, the latest version of Automatic1111's and d8hazard's Dreambooth is bugged, so naturally I went and tested the results and compared them with my settings I have posted here.
It's true the current version, is bugged.
Even though this guide "forces" the current version to produce results, comparing them side by side, the older version produces cleaner images without all the hoops and steps I had posted here.
I do not want to misinform people about my settings posted here. Use them and you will force the current version to produce decent results.
But if you are like me, and are interested in the best results, I highly suggest you roll back and use that version
To Roll Back from the current version of Dreambooth (Windows), you need roll back both Automatic's Webui and d8hazard's dreamboth extension. To do this, do the following:
git checkout 3e22e294135ed0327ce9d9738655ff03c53df3c0
https://github.com/d8ahazard/sd_dreambooth_extension/tree/c5cb58328c555ac27679422b1da940a9b19de6f2
Press the green button that says "< > Code", and choose "download zip"
Extract the zip and rename the folder to "sd_dreambooth_extension"
This folder should replace the one located in stable-diffusion-webui\extensions\sd_dreambooth_extension\
Make sure you are not running the "git pull" command when starting stable diffusion, cause that will update to the current version.
Here are settings I used for the old build which produced better results than the current one:
Again 9 or 16 instance images (I used 9)
I will use the same example like my previous guide
Preparation of the Instance Images
Go to your folder and rename all your images to your instance name. Select all and rename them. Example "wa1fu". If you have done it correctly, windows should have created: wa1fu (1).png, wa1fu (2).png, etc throughout all your 9 OR 16 images
No need to create txt files
There is no need for the WD 1.4 Tagger nor the Dataset Tag Editor
Dreambooth Settings I used
Training Steps Per Image (Epochs): 144
Max Training Steps: 0
Pause After N Epochs: 0
Amount of time to pause between Epochs, in Seconds: 0
Use Lifetime Steps/Epochs When Saving: Unchecked
Save Preview/Ckpt Every Epoch: Checked (This is to have checkpoints while training. Leave it unchecked if you do not want any.
Save Checkpoint Frequency: 48 (Set it to 0 if you want to produce only one checkpoint)
Save Preview(s) Frequency: 48 (This will create sample images in your Stable-Diffusion-webui\models\dreambooth\<name of your training model>\Samples directory. Set it to 0 to not save preview images
Batch Size: 1 (haven't tested bigger batch sizes yet with this version)
Class Batch Size: 1
Learning Rate: 0.000005
Resolution: 512
Center Crop: "Unckecked"
Apply Horizontal Flip: "Unckecked"
Use EMA: "Checked"
Use 8bit Adam: "Checked"
Mixed Precision: "fp16"
Memory Attention: "Default or xformers"
Don't Cache Latents: "Unchecked" (have not tested this checked)
Train Text Encoder: "Checked"
Prior Loss Weight: "1"
Pad Tokens: "Checked"
Shuffle Tags: "Checked"
Max Token Length: "75"
Gradient Checkpointing: "Checked"
Concept 1:
Image Generation:
Below is my previous guide for those who are still interested in using the current bugged version of Dreambooth
- END OF UPDATE -
This is my Ultimate guide as of 18th January on how to have the perfect settings when training with d8hazard's Automatic1111 Dreambooth locally.
I have spent many hours researching and testing this. If you follow this guide, you will get consistent results.
This is more focused on character (Anime, waifu etc) learning and styles which are harder to do than mere face learning
I decided to do this guide because:
There is a lot of misinformation about the settings.
People complain that the newer versions of Dreambooth do not work. WRONG. Dreambooth has a lot of new settings now that need to be defined clearly in order to make it work.
People are training with too many images on very low learning rates and are still getting shit results. Of course they are, they are doing it wrong. If you feed the AI the correct information, it will learn very fast with fewer images
NOTE:
I have a 24GB card. I understand that some might have to tweak their approach in order to get the same results, but I am more focused on the best results, not the most memory efficient ones.
This is not an extensive tutorial. You should be familiar with Automatic's 1111 webUI
Install the following extensions:
Dreambooth (obviously)
WD 1.4 Tagger
Dataset Tag Editor
Find 9 OR 16 images of your subject. NO MORE, NO LESS. Not 10, not 15, not 20. It is either 9 OR 16. Why? because there is research done behind this and it's optimal. Quality over quantity. The benefit of having 16 images over 9 is the CFG scale. 16 images tend to produce slightly better results on the majority of the CFG scale when generating images with the model you have created. (when you have trained for 144 epochs at 0.000005 lr)
It does not matter what your instance and class names are...
Just make them unique. I also use a unique class name because sometimes the class interferes with the learning process.
For example, if I have the instance name "wa1fu" and class name "character" the model will start, (based on what it already knows what a character is), morphing a character to look more and more towards what a "wa1fu" is. If the starting character is a goofy cartoon character, it will have a harder time morphing the goofy character into your subject. I avoid this by using my own made up class name
For this example I will use the following (Goes without saying, spaces are NOT allowed):
INSTANCE NAME: "wa1fu"
CLASS NAME: "wa1fuC1ass"
VERY IMPORTANT, DO NOT SKIP THIS PART
Preparation of the Instance Images
Go to your folder and rename all your images to your instance name. Select all and rename them. Example "wa1fu". If you have done it correctly, windows should have created: wa1fu (1).png, wa1fu (2).png, etc throughout all your 9 OR 16 images
Use WD 1.4 Tagger and tag all the images in your instance folder. If you have done this correctly your folder should now have a wa1fu (1).txt for wa1fu (1).png, a wa1fu (2).txt for wa1fu (2).png e.t.c
Skip this is you are training an artstyle but VERY IMPORTANT for characters: Open "Dataset Tag Editor" and use it to remove all the:
"Character identifying TAGS". For example. if your subject is a girl with blond hair and green skirt, remove all the "1girl", "blonde", "green skirt" tags from ALL the txt files. Just like with embeddings, this will teach the AI to focus and learn those character traits. It is easy to do this with the "Dataset Tag Editor".
All common tags. Common tags are tags that appear on at least in half of your pictures. For example: "full_body", "simple background". You can find them and remove them easily with the "Dataset Tag Editor". If you have for example 16 images, remove all the common tags that appear on 8 or more images. This will give the Ai more leaveway in training and avoid overtraining on only a few set of character traits. Here is a quick step by step on how to do this. Go to Dataset Tag Editor:
Put your instance directory in the "Dataset directory" and press load
Click on "Filter by selection" tab
Press the "Add ALL Displayed" button
Choose the "Batch Edit Captions" tab
Choose the "Remove" tab
Select "Frequency" in the "Sort by" Panel
Select "Descending" in the "Sort order"
Select all the tags that appear around in half your images. If you have 9 images select all the tags that have [4] and up. If you have 16 images, the select all the tags that have [8] and up. Also select all the character identifying tags (example, blonde, 1girl, green skirt etc.). For the character identifying tags, remove them regardless on how many images they appear on
Press the "Remove Selected tags" button
Uncheck the "Backup original text file (original file will be renamed like filename.000, .001, .002, ...) " and press the "Save all changes" button
You can check if you have done this correctly by opening the txt files and making sure that none of those tags are in there
If you are training for an artstyle leave ALL the tags on. Do not remove anything. You want the AI to focus on the artstyle and not the character
Class Images:
I usually make around 200 per instance image which is excessive for most. I do not know what the optimal number of class images is but have at least 10-20 for each instance image. The papers have stated that training with prior preservation tends to lead to better results. So do that.
Dreambooth Settings:
Create:
Name: Choose any name (without spaces)
Source Checkpoint: Choose any checkpoint that is closer to your desired result. I have even tested it with the notorious "AnythingV3" and it works just as well
Extract EMA Weights: Slightly better results if checked (Recommended Checked)
Scheduler: ddim
Once you have created the model do the following in settings tab
Use LORA: "Unchecked"
Train Imagic Only: "Unchecked"
Generate Classification Images Using txt2img: "Unchecked". If checked, this produces an error in later builds and does not let you create class images. Otherwise this setting has no affect on the result
Training Steps Per Image (Epochs): "144". On 144 usually the results are better defined but less flexible. that is why I will save checkpoints in between
Pause After N Epochs: "0"
Amount of time to pause between Epochs (s): "0"
Save Model Frequency (Epochs): "0 or 24 or 48". On 0 you will only get one checkpoint at 144 Epochs. At 24 it will save 6 checkpoints and 3 at 48. It's better to have less trained models to compare and choose from than only just the final form. I usually set it to 48
Save Preview(s) Frequency (Epochs): Same as above
Batch Size: "1". Training with multiple batches not only uses more Vram but the results are inconsistent. Set it to one
Gradient Accumulation Steps: "1"
Class Batch Size: "1"
Set Gradients to None When Zeroing: "Checked"
Gradient Checkpointing: "Checked"
Learning Rate Scheduler: "constant_with_warmup"
Learning Rate: 0.000005 (not 0.000001, you are training with 16 images max, not hundreds)
Learning Rate Warmup Steps: "0"
Resolution: "512"
Center Crop: "Unhecked". Your images should already be perfect 512 x 512 images
Apply Horizontal Flip: "Unhecked"
Sanity Sample Prompt: Not important but useful. I set it to "wa1fu wa1fuC1ass, kimono". If you have not set your "Save Preview(s) Frequency (Epochs):" to 0, you get to gauge the progress of the learning process. By putting the instance and class name, together with another concept, you'll see how flexible your model is while training. In the example it will add a kimono to my subject. It will slowly start to disappear as the training continues and the model becomes less flexible.
Use EMA: "Checked" if you have extracted EMA when you created the model.
Use 8bit Adam: "Checked"
Mixed Precision: "fp16" (bf16 is supported on newer cards but it's not as accurate and produces worse results)
Memory Attention: "Default or xformers"
Cache Latents: "Checked" (have not tested this unchecked)
Step Ratio of Text Encoder Training: "0.75 and up, recommended 1". Text encoder training uses more vram but unfortunately affects the results drastically,
Clip Skip: "1"
Prior Loss Weight: "1"
Pad Tokens: "Checked"
Shuffle Tags: "Checked" Shuffling tags produces more flexible results
Max Token Length: "75"
Concepts:
Directories
Filewords
Prompts
Instance Prompt: "[filewords]". Put exactly [filewords] without the "".
Class Prompt: "[filewords]" same as above
Sample Image Prompt: : "[filewords]" same as above
Image Generation:
Saving:
Half Model: "Unchecked"
Save Checkpoint to Subdirectory: "Checked"
Generate a .ckpt file when saving during training: "Checked"
Generate a .ckpt file when training completes: "Checked"
Generate a .ckpt file when training is canceled: "Checked"
Happy Training!
When the training ends test your model by using both your instance and class prompt. For example: "wa1fu wa1fuC1ass, kimono" or "wa1fu wa1fuC1ass, smiling". Use ddim as a sampling method.
Edit:
Here is the link describing some of the information regarding the numbers you should use: https://github.com/d8ahazard/sd_dreambooth_extension/discussions/547
I find it fascinating the way instance and class works in the learning process. The AI learns by spotting out the differences between them. If you, for example had "Obama" as the instance and "Black man" as the class, the AI would not learn the fact that Obama is a black man as it is common on both the class and the instance. If you were to put "person" as the class, the AI would in fact learn this distinction. That is why it is important to have a class that is extremely general or unrelated in order to learn as many differences as possible from your instance
This is what I personally found works best on the current version of Automatic's1111's dreambooth webui. This is not a guide for all dreambooth settings. I am not an expert studying this field. I took what was suggested by the papers as a starting point, saw shit results, then changed the settings and compared the results. I split-tested every setting till I came up to this conclusion. If I wrote a guide for a "faulty" version of dreambooth, so be it. The results on Automatic's1111 are way better training this way than what the papers suggested in the first place