Full Workflow For Newbie Stable Diffusion Trainers For SD 1.5 Models & SDXL Models Training With DreamBooth & LoRA
Tags: beginners, tutorial, python, ai
Published: 2024-02-19 14:02:15

<p>If you are new to Stable Diffusion and want to learn easily to train it with very best possible results, this article is prepared for this purpose with everything you need.</p>

<p><strong>Most up to date original Source of this article (Public Post) :&nbsp;</strong><a href="https://www.patreon.com/posts/full-workflow-sd-98620163" rel="noopener ugc nofollow" target="_blank"><strong>https://www.patreon.com/posts/full-workflow-sd-98620163</strong></a></p>

<p><a href="https://github.com/FurkanGozukara/Stable-Diffusion/blob/main/Patreon-Posts-Index.md" rel="noopener ugc nofollow" target="_blank">Patreon exclusive posts index</a></p>

<ul>
	<li>I have developed better workflows recently than that I did with Automatic1111 DreamBooth extension. Much better than that old one. Moreover, Automatic1111 DreamBooth extension is not anymore maintained so do not use it.</li>
	<li>I did 120+ trainings for SDXL to find the very best workflow and settings.</li>
	<li>I did over 70+ trainings for SD 1.5 based models to find very best workflow and settings.</li>
	<li>If you have further questions please leave a comment and hopefully I will keep updating this article.</li>
	<li>If you are overwhelmed with all the info, I am giving 1 to 1 private lectures as well</li>
	<li>Message me from Discord</li>
</ul>

<h1>Requirements</h1>

<ul>
	<li>You need to have Python 3.10.11 installed. I suggest you to install as shown in below video:</li>
	<li><a href="https://youtu.be/-NjNy7afOQ0" rel="noopener ugc nofollow" target="_blank">https://youtu.be/-NjNy7afOQ0</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>Also install ffmpeg, C++ tools &amp; Git.</li>
	<li>Don&rsquo;t forget to install the&nbsp;<a href="https://aka.ms/vs/17/release/vc_redist.x64.exe" rel="noopener ugc nofollow" target="_blank">Visual Studio 2015, 2017, 2019, and 2022 redistributable</a>&nbsp;as well.</li>
	<li>Install Python directly into your C drive like shown in above video.</li>
</ul>

<h1>How To Install &amp; Use Kohya SS GUI On Windows &amp; RunPod &amp; Kaggle</h1>

<ul>
	<li>The big video I explained how to install and use Kohya GUI on Windows is in below video:</li>
	<li><a href="https://youtu.be/sBFGitIvD2A" rel="noopener ugc nofollow" target="_blank">https://youtu.be/sBFGitIvD2A</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>The big video I explained how to install Kohya GUI on RunPod is below:</li>
	<li><a href="https://youtu.be/-xEwaQ54DI4" rel="noopener ugc nofollow" target="_blank">https://youtu.be/-xEwaQ54DI4</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>These 2 above videos shows how to train LoRA but everything same with DreamBooth. Just use DreamBooth tab and our shared best configs.</li>
	<li>Our RunPod Kohya GUI SS installer script:&nbsp;<a href="https://www.patreon.com/posts/84898806" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/84898806</a></li>
	<li>A quick video where I explained how to quickly use our Kohya GUI configs is below:</li>
	<li><a href="https://youtu.be/EEV8RPohsbw" rel="noopener ugc nofollow" target="_blank">https://youtu.be/EEV8RPohsbw</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>If you can&rsquo;t afford RunPod and don&rsquo;t have a decent GPU, we have a Free Kaggle account notebook that supports Kohya SS GUI and it is shown in below video:</li>
	<li><a href="https://youtu.be/16-b1AjvyBE" rel="noopener ugc nofollow" target="_blank">https://youtu.be/16-b1AjvyBE</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>Kaggle Kohya Script notebook link :&nbsp;<a href="https://www.patreon.com/posts/kohya-sdxl-lora-88397937" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/kohya-sdxl-lora-88397937</a></li>
	<li>This notebook has a cell that downloads best SDXL and SD 1.5 configs for Kaggle.</li>
	<li>On Kaggle, I suggest you to train SD 1.5 model. It is better since on Kaggle we can&rsquo;t use BF16 for SDXL training due to GPU model limitation. Kaggle GPUs are old. Also we can&rsquo;t train with full precision Float (FP32) due to VRAM limitation.</li>
	<li>However on Kaggle we can train SD 1.5 with full precision Float (FP32) therefore can obtain amazing results.</li>
	<li>Also on this Kaggle video (below link) I have explained my recent 200 repeat and saving every N steps checkpoints strategy which is better:</li>
	<li><a href="https://youtu.be/16-b1AjvyBE" rel="noopener ugc nofollow" target="_blank">https://youtu.be/16-b1AjvyBE</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>For example if you have 16 training images, 200 repeat and 1 epoch with reg images means 16x200x1x2 = 6400 steps. The last 2 comes from reg images. So if you want to save 10 checkpoints and compare, save every 641 steps. This will give you 10 checkpoints.</li>
	<li>After training completed, do x/y/z checkpoint comparison and decide the best model.</li>
	<li>x/y/z checkpoint comparison is shown in below video:</li>
	<li><a href="https://youtu.be/sBFGitIvD2A" rel="noopener ugc nofollow" target="_blank">https://youtu.be/sBFGitIvD2A</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>Why 200 repeat and 1 epoch better? Because with 200 repeating, we are able to utilize more ground truth absolute quality regularization / classification images.</li>
