- It generates high quality, coherent, and beautiful images based very fast, with much less resources than other image generation software.
- The team behind it seems to be extremely open and transparent. They seem to aim to give power to the people.
- Even if Stable Diffusion is also paid, they have made it available to the public, and we can use it via Hugging Face Spaces and we can also use Stable Diffusion from Hugging Face via Google Colab, which is free, and is the method which we’ll be using.
You don’t have to know anything about programming to follow this tutorial. We’ll simply run some code, observe the results and try to understand what’s going on.
We recommend you also check out our newer tutorial on a variant of Stable Diffusion with a web user interface. It’s easier to use, still uses Google Colab for free, and has many more features available.
Google Colab might seem intimidating at first, but it’s really quite easy to use. You can run each block of code in Colab by clicking on it, and then hitting the “play” button on the left side. We don’t have to understand what it means.
For a quick and easy intro you can check our Google Colab beginner guide.
Here’s a quick demo to see how fast and effortlessly you can generate images using Stable Diffusion in Google Colab:
Table of Contents
- Getting Started with Stable Diffusion (on Google Colab)
- Quick Video Demo – Start to First Image
- Step 1: Create an Account on Hugging Face
- Step 2: Copy the Stable Diffusion Colab Notebook into Your Google Drive
- Step 3: Make Sure You’re Using GPU
- Step 4: Run The First Cells
- Step 5: Run the Fifth Cell to Download Required Files
- Step 6: Generate Our First Image
Sidenote: AI art tools are developing so fast it’s hard to keep up.
We set up a newsletter called tl;dr AI News.
In this newsletter we distill the information that’s most valuable to you into a quick read to save you time. We cover the latest news and tutorials in the AI art world on a daily basis, so that you can stay up-to-date with the latest developments.Check tl;dr AI News
Getting Started with Stable Diffusion (on Google Colab)
We’ll start with a quick demo of running Stable Diffusion on Google Colab from start to finish, until we generate our first images.
Quick Video Demo – Start to First Image
The video also has timestamps to help you better understand the steps taken. Hopefully it gives you an overview of what we’re about to do.
Step 1: Create an Account on Hugging Face
We’ll download Stable Diffusion from Hugging Face. For this we need an account with them. Hugging Face is, in simple terms, a repository for working with different models, similar to Stable Diffusion, other than that it has many useful functionalities. A model is basically like a computer program that can learn to do things on its own.
The process is very straightforward. Just visit https://huggingface.co/join and create an account like you’d normally do, and check your email to confirm it.
Step 2: Copy the Stable Diffusion Colab Notebook into Your Google Drive
Next, just like with any Google Doc written by someone else that we need to edit, first visit the Stable Diffusion Google Colab (https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb) and go to File > Save a copy in Drive.
A new tab should open with the notebook saved to your drive. Only now it’s named Copy of Stable Diffusion with 🧨 diffusers. You can rename anything you want.
Step 3: Make Sure You’re Using GPU
To run Stable Diffusion we’ll need to make sure our Google Colab is using a GPU. To do this, in the menu go to Runtime > Change runtime type.
A small window will appear with a dropdown under Hardware accelerator. We want to see GPU there.
Click save, and we can move on.
Step 4: Run The First Cells
Now we can run the first cells in the Stable Diffusion colab. Just hover with your mouse on the every one of them, and a play button will appear. Just click it and wait for it to finish. It will display a green checkmark when a cell is done.
You can see that each cell has a description above it of what it does.
If something like “this notebook requires high ram” appears, just click ok.
Now we should be good to go.
Step 5: Run the Fifth Cell to Download Required Files
Next we’ll run the fifth cell, under Stable Diffusion Pipeline, that will download some the necessary components.
Also run the next cell, that says
pipe = pipe.to("cuda"):
Step 6: Generate Our First Image
Well done. Now we can generate our first image.
In the next cell, where you’re probably already seeing an image under it, is where we generate our first image.
Just write a text in the quotes, that you want turned into an image, and run the cell.
In the following example I wrote
a protoss cityscape with advanced technology, inspired by the game starcraft, making heavy use of light and shadow to create a sense of mystery and foreboding. the city sprawling below is a mix of organic and inorganic, with swirling energy currents and strange crystalline structures, illustrated in a realistic and detailed style by wei wang, artstation.
Well done! That image generation should have taken under a minute.
Generate Multiple Images at a Time
In the initial demo video you’ll see we’re also generating 3 images at a time. To do this scroll a bit further and you’ll see the following cells.
Just run the one that starts with
from PIL import Image and in the following one edit the text in
["blah blah"] and run it.
Congratulations! Hopefully this guide got you to generate your first image using Stable Diffusion from Hugging Face on Google Colab. From here you can explore the other instructions in the Google Colab notebook. Our purpose here was to just get you up and running to get through that initial barrier.
If you encountered any issues or have any questions feel free to leave a comment and we’ll get back to you as soon as we can.