Installing Stable Diffusion & Dreambooth For Windows

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4
At a glance
Powered by AI
The document outlines the process for installing Stable Diffusion, training a model using Dreambooth with your own images, and using the trained model with Stable Diffusion.

The document outlines installing the requirements like Python and Anaconda, then cloning the Stable Diffusion webui repository and downloading the model weights and GFPGAN files. It provides commands for running and closing the webui.

The document explains how to clone the Dreambooth repository, organize your images, edit the config files, and run the training command. It notes when training is complete.

--Resources--

Website & Videos:


Aitrepreneur SUPER Stable diffusion 2.0 Installation -
https://www.youtube.com/watch?v=vg8-NSbaWZI
Aitrepreneur DREAMBOOTH: Train Stable Diffusion With Your Images (cloud install) -
https://youtu.be/7m__xadX0z0

XavierXiao Dreambooth-Stable-Diffusion - https://github.com/XavierXiao/Dreambooth-


Stable-Diffusion
Gammagec Dreambooth-SD-optimized - https://github.com/gammagec/Dreambooth-SD-
optimized
JoePenna Dreambooth-Stable-Diffusion - https://github.com/JoePenna/Dreambooth-
Stable-Diffusion
(JoePenna's github no longer focuses on local running, but still a good resource.

Automatic1111 Stable-Diffusion-webui - https://github.com/AUTOMATIC1111/stable-


diffusion-webui
Automatic1111 Guide - https://stablediffusionguides.carrd.co/#one
Spinferno Dreambooth Guide -
https://www.reddit.com/r/StableDiffusion/comments/xpoexy/yet_another_dreambooth_pos
t_how_to_train_an_image/

Hugging Face - https://huggingface.co/


Birme Bulk Image Resizing - https://www.birme.net/?
target_width=512&target_height=512

Installers:
Python - https://www.python.org/downloads/windows/ (During Install "Add Python to
PATH")
Anaconda - https://www.anaconda.com/
Git - https://gitforwindows.org/

Downloads:
Stable Diffusion Model Weights 1.4 - https://huggingface.co/CompVis/stable-
diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt
GFPGAN Face Correction -
https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth

Regularization dataset examples: man_euler, man_unsplash, person_ddim, woman_ddim


(https://github.com/djbielejeski?tab=repositories)

-----------------------------------------------------------------------------------
-----------
Pre-Requirments:
1. Install Python.
During Install CHECK "Add Python to PATH".
2. Install Anaconda.
3. Install Git.
4. Restart PC.
5. Create a folder in your user directory, I named mine "AI" (C:\Users\natemac\
AI)
5b. You will need to update "natemac" to your user name for this guide.

-----------------------------------------------------------------------------------
-----------
Install Stable Diffusion webui:
(These same steps are also in "Aitrepreneur SUPER Stable diffusion 2.0
Installation" video and "Automatic1111 Guide")
1. Launch "Anaconda Prompt" from the Start Menu.
2. Go into your new folder [cd AI] (C:\Users\natemac\AI).
3. Clone Stable-Diffusion-webui [git clone
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git].
4. Download "Stable Diffusion Model Weights 1.4" (You will need a Hugging Face
account).
5. Rename the file from "sd-v1-4.ckpt" to "model.ckpt".
6. Move the "model.ckpt" file to the Stable Diffusion "Models" folder (C:\Users\
natemac\AI\stable-diffusion-webui\models).
7. Download the GFPGAN File.
8. Move the "GFPGANv1.3.pth" file to root Stable Diffusion webui folder (C:\
Users\natemac\AI\stable-diffusion-webui)
9. Stable Diffusion webui is installed.

-----------------------------------------------------------------------------------
-----------
Running Stable Diffusion webui:
1. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui"
folder (this will take longer the first time).
1b. This is complete once you see the line "To create a public link, set
`share=True` in `launch()`." in the Command Prompt.
2. Open a web browser and go-to: http://127.0.0.1:7860
3. Stable Diffusion is running.

-----------------------------------------------------------------------------------
-----------
Closing Stable Diffusion webui:
1. Close the web browser.
2. Close the Command Prompt that opened after running "webui-user.bat".

-----------------------------------------------------------------------------------
-----------
Install Dreambooth-SD-optimized:
(These steps are similar to "Aitrepreneur DREAMBOOTH" video)
1. Launch "Anaconda Prompt" from the Start Menu.
2. Go into your new folder [cd AI] (C:\Users\natemac\AI).
3. Clone Dreambooth-SD-optimized [git clone
https://github.com/gammagec/Dreambooth-SD-optimized.git].
3b. XavierXiao's version has the same steps, but a different folder name [git
clone https://github.com/XavierXiao/Dreambooth-Stable-Diffusion.git].

-----------------------------------------------------------------------------------
-----------
Install Dreambooth-SD-Optimized - Build Environment:
1. Open the "environment.yaml" file (in an editor such as notepad) in the
Dreambooth-SD-optimized folder (C:\Users\natemac\AI\Dreambooth-SD-optimized).
2. Edit the first line (name: ldm) to your choosing "name: SD-Optimized". Save &
close.
3. Launch "Anaconda Prompt" from the Start Menu.
4. Go into your Dreambooth-SD-optimized folder [cd C:\Users\natemac\AI\
Dreambooth-SD-optimized].
5. Build environment [conda env create -f environment.yaml]
5b. To activate environment use [conda activate SD-Optimized]
5c. To deactivate an active environment use [conda deactivate]

-----------------------------------------------------------------------------------
-----------
Install Dreambooth-SD-optimized - Copy Files:
1. Copy "model.ckpt" from (C:\Users\natemac\AI\stable-diffusion-webui\models) to
(C:\Users\natemac\AI\Dreambooth-SD-optimized)
2. Activate the environment by typing into the Anaconda Prompt [Conda activate
SD-Optimized]
3. Dreambooth-SD-optimized is now installed.

-----------------------------------------------------------------------------------
-----------
Pre-Training - Regularization Images:
1. Create folder structure in the "Dreambooth-SD-optimized" root-folder
(Dreambooth-SD-optimized/outputs/txt2img-samples/samples/) [md outputs\txt2img-
samples\samples]
2. Go-to this folder in the Anaconda Prompt [cd C:\Users\natemac\AI\Dreambooth-
SD-optimized\outputs\txt2img-samples\samples]
3. Choose one of the datasets (man_euler, man_unsplash, person_ddim, woman_ddim)
4. Replacing DATASET with your choice (https://github.com/djbielejeski/Stable-
Diffusion-Regularization-Images-DATASET.git)
5. Run your dataset clone [git clone https://github.com/djbielejeski/Stable-
Diffusion-Regularization-Images-woman_ddim.git]
6. Open your new DATASET folder(Stable-Diffusion-Regularization-Images-
woman_ddim).
7. Copy your DATASET folder (woman_ddim) to the (samples) folder.
8. Delete empty download folder (Stable-Diffusion-Regularization-Images-
woman_ddim).
9. You should now have 1500 images in the folder (C:\Users\natemac\AI\
Dreambooth-SD-optimized\outputs\txt2img-samples\samples\woman_ddim).

-----------------------------------------------------------------------------------
-----------
Pre-Training - Prepping Training Samples:
1. Collect your sample images you'd like to use. At least 10.
1b. ***THE COLLECTION ON IMAGE MUST BE AN EVEN AMOUNT.***
2. Crop images as needed to not have additional info such as another person if
you are training it on a single person.
3. Use (https://www.birme.net/?target_width=512&target_height=512) to Bulk crop
and size images. Download the zip.
4. Create a folder in the root (Dreambooth-SD-optimized) folder named
"training_samples".
5. Create a folder in the (training_samples) of your training set ("C:\Users\
natemac\AI\Dreambooth-SD-optimized\training-samples\rhaenyra").
6. Copy your finalized Cropped & Sized images into this folder.
7. Open the "personalized.py file (in an editor such as notepad) located in
("C:\Users\natemac\AI\Dreambooth-SD-optimized\ldm\data\personalized.py").
8. We will be editing and saving line 11 ('photo of a sks {}',) to your training
name ('rhaenyra {}',).

-----------------------------------------------------------------------------------
-----------
Training a Model with your Samples:
1. Launch "Anaconda Prompt" from the Start Menu.
2. Go into your Dreambooth-SD-optimized root folder [cd C:\Users\natemac\AI\
Dreambooth-SD-optimized].
3. Take note of your TRAINING-SAMPLES-NAME (rhaenyra) your REGULARIZATION-
IMAGES-NAME (woman_ddim) & CLASS (woman).
4. We will be editing the below code:
python main.py --base configs/stable-diffusion/v1-finetune_unfrozen.yaml -t --
actual_resume model.ckpt --reg_data_root outputs\txt2img-samples\samples\
REGULARIZATION-IMAGES-NAME -n TRAINING-SAMPLES-NAME --gpus 0, --data_root
training_samples\TRAINING-SAMPLES-NAME --batch_size 2020 --class_word CLASS

5. What it should look like:


python main.py --base configs/stable-diffusion/v1-finetune_unfrozen.yaml -t --
actual_resume model.ckpt --reg_data_root outputs\txt2img-samples\samples\woman_ddim
-n rhaenyra --gpus 0, --data_root training_samples\rhaenyra --batch_size 2020 --
class_word woman

6. Training is complete even if you see an error as long as somewhere you see the
line "Another one bites the dust..."

-----------------------------------------------------------------------------------
-----------
Pruning & Transfering Samples Model:
0. ***If you are running Dreambooth-SD-optimized, you will need to add
"prune_ckpt.py" from "XavierXiao Dreambooth-Stable-Diffusion" clone to the
"Dreambooth-SD-optimized" root folder.***
1. Find the name of the training data folder (C:\Users\natemac\AI\Dreambooth-SD-
optimized\logs\) "rhaenyra2022-09-28T11-46-55_rhaenyra".
2. Launch "Anaconda Prompt" from the Start Menu.
3. Go into your Dreambooth-SD-optimized root folder [cd C:\Users\natemac\AI\
Dreambooth-SD-optimized].
4. Run the following command with TRAINED-DATA-FOLDER replaced:
python "prune_ckpt.py" --ckpt "C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\
TRAINED-DATA-FOLDER\checkpoints\last.ckpt"

5. What it should look like:


python "prune_ckpt.py" --ckpt "C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\
rhaenyra2022-09-28T11-46-55_rhaenyra\checkpoints\last.ckpt"

6. There is now a roughly 2GB file named "last-pruned.ckpt" inside the


"checkpoints folder (C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\rhaenyra2022-
09-28T11-46-55_rhaenyra\checkpoints\). Transfer this file to your Stable Diffusions
Models folder (C:\Users\natemac\AI\stable-diffusion-webui\models).
7. Rename the "last-pruned.ckpt" file to your TRAINING-SAMPLES-NAME
"rhaenyra.ckpt".

-----------------------------------------------------------------------------------
-----------
Running Stable Diffusion webui with Trained data:
1. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui"
folder.
2. Open a web browser and go-to: http://127.0.0.1:7860
3. In the browser UI goto "Settings".
4. Under the section "Stable Diffusion" you will see a submenu of "Stable
Diffusion checkpoint". Choose your newly created Training Model "rhaenyra.ckpt".
5. At the top of the page, click "Apply Settings".
6. Close the web browser & Close the Command Prompt that opened after running
"webui-user.bat".
7. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui"
folder.
8. Open a web browser and go-to: http://127.0.0.1:7860

-----------------------------------------------------------------------------------
-----------
Using Your Trained Data for txt2img:
1. Using the TRAINING-SAMPLES-NAME & CLASS Prompts to create your image
"Portrait of rhaenyra woman".

You might also like