</ul>

<h1>Ground Truth Very Best Regularization / Classification Images</h1>

<ul>
	<li>You can see our both Man and Woman reg / class images datasets here with all resolutions you may need (all pre-prepared &mdash; takes days) :&nbsp;<a href="https://www.patreon.com/posts/massive-4k-woman-87700469" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/massive-4k-woman-87700469</a></li>
	<li>These regularization / classification images are manually collected by me and prepared by me from Unsplash and sorted with best quality. The preparatın took over few weeks in total. There are 5200 images for each class Man and Woman.</li>
</ul>

<h1>After Detailer Extension</h1>

<ul>
	<li>To improve faces significantly, I use After Detailer (ADetailer) extension. This extension automatically masks the face and inpaint it with the settings you provide. This will improve face significantly. Of course, the results depends on your initial training quality and the quality and resemble and quality of the initially generated image.</li>
	<li>In below video how to use ADetailer extension is explained:</li>
	<li><a href="https://youtu.be/16-b1AjvyBE" rel="noopener ugc nofollow" target="_blank">https://youtu.be/16-b1AjvyBE</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>Always you can look video chapters : 32:07 How to install after detailer (adetailer) extension to improve faces automatically</li>
	<li>After installing ADetailer extension from extensions menu, please restart the Automatic1111 for it to fully and properly install</li>
	<li>Specific settings for SD 1.5 and SDXL shown below in their sections</li>
</ul>

<h1>How To Crop And Resize Your Training Images</h1>

<ul>
	<li>You can use our state of the art auto crop and resize scripts. They are shared here :&nbsp;<a href="https://www.patreon.com/posts/sota-subject-and-88391247" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/sota-subject-and-88391247</a></li>
	<li>You can watch crop and resize scripts video in below link:</li>
	<li><a href="https://youtu.be/Fbuyu35TkE4?si=Sa1Hq7DMJtF2ZhX5" rel="noopener ugc nofollow" target="_blank">https://youtu.be/Fbuyu35TkE4?si=Sa1Hq7DMJtF2ZhX5</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>The first cropping script will zoom in the person in the image with as much as trying to match the target aspect ratio without cropping any part of the human subject. It supports may other classes as well such as : &lsquo;person&rsquo;, &lsquo;bicycle&rsquo;, &lsquo;car&rsquo;,&hellip; Please check the patreon post for full classes.</li>
	<li>Then with resize script, we focus on the face on the image and resize into exact target resolution. This crops the person body parts if necessary with focusing face.</li>
</ul>

<h1>Which Captions / Tokens To Use For Training</h1>

<ul>
	<li>For training captions / tagging, if it is a person i just use&nbsp;<em>ohwx man</em>&nbsp;as training token and&nbsp;<em>man</em>&nbsp;as reg images token. You can define them either via folder name or with image_file_name.txt files. If you are training a woman use&nbsp;<em>woman&nbsp;</em>or whatever you are training use that class token. Like&nbsp;<em>ohwx car</em>.</li>
	<li>If you want to train a style or other stuff, try&nbsp;<em>ohwx + class + captioning</em>&nbsp;and compare it with just&nbsp;<em>ohwx class</em>.</li>
	<li>If you want to learn what is ohwx and why we use such rare token watch below video:</li>
	<li><a href="https://youtu.be/Bdl-jWR3Ukc" rel="noopener ugc nofollow" target="_blank">https://youtu.be/Bdl-jWR3Ukc</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>This above is old but it is gem to learn rare tokens and class tokens</li>
	<li>You can use our SOTA captioning models for captioning which includes batch captioning for the following models: Clip Interrogator (115 Clip Vision Models), LLaVA (the strongest one), CogVLM, Qwen-VL, Blip2 &amp; Kosmos-2 (even works with 2 GB VRAM GPU best one for weak GPUs).</li>
	<li>You can download 1 click installers and batch captioning supporting amazing Gradio web apps having scripts from here :&nbsp;<a href="https://www.patreon.com/posts/sota-image-for-2-90744385" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/sota-image-for-2-90744385</a></li>
	<li>Each script has instructions and installers for Windows &amp; RunPod. Hopefully I will add Free Kaggle notebooks as well.</li>
	<li>If you are local linux user, just change the paths of RunPod scripts and use them on your local machine.</li>
	<li>Each script has default very best image captioning prompts set in the GUI apps.</li>
	<li>Once you generated captions with our SOTA captioning tools, you can use Kohya GUI&rsquo;s amazing caption manipulation screen as shown below.</li>
	<li>You can download the full resolution of below image :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17726831" rel="noopener ugc nofollow" target="_blank">Kohya Image Caption.png</a></li>
