-: Okay, this is Stable Diffusion.
Now this is definitely the most technical
of the image models because it is open source.
So you can actually run Stable Diffusion on Stability AI.
They have their own interface there,
but most of the reason why you want to use Stable Diffusion
so you can customize it.
So it really applies more to developers
than to like the average person.
I would say if you don't know how to code,
you don't want to code,
then you're probably better off using
DALL-E or Midjourney.
However, it's incredibly powerful if you do need
to do more advanced stuff.
It's really the most flexible model.
That said, there are actually multiple models now,
and some of them are less flexible than others.
So I'm just gonna go, this is the Google Colab.
I'm just gonna make a copy of this.
The reason why, you know,
actually lemme just do this way,
the reason why this is interesting using Google Colab
is that you typically need like a graphics card
to actually run Stable Diffusion.
It's a really big model
and it's also incredibly computationally expensive.
So unless you have, you know, you know how
to set this up in the cloud
or unless you have, you know, an M1 Mac
or you know, PC with a high-end graphics card,
you're not really gonna be able to run it.
However, at least at the time of recording,
Google is very generously gives you a GPU
that you can use here.
So I'm just gonna connect,
I'm just gonna allocate some resource
and then we're gonna run the pipeline.
So once this is initialized, we're connected,
this is an Nvidia command,
and then we're just gonna hit like Shift and Enter here,
or you can hit Play.
And what this does is it finds out
if we have a graphics card.
So here we have like a Tesla T4 graphics card,
which is really good for us to run.
Then we install the Stable Diffusion library.
So just running this when you are, you know,
when you're running this,
it's actually kind of running on Google's cloud.
So it is not actually running on your local computer,
which you know, is why we can kind of get away
with running it even if, you know,
I don't have a GPU on this.
So that works.
Now I talked to a little bit more about,
there's multiple models.
This is where it kind of gets confusing.
So Stability AI is, gets a credit for Stable Diffusion
because I think they're the most popular
or the most well-funded company,
but it's actually in collaboration with Runway ML,
which also do a ton of like video stuff.
Really interesting.
And there was a lot of confusion.
Still a lot of confusion.
They also have, you know, they've got the 1.5 model,
which is the old style, which is what a lot of people used,
but then they released v2.0.
And there's a lot of controversy there
because frankly a lot of people
are using v1.0 for -- and you know,
for making pictures of celebrities and you know,
for copying different artist styles.
And then v2.0 has largely made it impossible
for you to use it for that.
But there's a huge increase in quality.
So, you know, have a, you know, if you,
you want flexibility, you know,
the audience for Stable Diffusion
wants a lot of flexibility,
maybe not obviously for the best reasons
and therefore there was a lot of controversy
with the move to 2.1.
But you know, just to kind of, you know, figure out
what model you actually wanna run.
Here we have 1.4, which is I think the original,
the original Stable Diffusion.
And that's what's running here.
The actual use of it, it's not that different depending on,
you know, what you're doing with it.
And there's a lot of advanced functionality
was kind of built on top of it,
but v1.4 still works pretty well, you know,
relative to other models.
We've got, this is like pulling in all the different files,
and it's downloading a bunch of stuff.
It's pretty resource intensive,
like I said, even with it, you know, GPU,
it's gonna take a little bit of while to run.
So I'm just gonna pause this,
I'm gonna wait till it is downloaded
and then I'll start again.
Okay, this is downloaded only took a couple more minutes
and now we're ready to start Inference.
Inference is when you pass it a prompt
and then it infers what image to create.
So we're gonna create this pipe to CUDA
CUDA is basically a framework for running on the GPU,
so that's how we get it running faster,
otherwise it would take all day.
And then this is how you actually call Stable Diffusion.
So passing in a prompt, this is the text,
"a photograph of an astronaut riding a horse,"
and then we're getting back the image, you know,
it brings back the image in PIL format.
And then you can just use Image Save, save the PNG,
or if you're in Colab you can actually just, you know,
type in image and then it will display
for you, which is pretty cool.
So just gonna run this and you can see how long it takes.
So it's passing through.
It's got a counter here. There we go.
So it's relatively quick.
It's not too bad when you have a GPU,
I just think it doesn't run at all when you don't.
Okay. And here we go.
We have a different image from what we had before,
obviously, because, you know,
it is a probabilistic outcome, right?
Like we get different images each time. Cool.
So a few things you can do to play around with it.
You can add a manual seed, which makes it not probabilistic.
So we've added this manual seed
of just like a random number,
but as long as we use this number 1024 in the seed,
if we run it again,
we're gonna get the same thing again and again.
So I just run that again
and it's using the same seed
and it's gonna come back with the same image.
And the reason it does that
is because of the way Stable Diffusion works, right?
Like it's, it's a diffusion model.
It's starting with random noise
and then it's generating an image while this seed basically
starts it with the same random noise each time.
So it will generate the same image given the same prompt.
Cool. You can also change the number of inference steps.
So this makes a lower quality, you can tell it
how many images to bring back.
So this is how you assemble a grid
and that creates a certain number of rows.
So here we're generating three images.
If we wanted, we could, you know, put like 10 images
or nine images, whatever we want.
And then, you know, we can generate
like bigger grids like it's saying here.
So this is, you know, you're starting to see some
of the flexibility, you know,
when you are using Midjourney,
you just get a grid of four images, right?
And this gives you a bigger grid.
You could also run this with like,
a smaller quality level, right?
Like, so you could run with a smaller number
of steps in order to find an image that you like.
This is to generate a non square image
if you wanna change the different styles.
And you can really do a lot more than this actually,
you know, you can train the model yourself
even with DreamBooth.
So flexibility is really the key with Stable Diffusion,
you know, a program valid, your program,
programmatic ability, I guess is,
is what people are attracted to.
Not necessarily that it's the best image model,
but just really it's the one
that you can build your whole business around, right?
Like, you know, you can't rely necessarily on DALL-E
or, you know, rely on Midjourney, you know,
if they change something about the way it works,
then you don't really have any flexibility.
You can't really go back to the older model, right?
You know, if they ban certain types of images,
then you're stuck.
So that's what really people like about this model
and what's attractive.