You are currently viewing How do I use Stable Diffusion on my PC

How do I use Stable Diffusion on my PC

Want to use Stable Diffusion on your own computer? This is the step by step guide you need to get started in minutes.

In this article, we’ll walk you through the steps for setting up and using Stable Diffusion to create your own custom images. Whether you’re an artist looking for new inspiration or a developer looking to add visual elements to your project, Stable Diffusion has you covered.

Important: If you want to use Stable Diffusion on your local PC, you MUST have a GPU with at least 6GB of VRAM.

Note, although the following may look quite complex, it's pretty easy really. Just follow each step and you'll soon be running Stable Diffusion on your own machine! However, if you want an easier way to run Stable Diffusion, check out this article which outlines the best Web Apps you let you use Stable Diffusion without having to do any install.

Step 1: Download and Set Up Stable Diffusion

  1. Create a Huggingface account by going to this link and clicking “Sign Up” in the top bar.
  2. Once you’ve created an account, go to this link.
  3. Click on the “Files and versions” tab and download the sd-v1-4.ckpt file. This file is more than 4GB, so you may want to grab a coffee or do something else while you wait for it to download.
  4. Once the download is complete, unzip the file and navigate to stable-diffusion-main/models/ldm.
  5. Create a new folder called “stable-diffusion-v1” in this directory.
  6. Rename the sd-v1-4.ckpt file to “model.ckpt” and move it into the “stable-diffusion-v1” folder you just created.
  7. Open the file environment.yaml in a text editor and add “- git” after the line that says “dependencies:”. Make sure the “-” is aligned with the ones in the following lines.
  8. Go here and download Miniconda 3 for Windows.
  9. Install Miniconda for all users, but make sure to uncheck the option to “Register Miniconda as the system Python 3.9”.

Step 2: How to use Stable Diffusion to generate custom images

  1. Open the Anaconda Prompt (Miniconda 3).
  2. Type “cd” followed by a space and then drag the “stable-diffusion-main” folder into the Anaconda Prompt console. This will change the current directory to the stable-diffusion-main folder.
  3. Run the following command to create a new environment:
Copy codeconda env create -f environment.yaml
  1. Activate the environment by running the following command:
Copy codeconda activate ldm
  1. To generate an image, run the following command:
Copy codepython scripts/txt2img.py --prompt "Elon Musk as an alien" --H 512 --W 512 --seed 27 --n_iter 2 --ddim_steps 50

Replace the “Elon Musk as an alien” prompt with the text or image you want to create.

Step 3: Adjust Image Settings (Optional)

You can customize the appearance of your images by adjusting the following settings:

  • --H: The height of the image in pixels. The default value is 512.
  • --W: The width of the image in pixels. The default value is 512.
  • --seed: The random seed used to generate the image. The default value is 27.
  • --n_iter: The number of iterations to use when generating the image. The default value is 2.
  • --ddim_steps: The number of steps to use when generating the image. The default value is 50.

For example, to generate an image with a height of 1024 pixels, a width of 1024 pixels, and a random seed of 42, you would run the following command:

Copy codepython scripts/txt2img.py --prompt "Elon Musk as an alien" --H 1024 --W 1024 --seed 42 --n_iter 2 --ddim_steps 50

Troubleshooting

If you encounter an out-of-memory error while generating an image, try running the following command instead:

Copy codepython optimizedSD/optimized_txt2img.py --prompt "Elon Musk as an alien" --H 512 --W 512 --seed 27 --n_iter 1 --ddim_steps 50

This will use a more memory-efficient method for generating the image.

Enjoy Your Custom Image!

That’s it! With a little effort and some imagination, you can now turn your ideas into art using Stable Diffusion. Have fun creating your own custom images!