How to run Stable Diffusion on your PC to create AI images

The art of artificial intelligence (AI) is currently prevalent, but most of the AI ​​image generators work in the cloud. Stable Diffusion is different – you can run it on your computer and create as many images as you want. Here’s how to install and use Stable Diffusion on Windows.

What is stable diffusion?

Stable Diffusion is an open source machine learning model that can create images from text, modify images based on text, or fill in the details of low-resolution or low-detail images. It has been trained on billions of images and can produce results similar to those you get from DALL-E 2 and MidJourney. Developed by Stability AI and first released on August 22, 2022.

Stable Diffusion doesn’t have a neat user interface (yet) like some AI image generators, but it does have a very permissive license, and best of all – it’s completely free to use on your PC (or Mac).

Don’t be intimidated by the fact that Stable Diffusion currently runs in the CLI. Getting it up and running is very simple. If you can double-click an executable and type in a box, you can have it up and running in a few minutes.

What do you need to run Stable Diffusion on your PC?

Stable Diffusion won’t run on your phone or on most laptops, but it will work on average gaming PCs in 2022. Here are the requirements:

How to install and run Stable Diffusion on Windows

There are two types of software you need: Git and Miniconda3.

NB: Git and Miniconda3 are both secure programs produced by reputable organizations. You don’t have to worry about malware with them provided that you download them from the official sources linked to this article.

Install Git

Git is a tool that allows developers to manage different versions of the software they develop. They can keep multiple versions of the software they are working on in a central repository at the same time and allow other developers to contribute to the project.

Related: What is GitHub, and why is it used?

If you are not a developer, Git provides a convenient way to access and download these projects, and this is the method we will use in this case. Download the Windows x64 installer from the Git site, then run it.

There are several options that you will be prompted to select while the installer is running – leave them at their defaults. The one option page, “Set path environment” is particularly important. It should be set to “Git From The Command Line as well as from third-party programs.”

make sure that

Miniconda3 installation

Stable Diffusion is based on a few different Python libraries. If you don’t know much about Python, don’t worry about it – suffice it to say that libraries are just software packages that your computer can use to perform specific functions, such as converting an image or performing complex calculations.

Related: What is the Python language?

Miniconda3 is basically a convenient tool. It allows you to download, install and manage all the required libraries to run Stable Diffusion without much manual intervention. It will also be the way we use stable diffusion.

Head to the Miniconda3 download page and click “Miniconda3 Windows 64-bit” to get the latest installer.

Double-click on the executable file once downloaded to start the installation. The installation of Miniconda3 involves less clicking on pages compared to Git, but you need to pay attention to this option:

Check the box that says

Make sure to select All Users before clicking Next and completing the installation.

You will be prompted to restart your computer after installing Git and Miniconda3. We didn’t find it necessary, but it wouldn’t hurt if you did.

Download the stable deployment GitHub repository and the latest checkpoint

Now that we have the prerequisite software installed, we are ready to download and install Stable Diffusion.

Download the latest checkpoint first – Version 1.4 is about 5GB in size, so it may take some time. You need to create an account to download the checkpoint, but it only requires a name and email address. Everything else is optional.

NB: At the time of writing (September 2, 2022), the latest checkpoint is version 1.4. If there is a newer version, download it instead.

Click “sd-v1-4.ckpt” to start the download.

NB: the other file “sd-v1-4-full-ema.ckpt”, may be It offers better results, but it’s about twice the size. You can use either of them.

You then need to download Stable Diffusion from GitHub. Click the green Icon button, then click Download Zip File. Alternatively, you can use this direct download link.

Now we need to set up some folders where we are going to decompress all the Stable Diffusion files. Click the Start button and type “miniconda3” in the Start menu search bar, then click Open or press Enter.

We will create a folder named “Stable-diffusion” using the command line. Copy and paste the code block below into the Miniconda3 window, then press Enter.

cd C:/
mkdir stable-diffusion
cd stable-diffusion

NB: Almost any time you paste a block of code into a terminal, such as Miniconda3, you need to press Enter at the end to run the last command.

If all goes well, you will see something like this:

Minoconda3 terminal shows successful command execution.

Leave the Miniconda3 window open, we’ll need it again in a minute.

Open the ZIP file, “,” that you downloaded from GitHub in your favorite file archiving program. Alternatively, Windows can also open ZIP files by itself if you don’t have one. Keep the ZIP file open in one window, then open another File Explorer window and navigate to the “C:\stabil-diffusion” folder we just created.

Related: Get help with File Explorer on Windows 10

Drag and drop the folder in the ZIP file, “stabil-diffusion-main”, into the “stabil-diffusion” folder.

Drag and drop the contents of the ZIP file into the static-spread folder.

Go back to Miniconda3, then copy and paste the following commands into the window:

cd C:\stable-diffusion\stable-diffusion-main
conda env create -f environment.yaml
conda activate ldm
mkdir models\ldm\stable-diffusion-v1

