StableDiffusion is the latest AI model to takeover the image synthesis scene. Recently, the model was publicly released for anybody to freely use. There are many developers who have been hard at work creating new open source tools and resources increasing overall accessibility this amazing AI technology.
You can use StableDiffusion for free using Google Collab and this guide was created so you can join in on the fun and start making your own AI masterpieces.
There are quite a few existing StableDiffusion notebooks that are currently available (and there will be many more to come) but for this tutorial we will be focusing on the simple and effective “Stable Diffusion notebook” by Pharamapsychotic.
There is only one thing you need to download which is StableDiffusion model itself . You also need to have a google account and a HuggingFace account to use this model and notebook. Click the two links below and then continue reading this tutorial. I would also recommend opening another tab that is on your google drive.
Links You Will Need
Firstly we have to download the model. Create or sign into your HuggingFace account, then go to the StableDiffusion model download page on HuggingFace (link above). Select access repository, then accept the terms and begin your download. You won’t see this option if you aren’t signed in.
The download is around 4gb and you will only need to do this one time.
NOTE: If it doesn’t automatically download click the new “come here” that is on the third paragraph of the page.
Then download “sd-v1-4.ckpt”.
Once it has been downloaded go into your google drive and place the file under My Drive > AI > models . If these folders don’t already exist just create them with the same names.
Once you have uploaded the file to your google drive you are ready to begin working with the notebook.
Now we are going to run each cell one by one (A cell is a group of code in the notebook) by pressing the play button that is to the left of each cell. We will start by pressing the “Check GPU” cell.
On the first cell you can check what GPU you get. This effectively tells you how quickly you can generate each image. If you are using the free version of google collab you will want to get at least a Tesla T4 GPU. If you have google Collab pro you will ideally want to go for at least a Tesla P1000.
As you can see in the image below we got a Tesla T4 which will work great for us for now.
If you get a K80 graphics card or want to try and get a better GPU go to Runtime > “Disconnect and delete runtime” and click. Then rerun the “Check GPU” cell.
If you end up getting the same graphics card you can continue to disconnect and reconnect until you get the GPU you are satisfied with.
Once again, a Tesla T4 will work fine and that will most likely be the best GPU you get with the free version of google collab.
The mount google drive cell will connect to your google drive so you can easily save your models and images to the cloud. When you run this cell there will be a popup window clarifying the connection.
Install / Load Model
Just run these two cells and wait for all the installations to finish.
After all these cells are done running we can get to the fun stuff.
The Fun Stuff
Now to the actual image creation. This notebook keeps the parameters nice, simple, and easy to use. This tutorial won’t go too in depth with each of the parameters but you can learn a little more in the “image creation” section and from experimentation.
A list of those parameters is featured below.
For beginners you really don’t need to touch anything but feel free to play around with the parameters.
Note: width and height must be a multiple of 64. (256, 512, 704, 768)
The parameters are not scary. There is nothing you can do to really mess up I promise. There will be some parameter notes at the end of this tutorial.
For now you should only change batch_name to “Test” or you can name it whatever you like. This is what the folder in your google drive will be named and where your outputs will save to.
At the bottom of the page we already see a cat created with the notebook. Before we make any adjustments to the settings lets run the “Image Creation” cell and see if we generate our own cat.
If everything is done correctly you should see a fresh new feline face! The images save directly to your drive and you can find them under My Drive > AI > StableDiffusion > YOURBATCHNAME
Images and settings get saved here.
Okay now the final step to making your own prompt! Prompting can be challenging and is a skill that requires practice and patience.
As an example prompt I will use “A man teaching art to a human sitting behind a computer screen”.
Well… that didn’t turn out as I wanted. I thought AI art was supposed to be perfect!!! Alright I give up.
Don’t let that be you, in fact I think this image perfectly resembles the whole creation experience. It won’t be perfect every time and patience is key. Prompting is a skill that takes time to learn try lots of different things. Do not be afraid!
Also wanted to quickly touch on init images. Init images are basically starting images that you can transform with AI.
If you click the folder icon on the left side of the screen you can open up the files of the current session.
Now simply upload your file to this section. For our example we will use the original cat image we generated.
After you have uploaded the image right click the filename in the file section of the page and “copy path”. Paste this path in the “init_image_or_folder” variable.
Init strength is how much the image will look like the original. This value goes between 0-1. If you set it to 0 it will look nothing like the original image and if you set it to 1 it will look exactly like it. 0.3-0.5 is a nice range that gives variety and some great results. Feel free to try whatever you want. In our example I will be using 0.4.
Time to render! With an init image you also write a prompt. I am going to put “A human with fur and whiskers school photo portrait.”
I hope you enjoyed this tutorial and that you can create some amazing things.