Getting Started with Stable Diffusion Using Google Colab
Anyone can create with Stable Diffusion as long as they have a Google account and this guide.Written By: Holostrawberry
Last updated: 2023-06-21
Feeling impatient? Go straight to the Colab Notebook and start clicking on stuff.
While AI becomes more and more widespread, Stable Diffusion remains at the forefront of image generation. Unlike paid services like Midjourney, Stable Diffusion is a software you can run on your own home computer, or in this case, on Google's computers.
This guide is perfect for you if:
- You would like to make your own images using AI, but don't know where to start;
- Your computer is not particularly powerful;
- Your budget is limited, or even zero;
- You desire full control over the images you generate, even if that means learning a few new concepts along the way.
Normally, Stable Diffusion requires that you own a computer with a modern graphics card, specifically, around 8 GB or more of video memory (VRAM). However, there are several services online that let you borrow computing power for the purposes of AI. The most notable of these is Google Colab.
Thanks to Google Colab, we can run a program that somebody else created, on the cloud, from the comfort and safety of our own device. This service is "free", that is, you can use it for a limited time each week without subscribing to a premium plan. Please note however that Google may restrict you from running Stable Diffusion without a premium plan, although this is inconsistent. In any case, the plan would cost $10 for dozens of hours of continuous usage, or thousands of images.
To generate images, we will be using Automatic1111's WebUI, which is an interface for using Stable Diffusion that you can control from your browser. It will be launched remotely from within a colab document, made by a talented user whose contact info you'll find attached.
Starting the Colab
First open the colab document here.
You'll see a few options you can read through, but below are the ones we care about right now: You can choose whether the images you generate and your settings will be saved to your Google Drive. If you don't, the images you created will be deleted after you close the colab!
Then, we come to a section where you can choose what kind of resources you want to make images with. Select the default model of "deliberate_v2" for this guide.
Finally, run the colab by pressing the floating play button () on the left side of the screen.
You'll need to wait a little bit while the notebook is running and configuring a Google cloud server instance to run Stable Diffusion and create a webui for you. When it is done running, it will produce a public link, which will look like this:
Click on it to start your journey with Stable Diffusion!
Creating Your First Images
The WebUI tab you just opened should look something like this:
There is a vast, grand number of options available to you. But you only need a couple of them to get started! Here's a few things to note:
- At the top, our "checkpoint" is deliberate_v2 like we selected earlier.
- We're in the first tab, called "txt2img". This means we can generate images from a text prompt.
- This prompt is the main text box, which is currently empty.
- Below the prompt is the negative prompt, which currently has some terms we would like to avoid. Don't worry about them for now.
Let's try a simple prompt to start. I write "green bowl with chicken nuggets" in the prompt and click Generate on the right side. This image pops out:
(Image generated with seed 1. Yours will most likely be different)
That's cool, but what else can it do? Well, the Deliberate model is good with human subjects. I'll try "30 year old canadian woman eating chicken nuggets"
This person isn't real! Well, you can probably tell. She looks a little off, but we could probably tweak the settings a bit or try again. Additionally, it would probably do better if it could focus entirely on the woman, without the chicken nuggets. I change the prompt to "30 year old canadian woman, kitchen", then I go to the settings below the prompt: I simply change the Sampling method and enable Hires Fix (which upscales the image). Now the image takes much longer to generate, but...
That's pretty good! (Does she look Canadian to you? Let us know!)
Notice how her face is different - Stable Diffusion doesn't know any one specific face (except a few famous people), so you won't be able to make multiple images with the same face unless you use more advanced methods. What we can control are her features, such as hair color and body type.
Now, let's expand on what we know.
Using models from Civitai.com
Stable Diffusion is a software, but the "model" or "checkpoint" you use is the actual brain of the artificial intelligence, of which there are thousands available for free online. You can generate images of a variety of topics, in a multitude of styles, and even specific people, characters, or situations.
Now we will be going on Civitai to find a new model to use for generations. Make sure it is labeled as a "Checkpoint" (other types of models work differently). For this example I pick Anireality-Mix, which seems to offer generations of anime characters in realistic landscapes. To add it to our colab, we must do so before we run it. All you need to do is right-click the Download button, copy the link, and paste it in the "Custom URLs" part of the colab. If you wanted to load more than one at the same time, you would separate the links by commas
Now we run the colab cell like we did earlier. After you open the link you'll be able to choose the model in the top left:
I'll use some common anime tags and techniques to generate an image using this model. I'm skipping ahead a few steps, but if you want to learn more about improving the quality of your images, look forward to more guides from us in the near future!
Tip: If you want to generate similar images to examples you find on Civitai, you can copy their generation parameters, assuming they were included. It's often impossible to get every setting the exact same however, so don't worry if you don't get the exact same image. If your image is too different, you may be missing something. You can join our Discord and ask for help!