You've probably seen the Michael Jackson video, Black or White. Where they do these amazing
morphs between people. I'm going to show you in this video how you can do this kind of thing.
We've talked about GANs before. GANs are these images that you see here. These are not
real people. These are basically random number sequences that NVIDIA StyleGAN2 ADA turns into
these images. Well if you transform one of these vectors, which is what these people are made from,
to the other you can get a very similar effect to the Michael Jackson video as you see here.
The problem is most people ask me, well how do I do this with real pictures. The way you do this
with real pictures is you need to essentially find a latent vector inside of the GAN space,
so to speak. Of all of these images that StyleGAN can generate that looks like you or the person
that you want to transform. And this will only work with people because NVIDIA StyleGAN2 ADA,
at least with the FFHQ dataset, the faces, that is what it was trained on. So you need to find
a different pre-trained GAN if you wanted to generate other types of images. But let's focus
on how we do this for faces. Here's a sample video. I transformed me into Thor or another
one I transform me into Anakin Skywalker. I particularly like this video it was kind of fun.
I call him GAN-akin Skywalker. I basically make Anakin can grow up to a Sith lord using waypoints
of several different samples in his ages from the videos. I'm gonna focus really just on how to run
my script and use it. If you'd like to see another video doing a deep dive into the code, definitely
let me know. Give me a like in the video. The likes are very much what I use to tell what I'm
going to make my next videos on. I always go back and look at what has been liked the most what has
gotten the most amount of views, and subscribe to the channel so that you don't miss anything.
Let's just jump right into it. Now this does make use of Python and Python coding mostly my videos
are for coders, but if you just want to do a morph video, you should be able to make it through this
without knowing really anything of the code. This is GitHub and you're going to click open in CoLab.
This basically just opens my Jupyter notebook in CoLab. A Jupyter notebook just contains code in
the instructions on what you want to do with that code. Make sure that you have a GPU. If you do
run time change runtime type you should see hardware accelerator GPU it may not be picked
by default. So make sure that you have that. What you're going to do now is run the blocks of code.
You have to make sure that you run each of them. If you don't run them all you'll get an error.
So you'll run this, "steps" is how many steps it's going to be in your video.
The more steps you have, the longer your video is. This is your frames per second
and freeze steps, this is, just shows you the image at the beginning of the video before
it starts to morph. So this gives you like a second-lead-into it and then at the end it freezes
on the final frame just for a second or so. You need to upload your starting image you run this
and then you click choose files, and I'm going to pick me. I'm going to turn myself into Thor again.
Click this to choose your ending image. This will be Thor. In my case you want these images to be
relatively high resolution at least 1,024, because that's what the final GAN is going
to render into 1,024 by 1,024. So if it's smaller, you're going to get pixelation.
So now I've got both images uploaded into the system. We have to install StyleGAN2 ADA
into this and we have to install some software that I need for pre-processing. These are both
in these two frames. Pre-processing is very important if you just use the
out-of-the-box software that NVIDIA gives you. You're going to get an image a starting image say
that looks like this for me, yeah that's horrible. So don't do that. What we're going to do instead
is pre-process it. I'll do a more in-depth video and explain the code that I put together. I wrote
this really just to do the process that I used to do in Photoshop manually. It uses some artificial
intelligence. This is the code that actually calls that function above and pre-processes it for you.
So it's going to give you the crop source and the cropped target. Notice it really zoomed in on
me it's important that your facial features be in specific locations. It's important that
my facial, at least some of my facial features, are where Thor's are. Now I didn't choose as high
a resolution of the image of Thor as I had in the sample video that I showed you just
a few minutes ago. But this will work. Now we're going to convert the source into a GAN
again, is just a numeric representation of the picture. It's not exactly me. It's going to
be in the GAN-space of just about an infinite number of images that these GANs can produce,
which one looks the closest to me. So it's my GAN doppelganger. The same thing will happen for Thor.
We'll fast forward through this. This takes a bit this will take maybe five minutes running
it through. Now as it builds this, you'll see distance. This is the distance between the
GAN doppelganger and me. This will get smaller and smaller and smaller. It should land somewhere in
the 20s. Loss is just the training parameter that it's trying to push further and further to zero.
If you do want higher quality GAN representations increase this number of steps. I set this to 5,000
for the higher-quality videos that I showed you earlier. As I was doing the intro. 3,000 is also a
good middle-of-the-road number. All right, now we need to do the target image. Don't need to change
anything and I'm going to do a lot of other videos related GAN and graphics processing
with artificial intelligence, so please subscribe to the channel if you don't want to miss any of
that. All right, let's have a look at the GAN doppelgangers and see what they look like. Now,
this is an image that I put in previously, so let's run it on the new one that I just
uploaded. It's not as high a quality as the other ones. I might want to potentially play
with the image in Photoshop, but yeah that's me it's kind of an "angry me." But it's
nonetheless me. That was from a higher res Thor let's see what this lower res store looks like,
uh not horrible blurry. So now let's build the video. This is actually pretty quick. What's
going to happen is both of those two images are Thor and me reduced to a series of numbers and
it's going to use linear algebra to basically just transist between those two images. So you can see
it happening here this is pretty quick we'll just let that run in real-time and it's done.
Now we just download our video and that's it you'll get something called "movie.mp4" we'll
play that in just a second that'll be 1024x1024 resolution, so it's relatively high-resolution
video it's square so it's not HD aspect ratio, but it is close to HD
quality. So let's have a look at that, all right there you see me transist into
Thor. Would you like to see more of the code and see how this actually works is there are
several interesting things going on here both my pre-processing and how it searches gan space to
actually find my doppelganger and it's important to realize too the Michael Jackson video
where they were using morphine technology they weren't using AI, they were using
images and identifying facial features and letting the computer kind of morph from one image to
another. This is not really using the original images. It's just finding two gans and I know
that GANs I can do a morph type transition between them. So definitely subscribe if you want to see
the more advanced versions of this and go through the code. Thank you for watching this video
have fun making your own GAN transformations with these. Let me know in the comments what
you've used it for and how well it's worked for you and if you'd like to see the deep dive
into the code. Let me know. Like this video and subscribe to my channel thank you for watching.