Advertisement
NateMac00

Installing Stable Diffusion & Dreambooth for Windows

Sep 28th, 2022 (edited)
26,515
2
Never
21
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 2 0
  1. --Resources--
  2. Website & Videos:
  3. Aitrepreneur SUPER Stable diffusion 2.0 Installation - https://www.youtube.com/watch?v=vg8-NSbaWZI
  4. Aitrepreneur DREAMBOOTH: Train Stable Diffusion With Your Images (cloud install) - https://youtu.be/7m__xadX0z0
  5.  
  6. XavierXiao Dreambooth-Stable-Diffusion - https://github.com/XavierXiao/Dreambooth-Stable-Diffusion
  7. Gammagec Dreambooth-SD-optimized - https://github.com/gammagec/Dreambooth-SD-optimized
  8. JoePenna Dreambooth-Stable-Diffusion - https://github.com/JoePenna/Dreambooth-Stable-Diffusion
  9. (JoePenna's github no longer focuses on local running, but still a good resource.
  10.  
  11. Automatic1111 Stable-Diffusion-webui - https://github.com/AUTOMATIC1111/stable-diffusion-webui
  12. Automatic1111 Guide - https://stablediffusionguides.carrd.co/#one
  13. Spinferno Dreambooth Guide - https://www.reddit.com/r/StableDiffusion/comments/xpoexy/yet_another_dreambooth_post_how_to_train_an_image/
  14.  
  15. Hugging Face - https://huggingface.co/
  16. Birme Bulk Image Resizing - https://www.birme.net/?target_width=512&target_height=512
  17.  
  18. Installers:
  19. Python - https://www.python.org/downloads/release/python-3109/ (During Install "Add Python to PATH")
  20. Anaconda - https://www.anaconda.com/
  21. Git - https://gitforwindows.org/
  22.  
  23. Downloads:
  24. Stable Diffusion Model Weights 1.4 - https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt
  25. GFPGAN Face Correction - https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth
  26.  
  27. Regularization dataset examples: man_euler, man_unsplash, person_ddim, woman_ddim (https://github.com/djbielejeski?tab=repositories)
  28.  
  29. ----------------------------------------------------------------------------------------------
  30. Pre-Requirments:
  31. 1. Install Python (3.10.x).
  32. During Install CHECK "Add Python to PATH".
  33. 2. Install Anaconda.
  34. 3. Install Git.
  35. 4. Restart PC.
  36. 5. Create a folder in your user directory, I named mine "AI" (C:\Users\natemac\AI)
  37. 5b. You will need to update "natemac" to your user name for this guide.
  38.  
  39. ----------------------------------------------------------------------------------------------
  40. Install Stable Diffusion webui:
  41. (These same steps are also in "Aitrepreneur SUPER Stable diffusion 2.0 Installation" video and "Automatic1111 Guide")
  42. 1. Launch "Anaconda Prompt" from the Start Menu.
  43. 2. Go into your new folder [cd AI] (C:\Users\natemac\AI).
  44. 3. Clone Stable-Diffusion-webui [git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git].
  45. 4. Download "Stable Diffusion Model Weights 1.4" (You will need a Hugging Face account).
  46. 5. Rename the file from "sd-v1-4.ckpt" to "model.ckpt".
  47. 6. Move the "model.ckpt" file to the Stable Diffusion "Models" folder (C:\Users\natemac\AI\stable-diffusion-webui\models).
  48. 7. Download the GFPGAN File.
  49. 8. Move the "GFPGANv1.3.pth" file to root Stable Diffusion webui folder (C:\Users\natemac\AI\stable-diffusion-webui)
  50. 9. Stable Diffusion webui is installed.
  51.  
  52. ----------------------------------------------------------------------------------------------
  53. Running Stable Diffusion webui:
  54. 1. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui" folder (this will take longer the first time).
  55. 1b. This is complete once you see the line "To create a public link, set `share=True` in `launch()`." in the Command Prompt.
  56. 2. Open a web browser and go-to: http://127.0.0.1:7860
  57. 3. Stable Diffusion is running.
  58.  
  59. ----------------------------------------------------------------------------------------------
  60. Closing Stable Diffusion webui:
  61. 1. Close the web browser.
  62. 2. Close the Command Prompt that opened after running "webui-user.bat".
  63.  
  64. ----------------------------------------------------------------------------------------------
  65. Install Dreambooth-SD-optimized:
  66. (These steps are similar to "Aitrepreneur DREAMBOOTH" video)
  67. 1. Launch "Anaconda Prompt" from the Start Menu.
  68. 2. Go into your new folder [cd AI] (C:\Users\natemac\AI).
  69. 3. Clone Dreambooth-SD-optimized [git clone https://github.com/gammagec/Dreambooth-SD-optimized.git].
  70. 3b. XavierXiao's version has the same steps, but a different folder name [git clone https://github.com/XavierXiao/Dreambooth-Stable-Diffusion.git].
  71.  
  72. ----------------------------------------------------------------------------------------------
  73. Install Dreambooth-SD-Optimized - Build Environment:
  74. 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).
  75. 2. Edit the first line (name: ldm) to your choosing "name: SD-Optimized". Save & close.
  76. 3. Launch "Anaconda Prompt" from the Start Menu.
  77. 4. Go into your Dreambooth-SD-optimized folder [cd C:\Users\natemac\AI\Dreambooth-SD-optimized].
  78. 5. Build environment [conda env create -f environment.yaml]
  79. 5b. To activate environment use [conda activate SD-Optimized]
  80. 5c. To deactivate an active environment use [conda deactivate]
  81.  
  82. ----------------------------------------------------------------------------------------------
  83. Install Dreambooth-SD-optimized - Copy Files:
  84. 1. Copy "model.ckpt" from (C:\Users\natemac\AI\stable-diffusion-webui\models) to (C:\Users\natemac\AI\Dreambooth-SD-optimized)
  85. 2. Activate the environment by typing into the Anaconda Prompt [Conda activate SD-Optimized]
  86. 3. Dreambooth-SD-optimized is now installed.
  87.  
  88. ----------------------------------------------------------------------------------------------
  89. Pre-Training - Regularization Images:
  90. 1. Create folder structure in the "Dreambooth-SD-optimized" root-folder (Dreambooth-SD-optimized/outputs/txt2img-samples/samples/) [md outputs\txt2img-samples\samples]
  91. 2. Go-to this folder in the Anaconda Prompt [cd C:\Users\natemac\AI\Dreambooth-SD-optimized\outputs\txt2img-samples\samples]
  92. 3. Choose one of the datasets (man_euler, man_unsplash, person_ddim, woman_ddim)
  93. 4. Replacing DATASET with your choice (https://github.com/djbielejeski/Stable-Diffusion-Regularization-Images-DATASET.git)
  94. 5. Run your dataset clone [git clone https://github.com/djbielejeski/Stable-Diffusion-Regularization-Images-woman_ddim.git]
  95. 6. Open your new DATASET folder(Stable-Diffusion-Regularization-Images-woman_ddim).
  96. 7. Copy your DATASET folder (woman_ddim) to the (samples) folder.
  97. 8. Delete empty download folder (Stable-Diffusion-Regularization-Images-woman_ddim).
  98. 9. You should now have 1500 images in the folder (C:\Users\natemac\AI\Dreambooth-SD-optimized\outputs\txt2img-samples\samples\woman_ddim).
  99.  
  100. ----------------------------------------------------------------------------------------------
  101. Pre-Training - Prepping Training Samples:
  102. 1. Collect your sample images you'd like to use. At least 10.
  103. 1b. ***THE COLLECTION ON IMAGE MUST BE AN EVEN AMOUNT.***
  104. 2. Crop images as needed to not have additional info such as another person if you are training it on a single person.
  105. 3. Use (https://www.birme.net/?target_width=512&target_height=512) to Bulk crop and size images. Download the zip.
  106. 4. Create a folder in the root (Dreambooth-SD-optimized) folder named "training_samples".
  107. 5. Create a folder in the (training_samples) of your training set ("C:\Users\natemac\AI\Dreambooth-SD-optimized\training-samples\rhaenyra").
  108. 6. Copy your finalized Cropped & Sized images into this folder.
  109. 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").
  110. 8. We will be editing and saving line 11 ('photo of a sks {}',) to your training name ('rhaenyra {}',).
  111.  
  112. ----------------------------------------------------------------------------------------------
  113. Training a Model with your Samples:
  114. 1. Launch "Anaconda Prompt" from the Start Menu.
  115. 2. Go into your Dreambooth-SD-optimized root folder [cd C:\Users\natemac\AI\Dreambooth-SD-optimized].
  116. 3. Take note of your TRAINING-SAMPLES-NAME (rhaenyra) your REGULARIZATION-IMAGES-NAME (woman_ddim) & CLASS (woman).
  117. 4. We will be editing the below code:
  118. 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
  119.  
  120. 5. What it should look like:
  121. 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
  122.  
  123. 6. Training is complete even if you see an error as long as somewhere you see the line "Another one bites the dust..."
  124.  
  125. ----------------------------------------------------------------------------------------------
  126. Pruning & Transfering Samples Model:
  127. 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.***
  128. 1. Find the name of the training data folder (C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\) "rhaenyra2022-09-28T11-46-55_rhaenyra".
  129. 2. Launch "Anaconda Prompt" from the Start Menu.
  130. 3. Go into your Dreambooth-SD-optimized root folder [cd C:\Users\natemac\AI\Dreambooth-SD-optimized].
  131. 4. Run the following command with TRAINED-DATA-FOLDER replaced:
  132. python "prune_ckpt.py" --ckpt "C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\TRAINED-DATA-FOLDER\checkpoints\last.ckpt"
  133.  
  134. 5. What it should look like:
  135. python "prune_ckpt.py" --ckpt "C:\Users\natemac\AI\Dreambooth-SD-optimized\logs\rhaenyra2022-09-28T11-46-55_rhaenyra\checkpoints\last.ckpt"
  136.  
  137. 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).
  138. 7. Rename the "last-pruned.ckpt" file to your TRAINING-SAMPLES-NAME "rhaenyra.ckpt".
  139.  
  140. ----------------------------------------------------------------------------------------------
  141. Running Stable Diffusion webui with Trained data:
  142. 1. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui" folder.
  143. 2. Open a web browser and go-to: http://127.0.0.1:7860
  144. 3. In the browser UI goto "Settings".
  145. 4. Under the section "Stable Diffusion" you will see a submenu of "Stable Diffusion checkpoint". Choose your newly created Training Model "rhaenyra.ckpt".
  146. 5. At the top of the page, click "Apply Settings".
  147. 6. Close the web browser & Close the Command Prompt that opened after running "webui-user.bat".
  148. 7. Run/Double-click on the "webui-user.bat" inside the "stable-diffusion-webui" folder.
  149. 8. Open a web browser and go-to: http://127.0.0.1:7860
  150.  
  151. ----------------------------------------------------------------------------------------------
  152. Using Your Trained Data for txt2img:
  153. 1. Using the TRAINING-SAMPLES-NAME & CLASS Prompts to create your image "Portrait of rhaenyra woman".
Advertisement
Comments
  • sithclone
    1 year
    # text 0.20 KB | 0 0
    1. I'm having trouble at line 124. (I installed the optimized version of Dreambooth). I do not find the ''logs'' folder in my root folder. When should the ''logs'' file appear? I might of misssed a step.
  • Highjack77
    1 year
    # text 0.10 KB | 0 0
    1. My trouble is at line 118 the execution gave me an error "NameError: name 'trainer' is not defined"
    • ntmatter
      1 year
      # text 0.17 KB | 0 0
      1. I got this error when using a model.ckpt file other than the default. I tried to rename the diffusions model and got this error, went back to the original and it worked.
  • b1l
    b1l
    1 year
    # text 0.14 KB | 0 0
    1. hello! i cant find prune_ckpt.py" from "XavierXiao Dreambooth-Stable-Diffusion" on github! do you know what i am doing wrong? thanks for the data
  • # text 0.13 KB | 0 0
    1. You change the number of steps in the file: configs/stable-diffusion/v1-finetune_unfrozen.yaml
    2.  
    3. took me a while to figure that out
  • Afrox
    1 year
    # text 0.27 KB | 0 0
    1. I am currently stuck on line 117 of the guide
    2. "4. We will be editing the below code: ..."
    3.  
    4. Where do you go to edit the code?
    5.  
    6. -also-
    7. Went to Anaconda Prompt Dreambooth-SD-optimized root folder, but not sure how to run training. Any help would be greatly appreciated!
  • bestjammer
    1 year
    Comment was deleted
  • bestjammer
    1 year
    # text 0.68 KB | 0 0
    1. Epoch 0: 15%|▏| 500/3232 [10:04<55:04, 1.21s/it, loss=0.311, v_num=0, train/loss_simple_step=0.0769, train/loss_vlb_sC:\Users\Ben\miniconda3\envs\SD-Optimized\lib\site-packages\pytorch_lightning\callbacks\model_checkpoint.py:644: UserWarning: ModelCheckpoint(monitor='val/loss_simple_ema') not found in the returned metrics: ['train/loss_simple', 'train/loss_simple_step', 'train/loss_vlb', 'train/loss_vlb_step', 'train/loss', 'train/loss_step', 'global_step']. HINT: Did you call self.log('val/loss_simple_ema', value) in the LightningModule?
    2. warning_cache.warn(m)
    3. Epoch 0, global step 499: val/loss_simple_ema was not in top 1
    4.  
    5. I get to 15% then this happens... python then crashes.
  • Artfackt
    1 year
    Comment was deleted
  • EdBear
    1 year
    # text 0.47 KB | 0 0
    1. I followed these steps for both Dreambooth-SD-Optimized and for the XavierXiao version. Followed the guide for both, created separate installs for them. Same error both times, just when it's about to start training.
    2.  
    3. >Traceback (most recent call last):
    4. > File "main.py", line 787, in <module>
    5. > ngpu = len(lightning_config.trainer.gpus.strip(",").split(','))
    6. >AttributeError: 'int' object has no attribute 'strip'
    7.  
    8. Not sure what to do! Any suggestions would be appreciated.
    • TheCharmingBard
      1 year (edited)
      # text 0.08 KB | 0 0
      1. I got this exact same error and had no issues up to this point. How do I fix this?
      • # text 0.35 KB | 0 0
        1. I have found the answer some machines require --gpus "0," see the corrected script below:
        2.  
        3. 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
        4.  
        5.  
  • # text 0.10 KB | 0 0
    1. Can anyone get this version to work locally? https://github.com/kanewallmann/Dreambooth-Stable-Diffusion
  • jdm5680
    1 year
    # text 1.50 KB | 0 0
    1. I'm striking out on lines 54/55 - installing torch and torchvision. I've manually gone to the link and I see a bunch of files that look like they meet the needs as they have 1.12.1+cu113 listed in the file name. Any ideas on how to fix this? Below is what shows when I run the webui-user.bat file.
    2.  
    3. venv "C:\Users\jdm56\AI\stable-diffusion-webui\venv\Scripts\Python.exe"
    4. Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
    5. Commit hash: 685f9631b56ff8bd43bce24ff5ce0f9a0e9af490
    6. Installing torch and torchvision
    7. Traceback (most recent call last):
    8. File "C:\Users\jdm56\AI\stable-diffusion-webui\launch.py", line 294, in <module>
    9. prepare_environment()
    10. File "C:\Users\jdm56\AI\stable-diffusion-webui\launch.py", line 206, in prepare_environment
    11. run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch")
    12. File "C:\Users\jdm56\AI\stable-diffusion-webui\launch.py", line 49, in run
    13. raise RuntimeError(message)
    14. RuntimeError: Couldn't install torch.
    15. Command: "C:\Users\jdm56\AI\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
    16. Error code: 1
    17. stdout: Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu113
    18.  
    19. stderr: ERROR: Could not find a version that satisfies the requirement torch==1.12.1+cu113 (from versions: none)
    20. ERROR: No matching distribution found for torch==1.12.1+cu113
    21.  
  • andresbg83
    321 days
    # text 0.56 KB | 0 0
    1. Hi! I think this error is due to some crash with GPU, not sure if it is possible to configurate this to be able to continue the training? I'm using a NVIDIA GeForce RTX 3090
    2.  
    3. return Variable._execution_engine.run_backward(
    4. RuntimeError: CUDA out of memory. Tried to allocate 512.00 MiB (GPU 0; 24.00 GiB total capacity; 20.72 GiB already allocated; 0 bytes free; 21.06 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
Add Comment
Please, Sign In to add comment
Advertisement