-: All right, let me show you how to train a product
into Stable Diffusion.
So this is using Dream Booth.
You know, this is the Shivam Shrirao.
(chuckles) I can never pronounce it.
This is there, you know, specific Colab notebook,
which is really, really powerful.
Colab, the reason we use this
is it actually gives us access to a GPU,
which is needed in order to run this.
And even with the GPU, it takes quite a while.
So buckle up.
So we're gonna go through, first thing you wanna do,
I'm not actually gonna run this
'cause it'll take a long time.
I've already run it in the background,
but I'll kind of walk you through it.
So first you need to kind of install the code
to train Dream Booth and the Diffusers library.
You also need to log into Hugging Face.
So you need to put your HuggingFace token in here.
You can get that when by logging in.
I'm going to, yeah, I've already changed mine here,
so you know, yours would work,
but if you try this, it won't work.
But you'll have your own and you can just kind of
visit Having Face and go to the API section to get that.
I don't recommend saving the model with gdrive,
it takes up four to five gigs,
so it can take up quite a lot of your gdrive,
but if you're gonna use it again, you can do that.
The model that you're using is here.
I use the Stable Diffusion version 1.5.
You know, I think there are later versions,
I don't know if Dream Booth specifically works them,
but this is the one I found works pretty well.
And then you just wanna kind of create a directory
for outputting the weights.
Alright, so I'm gonna start training
and there's a few things you need to change
before you do that.
So one is like, at least specifically here, you know,
if you're training on a person,
like if you're making one of those AI photo,
you know, photo profile things
where you train yourself into the AI
and then put yourself into different situations,
then you would use this class instance of a person.
But in this case, we're doing a product
and then we're calling it the product zwx.
So that's what we're going to use in the actual prompt, zwx.
And you just run that and then you can upload your photos.
So here I have, you know, all the photos that I've uploaded
and it's actually takes a little bit of time to do that.
But you know, that's done.
You could also, if you know how to structure it,
you can actually upload it into the instant data directory.
But, you know, if you're not as technical,
then just run this and click "choose files".
All, right so this is where
the actual training happens, right?
So, you know, put the model name in, et cetera.
You don't need to change anything around this.
Just make sure that this is a sample prompt.
So this is what is going to use to run afterwards.
Although obviously you can run your own prompts
and you just need to kind of make sure that fits.
So I have the product as zwx or dwx and you run that
and then it starts the training.
So it took a little bit of a while.
In this case I think it was, you know, 14...
Yeah, 26 minutes.
So not terrible, especially for how valuable it is.
And then this is where you kind of run it.
So if you already have some weights,
if you've saved them in the past, you know,
you could use them here.
But this is where it really gets interesting.
So what I trained it on
were pictures of my daughter's purse.
So she's three, right?
And she has like this little kinda purse that she got
with sequins, purple and turquoise.
And the really cool thing here is that
these are not real pictures of the purse, right?
Like I uploaded them earlier.
These are actual kind of, AI generated photos
and they look similar to the ones I've uploaded
because that's kind of in the training data now.
Like I uploaded one that was next to my kitchen tiles,
one on a wooden surface, et cetera.
You wanna provide different formats
and the more different scenarios and angles
you put the product in, the better
because then it's gonna be able to replicate that.
Cool, so that kinda shows that it works,
but then the way you actually use it is
when you run inference down here.
So you can set a seed
and that makes it reproducible, so you run the same thing
and it'll get the same result.
But what I wanted to do, just to impress my daughter
was have Princess Elsa from Frozen
carrying zwx product, right?
'Cause I've negative prompts,
you can change the guidance scale, all these other things,
but you can see that, you know,
in some cases it doesn't get it right.
but in other cases it kind of gets a bit creepy.
Here it kind of looks like the purse,
but then some of 'em turn out great.
So you can see here that this really looks
much like the purse and then it's pretty much got
Princess Elsa here as well.
So, you know, this is kind of a basic prompt
and you can do more fine tuning on this.
You can provide more images,
you can actually do this with multiple products.
But just wanted to kinda show you how you could do this.
You know, if you have this use case of generating ads
for a client or, you know, generating photos
where you actually have to have the real product inserted,
now you can train the AI on this specific concept.
And that's it.
So this takes up a lot of space and you know,
you can just about run it on a Google Colab for free.
But you know, typically once you're doing this more often
you would do this on your own GPU enabled computer
or in the cloud.
And this is basically the same code
that these AI profile photo companies use,
but obviously, we're using it
to train the product in this case.
So, yeah, hopefully that was helpful.
It's a really powerful use case
and obviously if you can kind of get it to work
for the more powerful Stable Diffusions
or as the models get better,
then you can be much more flexible with this.