Wait for the download to finish.

Do not interrupt this process. Some files are larger than a gigabyte, so it may take a bit to download. If you accidentally interrupt the process, you need to delete the environment folder and run it conda env create -f environment.yaml repeatedly. If this happens, go to “C:\Users\(Your User Account)\.conda\envs” and delete the “ldm” folder, then run the previous command.

NB: So, what did we just do? Python allows you to sort coding projects into “environments”. Each environment is separate from the others, so you can load different Python libraries into different environments without having to worry about conflicting versions. It is invaluable if you are working on multiple projects on one computer.

The lines we ran created a new environment called “ldm”, downloaded and installed all the necessary Python libraries for Stable Diffusion to work, activated the ldm environment, and then changed the directory to a new folder.

We are in the last step of the installation. Go to “C:\Stable-diffusion\stabil-diffusion-main\Models\ldm\Stable-diffusion-v1” in File Explorer, then copy and paste the checkpoint file (sd-v1-4.ckpt) into the folder.

Copy the sample file to the stable-diffuse-v1 folder.

Wait for the file transfer to finish, right click on “sd-v1-4.ckpt” and then click on “Rename”. Type “model.ckpt” in the highlighted box, then press Enter to change the file name.

NB: If you’re running Windows 11, you won’t see Rename in the right-click context menu. There is an icon that looks like a mini text field instead.

Related: Windows 11’s little context menu buttons will confuse people

Rename the form file

And that’s it – we’re done. We are ready to use Stable Diffusion now.

How to use stable spread

The ldm environment we created is essential, and you need to activate it any time you want to use Stable Diffusion. Enters conda activate ldm in the Miniconda3 window and press “Enter”. The (ldm) on the left side indicates that the ldm environment is active.

NB: Simply enter this command when Miniconda3 is opened. The ldm environment will remain active as long as the window is not closed.

Activate the ldm environment.

Then we need to change the directory (so the commandcd) to “C:\stable-deployment\stable-spread-main” before we can create any images. paste cd C:\stable-diffusion\stable-diffusion-main in the command line.

How to make a stable diffusion image

We will invoke a script,, which allows us to convert text prompts into 512 x 512 images. Here is an example. Try this to make sure everything is working properly:

python scripts/ --prompt "a close-up portrait of a cat by pablo picasso, vivid, abstract art, colorful, vibrant" --plms --n_iter 5 --n_samples 1

Your console will give you an indication of the progress during image production.

Stable spread for image generation.

This command will produce five images of cats, all located in “C:\stabil-diffusion\stabil-diffusion-main\outputs\txt2img-sample\sample”.

A cat in the style of Pablo Picasso.

It’s not perfect, but it clearly resembles Pablo Picasso’s style, just as we outlined in the prompt. Your photos should look similar but not necessarily the same.

Anytime you want to change the created image, you just need to change the text in the following double quotes --prompt.

advice: Do not retype the entire line each time. Use the arrow keys to move the text cursor and just replace the command.

python scripts/ --prompt "YOUR, DESCRIPTIONS, GO, HERE" --plms --n_iter 5 --n_samples 1

Suppose we wanted to create a realistic-looking gopher in a magical forest wearing a wizard’s hat. We can try it:

python scripts/ --prompt "a photograph of a gopher wearing a wizard hat in a forest, vivid, photorealistic, magical, fantasy, 8K UHD, photography" --plms --n_iter 5 --n_samples 1

Gopher with a purple witch hat.

It’s really that easy – just describe what you want as specifically as possible. If you want something realistic, be sure to include terms related to a realistic image. If you want something inspired by the style of a particular artist, select the artist.

Stable propagation is not limited to images and animals as well, but can also produce stunning landscapes.

Tranquil lake surrounded by mountains and exciting skies.

What do the arguments mean in the matter?

Stable Diffusion has a huge number of settings and arguments that you can provide to customize your results. The few items listed here are basically essential to ensure Stable Diffusion runs on an average gaming PC.

  • -plms – Specifies how the images will be sampled. There is a paper about it, if you want to check the math.
  • –n_iter – Specifies the number of iterations you want to create for each prompt. 5 is a decent number to see what kind of results you get.
  • –n_samples – Specifies the number of samples to be generated. The default is 3, but most computers don’t have enough VRAM to support that. Stick to #1 unless you have a specific reason to change it.

Of course, Stable Diffusion has a lot of different arguments you can implement to modify your results. Being python scripts/ --help For a comprehensive list of arguments you can use.

There’s a lot of trial and error getting great results, but that’s at least half the fun. Be sure to write down or save the arguments and descriptions that show the results you want. If you don’t feel like doing all the experimenting yourself, there are growing communities on Reddit (and elsewhere) dedicated to sharing the images and claims they generate.

#run #Stable #Diffusion #create #images

Leave a Comment

Your email address will not be published.