Stable Diffusion Tutorial
In the past, artificial intelligence (AI) text-to-image software was only accessible to a few lucky individuals who managed to get beta access. Stability AI is changing the narrative with its recently launched latent diffusion model, Stability Diffusion.
On 22nd August, 2022, Stability AI launched Stable Diffusion, an open-source AI image generator. Not only is Stable Diffusion open-source, but the model can be run on consumer-grade gaming computers. Stable Diffusion is transforming the AI image-generation space to give every user the ability to create stunning art from text input.
The next step is to learn how to use this amazing AI image generator.
How to Use Stable Diffusion
As an open-source project, Stability AI published the codes of Stable Diffusion for free, which opens up the possibility of multiple ways of using the text-to-image latent diffusion platform. In this tutorial, we’ll look at three possible ways of using Stable Diffusion.
1. Run Stable Diffusion Locally
If you want complete control over Stable Diffusion, you can install the model on a consumer-grade computer that has at least six gigabytes (GB) of VRAM and ten or more GB of internal storage space on a hard drive or solid-state drive.
To install Stable Diffusion on a PC, you need to first install two pieces of prerequisite software: Git and Miniconda3.
To create images with Stable Diffusion, take the following steps:
- Visit GitHub and download the cloned repo of Stable Diffusion by clicking ‘Code’ (green button) and selecting ‘Download ZIP.’ Unzip the file.
- Find ‘stable-diffusion-main/models/ldm’ in the unzipped files. Create a folder with the name ‘stable-diffusion-v1.’
- Rename the sd-v1-4.ckpt file to ‘model.ckpt,’ and copy it into the new folder (stable-diffusion-v1) you made.
- Open the file ‘environment.yaml’ in Notepad. After the line saying ‘dependencies:,’ add ‘- git,’ The ‘-’ should be lined up with the ones in the following lines.
- Visit Miniconda and download Miniconda 3 for Windows.
- Install Miniconda for all users. However, during the installation process, uncheck ‘Register Miniconda as the system Python 3.9.’
You now have Stable Diffusion fully installed on your PC. To create images using the software you have installed, use the following steps:
- Run the Anaconda Prompt/Miniconda 3 you installed.
- Type "cd" and then drag the folder into the Anaconda prompt console.
- Open the stable-diffusion-main folder you created and run the command: ‘conda env create -f environment.yaml’ in Anaconda Prompt.
- Run the following command: ‘conda activate ldm.’
- To generate an image, run the following command: ‘python scripts/txt2img.py --prompt ‘input your prompt here’ --H 512 --W 512 --seed 27 --n_iter 2 --ddim_steps 50.’
- To create your own image, replace ‘Elon Musk as an alien’ with a description of the image you want created. Run Stable Diffusion to generate an image based on the description you provided.
To create more images, repeat the fourth, fifth and sixth steps in the section immediately above.
2. DreamStudio Web App
Another way to use Stable Diffusion is to run the model through the DreamStudio web app, which was also developed by the makers of Stable Diffusion. All you need to do is create an account on the DreamStudio site. Anytime you log in, input the text you want to be converted into an image and click the Dream button.
The DreamStudio web app will generate your image within seconds. However, you can only create 200 512x512 resolution-free images with the DreamStudio web app. If you want to do any more than this, you will need to pay £1 to purchase another one hundred generations.
3. Google Colab
One of the best ways to use Stable Diffusion is with Google Colaboratory (Google Colab). Google Colab is a product from Google Research that allows anybody to write and execute arbitrary python code through the browser, while leveraging the infrastructure of Google. This means you can run Stable Diffusion through your browser even if your PC doesn’t meet the minimum requirements required to run it locally on your computer.
The benefit of using Google Colab is that your generated images are instantly saved to your Google Drive, meaning you don’t have to worry about losing any of your artwork. Because the online process involves several steps, we covered this topic in another article: How to Use Stable Diffusion Online.
Stable Diffusion signifies a quantum leap forward in the text-to-image domain, giving almost everyone with a PC the ability to create beautiful AI-generated images with just a few words and a few minutes' time. When you compare Stable Diffusion versus DALL-E 2 and other AI-image generators, you will begin to understand why there is so much hype surrounding this model.