</ul>

<p><img alt="" src="https://miro.medium.com/v2/resize:fit:875/0*XsQ1OmdMUMLOM7yn" style="height:286px; width:700px" /></p>

<h1>How To Make Kohya GUI To Use Captions Instead Of Folder Names</h1>

<ul>
	<li>Once the Caption Extension is set and enabled, it will read the captions from the folder and ignore the folder names.</li>
	<li>The repeating count number will be still valid.</li>
	<li>You can download below image full size from :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17726850" rel="noopener ugc nofollow" target="_blank">Kohya Enable Image Caption.png</a></li>
</ul>

<p><img alt="" src="https://miro.medium.com/v2/resize:fit:875/0*zsZdIbNwdSATcR4n" style="height:207px; width:700px" /></p>

<h1>SD 1.5 Based Models Configuration</h1>

<ul>
	<li>Download best configuration from here :&nbsp;<a href="https://www.patreon.com/posts/very-best-kohya-97379147" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/very-best-kohya-97379147</a></li>
	<li>For SD 1.5 I used 768x768 training, no bucketing (I crop training images into 768x768 aspect ratio and resize them to 768x768) and generate images in 1024x1024.</li>
	<li>Use same resolution of training images resolution for regularization / classification images resolution.</li>
	<li>Once you become a more experienced, you can enable bucketing and do bucketing enabled different aspect ratio and resolution including trainings</li>
	<li>I use After Detailer (ADetailer) with the following configs for SD 1.5</li>
	<li>Everything default except below:</li>
	<li>Prompt :&nbsp;<em>photo of ohwx man</em>&nbsp;if realism is targeted</li>
	<li>If you are targeting stylization such as 3D you need to try with full prompt or like&nbsp;<em>3D image of ohwx man</em></li>
	<li>Set ADetailer inpainting resolution to 768x768 : Remember we are generating images in 1024x1024 but when inpainting face, it is best to inpaint with native resolution we trained.</li>
	<li>The denoise strength I set is 0.5 and I also set separate number of steps for better quality like 70</li>
	<li>Here ADetailer settings for SD 1.5 download image to see :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17726889" rel="noopener ugc nofollow" target="_blank">SD 1.5 ADetailer Settings.png</a></li>
	<li>I compared 1024x1024 training vs 768x768 training for SD 1.5 and 768x768 performed better even though we generate images in 1024x1024.</li>
	<li>Also not all SD 1.5 models will support 1024x1024 resolution. To find which model is best, I compared 161 SD 1.5 models. You can watch its video below:</li>
	<li><a href="https://youtu.be/G-oZn4H-aHQ" rel="noopener ugc nofollow" target="_blank">https://youtu.be/G-oZn4H-aHQ</a></li>
</ul>

<p>&nbsp;</p>

<ul>
	<li>The Kohya SS GUI config for SD 1.5 automatically uses the best SD 1.5 realism model that supports 1024x1024 image generation and automatically downloads it into your PC.</li>
</ul>

<h1>SD 1.5 Based Models Results &amp; Prompts</h1>

<ul>
	<li>20 Images :&nbsp;<a href="https://civitai.com/posts/1300478" rel="noopener ugc nofollow" target="_blank">https://civitai.com/posts/1300478</a></li>
	<li>20 Images :&nbsp;<a href="https://civitai.com/posts/1300774" rel="noopener ugc nofollow" target="_blank">https://civitai.com/posts/1300774</a></li>
	<li>20 Images :&nbsp;<a href="https://civitai.com/posts/1300759" rel="noopener ugc nofollow" target="_blank">https://civitai.com/posts/1300759</a></li>
</ul>

<h1>What If You Want LoRA For SD 1.5 Based Models?</h1>

