How to Install and Use Stable Diffusion on Windows


Generative neural networks are evolving rapidly. Not so long ago, everyone knew only DALLE and Midjourney, but now you can find neural networks for any task. And there are not only plenty of commercial tools, but also free ones. One of the most flexible, versatile and popular tools is Stable Diffusion (SD). The thing is, you can install it on your computer and create incredible illustrations for free. In this article, we will explain how to install Stable Diffusion on Windows and how to use it.

Stable Diffusion installation

SD is an open source neural network, unlike its paid counterparts such as DALL-E 2 and Midjourney. This means that you can install it on your device and use it free of charge.

Bear in mind that Stable Diffusion's basic interface isn't user-friendly. When you install official software, you have to work via the command line. However, the beauty of open source software is that enthusiasts create alternatives very quickly. It is also important to understand that the speed and quality of your work will largely depend on your video card. If it is weak, you will hardly be able to use the neural network to its full potential. The recommended graphics card is the NVidia RTX 3xxx series with at least 6 GB of video memory.  NVidia is recommended because the neural network uses CUDA kernels for generation, which are only available on these graphics cards.

A GTX1050Ti will be sufficient, but the neural network will be very slow. Graphics cards with 8 or even 12 GB of memory will provide much more comfortable performance.

Where to download Stable Diffusion

There are many different editions of Stable Diffusion, each with a different interface. Some versions are more difficult to install than others. The easiest and most convenient for those trying it for the first time is Easy Stable Diffusion. You can find it at github.com.

At the bottom of the page, select the installation file for Windows. You should download and install it. To answer the question about the installation location, it is best to choose a separate folder for the neural network, right in the root of the disc, so you can easily find it later.

The installation takes a long time, so be patient. At the end, do not forget to check Create a Desktop Shortcut, which will create a shortcut on your desktop, and uncheck Run Easy Diffusion. You will need to launch the application later.

Next, choose and download the AI model you want (different models are trained to create images in different styles). You can find models to imitate different artistic styles, to create photorealistic images, anime style and much more.

For example, let's install the Deliberate 2.0 model, which is universal and well-known to many people. First of all, download it. Then, in the folder where we installed Easy Diffusion, open the models folder and in it - the stable-diffusion folder. Copy the downloaded Deliberate 2.0 model file into this folder.

You can then run the neural network by double-clicking on the shortcut on your desktop. A window with a command line will appear, and after about a minute you will see a working interface through which you can issue commands to the neural network to generate images. The command line window must not be closed, it is necessary for the neural network to work.

How to use Easy Diffusion

The interface of Easy Diffusion in the browser looks like this:

Prompt is a field where we enter a text prompt. It defines what the neural network will generate in the final image. The prompt should be written in English;

Negative prompt - is a negative prompt field. That is, what we do not want to see in the image.

Model is the name of the model used for the generation. It is relevant if we have more than one. In our example we use Deliberate v2.

Image Size is the desired dimensions of the future image: width and height.

Inference Steps - this is the number of generation steps. Increasing this value will improve the quality of the image, but the process will take longer. On average, 16-20 steps are sufficient, but if you have a powerful graphics card, you can use 20-30 steps.

Guidance scale is responsible for the accuracy of the hint. Minimum values give the neural network more freedom, but also less predictability for you. Values above 16 will be fine for experienced users who are good at writing prompts. For normal users, a value of 7-10 will be optimal.

Show a live preview allows you to see the generation process. If you turn it off, you will only see the result.

Installing the official version:

Installing the official version of Stable Diffusion works in the same way, but the components are installed manually. For proper operation, you need a video card with at least 6 GB of memory.

First, download the Windows distribution from Git and install the neural network using the recommended parameters.

Then install Miniconda3. You can find it on the official website. During the installation, select the "Install for all users" option.

Download the Stable Diffusion archive from the official website. To do this, click on the "Code" button and find the "Download ZIP" option. Download the Stable Diffusion model and select the latest version.

Search for the Miniconda3 console in the Windows
taskbar and run it. Enter the commands to create the SD files folder:

1. cd C:/

2. mkdir stable-diffusion

cd stable-diffusion

Copy the stable-diffusion-main folder from the previously downloaded Stable Diffusion archive and move it to the main folder of the neural network. For example, if you installed it on the C: drive, it will be C:\stable-diffusion\.

In the Miniconda3 console, type the following commands:

3. cd C:\stable-diffusion\stable-diffusion-main

4. conda env create -f environment.yaml

5. conda activate ldm

mkdir models\ldm\stable-diffusion-v1

At this stage you will have to wait a while as the download of additional components from the internet begins.

When the download is complete, the model.ckpt file should be copied to the C:\stable-diffusion\stable-diffusion-main\models\ldm\stable-diffusion-v1 folder.

This completes the installation. You can now run Stable Diffusion as a command line application:

conda activate ldm

It will always start in this way.

Working with Stable Diffusion

If you are using the official version of SD, the work of generating images is done directly from the console. You use commands to pass image parameters to the neural network.

For example, if you want to draw a cartoon snowman, the command will look like this:

python scripts/txt2img.py --prompt "funny snowman, cartoon style" --plms --n_iter 3 --n_samples 1

iter 3 in the command means that the AI will prepare 3 variants of the image. The image resolution will be 512×512. The finished images will be sent to the Stable Diffusion folder.

C:\stable-diffusion\stable-diffusion-main\outputs\txt2img-samples\samples

If you want to see what command line options are available, type in the console:

python scripts/txt2img.py --help

Conclusion

It is not that difficult to install and start working with Stable Diffusion neural networks. However, there is a lot to learn when it comes to high-quality generation. Once you have studied the interface and the available settings, master the correct formulation of promts. Read articles, look at other people's work, pay attention to what kind of requests users use to achieve the desired artistic effect.


Is useful article?
1
0
author: John
published: 02/16/2024
Last articles
Scroll up!