-: Hey, I'm gonna show you how to make AI profile pictures
like you might've seen on Twitter.
So there are a few of these tools out there that do this.
And to be honest, it's probably better
and easier just to use those tools,
especially if you don't have access to a GPU.
But you know, I think there's a lot you can do
in terms of flexibility once you understand
this format and how it works.
We're using Dream Booth.
A Dream booth is a way to fine tune
the Stable Diffusion library
to train it on your own images.
So you could train it on a specific style
or you could train it on pictures of yourself.
Like I have.
The main thing to note here, I'm just gonna connect,
is when you connect, you wanna view your resources
and change runtime type
and you need to make sure that you're running with a GPU.
So the reason why you need this is
you're running Stable Diffusion and also training the model
and that is resource intensive.
So I'm not actually gonna run this,
I've run it previously,
just 'cause it takes quite a long time.
But you'll have access to this code
to be able to run it in a couple hours yourself.
So we're just, you know, first thing just downloading
the install requirements.
So that's pretty quick.
And then you need a HuggingFace token.
So this one is mine.
I'm gonna delete this afterwards
just so you guys can't access. (chuckles)
But in order to get it, you could just go into Hugging Face.
This is the original Stable Diffusion, the 1.5 version.
And then I'm just gonna go to the settings.
I think first you have to accept this model card,
which I've already done so it's not showing up for me.
But if you go to Access Tokens
and then you know, you can create a new access token here.
So that's where you would run this.
And then if you wanna invalidate and refresh,
you can do that here as well.
And then this token will stop working.
So that's fine 'cause I'm not running this.
The model name that you're using
is Stable Diffusion 1.5.
And then you have like an output directory,
which is gonna kinda store this locally.
There's just enough RAM and storage in the computer
that Google CoLab gives you to store all this.
But it's kind of getting to the limits.
Okay, so the main thing you need to do is
you need to edit this part here so you know,
you can put in different concepts.
I would say only do one concept at a time
and then like generate the image and then cut out that part.
Because when you try and combine multiple concepts,
it tends not to work very well
and takes a really long time for training.
So here we go.
What we're doing is, the instance prompt
is Photo of ukj person.
And this is a type of class.
So if you're doing a style,
like a certain type of art style,
you could change that here.
And then the reason why we use ukj or you know, zwx
is because that's like pretty far away
from an actual word, right?
It's not a real word and so we won't get confused.
And you know, there's different types of classes.
So like this product person or you could have style.
Alright, so that's just gonna run and when you run that,
it will do the JSON dump here,
to kind of use this concept list when it's training.
And now what you can do is upload the actual images.
And what I've done, I just went on my Facebook account
and downloaded 30, I think it was 30.
And actually only 20 images of myself,
just screen shotted them.
And then I uploaded them.
I would say typically you need at least 10,
otherwise it doesn't work very well.
20 is fine, 30 is great.
The more you upload, the longer it takes, obviously.
But about 20 was fine.
The main thing to make sure is that the images are all like
very similar or not very similar,
so you wanna make sure that the images
have some diversity, you know, some full body,
some close up, you know, some of you laughing,
some of you wearing a hat,
wearing different clothes, in different locations.
I think that tends to improve the diversity
because then it can kind of see the common threads
of like what makes you, you
when it kind of trains.
This is the actual training code here.
So nothing to change other than the sample_prompt.
And so what I wanted to do is I wanted to make
an illustration of myself in the style of
SpiderMan: into the Spiderverse.
I generated this prompt.
I would say like this is really good
to combine fine tuning with prompting.
So this is an actual prompt that I used to use
in order to make Into The Spiderverse type images.
And then this is kind of like doubling up, right?
So you know, we have the prompt
and then we have the image of me
and then, you know, that way
I don't have to like kind of describe myself in this prompt.
You can actually get me from the training data.
Cool, so you can also save the weights
and reuse them if you want.
I haven't saved them, in this case,
it takes up quite a lot of space
in your Google drive or locally.
And then when you run this,
then it's generating the example images after the training.
So just to see here, this took about 10,
I guess this is 10 minutes.
It's not, oh no, sorry, it's 10 hours. Yeah.
(chuckles) So it's quite a while I was running it.
Yeah, I think it's 10 minutes,
but sometimes it takes a long time to run.
I've run it before and it took half a day.
And so I think that's probably the longest.
You just make sure you have the GPU
and that's what makes it faster.
Cool. So it did a pretty good job, right?
Like this is a decent image of me,
obviously this is kind of cheating, showing me in a mask,
but you know, this is kind of, taking my beard
and my eyebrows and my hair and stuff
and yeah, I think it's done a good job of matching the style
and putting me in into the Spiderverse.
You can also save the weights and kind of
use that for...
At some of the web UIs, like automatic, if you want.
But you can also just keep running it in this Google CoLab.
So at this part here is to actually kind of run the pipeline
and then you can set a seed from here.
And that's just so you get the same image every time
if you use the same prompt.
And then I've used at this specific prompt here,
illustration ukj person in the style of SpiderMan,
blah, blah, blah, right?
So that's what it's come back with.
And you can edit this so you can say, you know,
I want guidance scale.
Like you know, the higher the guidance scale,
the closer it is to the prompt,
the lower, the more kind of creative it can be.
There's also number of inference steps.
So, you know, if these steps are higher,
it tends to be higher quality images, but not always.
I think it's good to experiment with this.
And then number of samples as well.
So I've generated four images here
and yeah, you can see it's done pretty cool job here.
Cool. So, that's how this works.