<ul>
	<li>LoRA is optimized version of DreamBooth training. Therefore, no matter what configuration you use, it will be inferior to the DreamBooth training. Moreover, LoRA has infinite number of configuration combination. Therefore, I don&rsquo;t research LoRA.</li>
	<li>Also as mentioned in this paper,&nbsp;<a href="https://arxiv.org/abs/2402.09353," rel="noopener ugc nofollow" target="_blank">https://arxiv.org/abs/2402.09353,</a>&nbsp;LoRA lacks a significant feature :&nbsp;<em>They found that LoRA either increases or decreases magnitude and direction updates proportionally but seems to lack the capability of making only subtle directional changes as found in full fine-tuning.&nbsp;</em>Therefore do full DreamBooth / Fine Tuning and extract LoRA is best.</li>
	<li>So what you can do If you need LoRA?</li>
	<li>It is so easy. We use Kohya SS GUI LoRA extraction tool. Recently I contacted Kohya for this and he even Improved its logic. Now even low VRAM GPUs can extract LoRA very well.</li>
	<li>Open your latest version Kohya SS GUI and extract as shown in below image</li>
	<li>The best model that our config auto trains on is Hyper Realism V3 which you can download safetensors file here :&nbsp;<a href="https://civitai.com/models/158959/hyper-realism" rel="noopener ugc nofollow" target="_blank">https://civitai.com/models/158959/hyper-realism</a></li>
	<li>You need to set your base model whatever you trained on. If you used our default config, you need to download that safetensors file and use it as base.</li>
	<li>You can download full resolution of below image :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17726686" rel="noopener ugc nofollow" target="_blank">SD 1.5 LoRA Extract.png</a></li>
</ul>

<p><img alt="" src="https://miro.medium.com/v2/resize:fit:875/0*L2GEizr7GB4a2lK6" style="height:458px; width:700px" /></p>

<h1>SDXL Based Models Configuration</h1>

<ul>
	<li>Download best configuration from here :&nbsp;<a href="https://www.patreon.com/posts/89213064" rel="noopener ugc nofollow" target="_blank">https://www.patreon.com/posts/89213064</a></li>
	<li>For SDXL I used 1024x1024 training, no bucketing (I crop training images into 1024x1024 aspect ratio and resize them to 1024x1024) and generate images in 1024x1024.</li>
	<li>Use same resolution of training images resolution for regularization / classification images resolution.</li>
	<li>Once you become a more experienced, you can enable bucketing and do bucketing enabled different aspect ratio and resolution including trainings</li>
	<li>I use After Detailer (ADetailer) with the following configs for SDXL</li>
	<li>Everything default except below:</li>
	<li>Prompt :&nbsp;<em>photo of ohwx man</em>&nbsp;if realism is targeted</li>
	<li>If you are targeting stylization such as 3D you need to try with full prompt or like&nbsp;<em>3D image of ohwx man</em></li>
	<li>The denoise strength I set is 0.5 and I also set separate number of steps for better quality like 70</li>
	<li>Here ADetailer settings for SDXL download image to see :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17726922" rel="noopener ugc nofollow" target="_blank">SDXL ADetailer Settings.png</a></li>
	<li>For realism I still find SDXL 1.0 is best but you can try other models and compare results</li>
	<li>Some custom models may require longer training or higher learning rate</li>
</ul>

<h1>SDXL Based Models Results &amp; Prompts</h1>

<ul>
	<li>20 Images :&nbsp;<a href="https://civitai.com/posts/1238778" rel="noopener ugc nofollow" target="_blank">https://civitai.com/posts/1238778</a></li>
	<li>20 Images :&nbsp;<a href="https://civitai.com/posts/1238769" rel="noopener ugc nofollow" target="_blank">https://civitai.com/posts/1238769</a></li>
</ul>

<h1>What If You Want LoRA For SDXL Based Models?</h1>

<ul>
	<li>LoRA is optimized version of DreamBooth training. Therefore, no matter what configuration you use, it will be inferior to the DreamBooth training. Moreover, LoRA has infinite number of configuration combination. Therefore, I don&rsquo;t research LoRA.</li>
	<li>So what you can do If you need LoRA?</li>
	<li>It is so easy. We use Kohya SS GUI LoRA extraction tool. Recently I contacted Kohya for this and he even Improved its logic. Now even low VRAM GPUs can extract LoRA very well.</li>
	<li>Open your latest version Kohya SS GUI and extract as shown in below image</li>
	<li>You need to set your base model whatever you trained on.</li>
	<li>Using LoRA on custom stylized models yields good stylized images</li>
	<li>You can download full resolution of below image :&nbsp;<a href="https://www.patreon.com/file?h=98620163&amp;i=17727019" rel="noopener ugc nofollow" target="_blank">SDXL LoRA Extract.png</a></li>
</ul>

<p><img alt="" src="https://miro.medium.com/v2/resize:fit:875/0*TtWuLxoRfRqCd_aH" style="height:393px; width:700px" /></p>

<p><img alt="" src="https://miro.medium.com/v2/resize:fit:875/1*1HA-WpDBpjy9m7dW6Qo5pg.png" style="height:350px; width:700px" /></p>