Face Swap AI in Python! Live Coding.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign hello hello can you hear me okay it is Tuesday June 6 2023 and we are back in the building how's everyone doing today we are live zero nine damage welcome to the chat and I hope you're having a good time I need to make sure that I mute everything I'm listening to because otherwise I get an infinite Loop in my ears okay there we go my favorite is live oh I'm your favorite were you just mentioning that someone else is streaming they're your favorite but I also seem to be streaming Halo we have memes meme Master Pro welcome to the chat let's give people a second to arrive by the way hey if you're watching from YouTube let me know what you think about having the twitch chat appear in your chat is that too much is it confusing I'm your favorite data science ml engineer all thank you zero nine damage we got Steve uh we have we have Jamshed in the chat we have someone from Brazil Louise welcome okay so what are we gonna do today we're gonna do some live coding and we are going to try to test out some open source software now let me show you a little bit of what I've been looking at okay so you might have noticed this from the title uh but I thought today we could spend some time let me get this out of the way hold on hold on cleaning up my screen the thing is I was trying to do this offline beforehand and I was running into some issues so we're going to deal with this together it's going to be a team effort we're gonna take it on and we are going to win I know it hey from the Ivory Coast welcome Jamil from Ghana welcome aspiring data science from the Philippines cooled I actually pronounced it well ski well I think yeah you've been watching for a while so I I think I've I've got it a little better than if it was my first time just call me Zio okay Zio all right so I was looking on I don't know if you guys knew this but you can go on to GitHub you can actually look at what is trending it's kind of like Twitter trending but not as cool and you can choose the language like the spoken language you can choose the language which you code in that's python for me and I just picked this past week and I noticed that we've done facial recognition stuff on the stream before and what I would like to do is take a look at this one because it is just blowing up um from Deep Insight Insight face it's a face analysis project so um uh we have some from Iran what's up so going over to Insight faces page so if I load this up it looks like they have a website they have been updating this recently so as of four days ago there's been updates to this code base let me turn on the dark mode for you guys you can tell me if this is better oh wait you can't read anything okay so it's been updated four days ago and um it has 14 15 000 Stars that's a lot of stars I think it's because and someone can correct me if not but I think it's because this hat they have like a Discord bot that you can add using this which is pretty cool um but it's an open source library for doing things like face identification it says it does it in 2D in 3D it says it's based off of Pi torch and we can actually go to their website to kind of get a better idea of what we're going to get ourselves into um so they have a lot of updates maybe this will bring us to their website alright so they need to update this because it has more than 13.9 000 Stars it has over 15 000 stars now what do you got saying in chat what a Moon tour version do I use I just I upgraded not too long ago to 2204. 22.04 is that right or 06 whatever it was are you part of any kygo competitions right now not currently not right right now I was attempting one and I kind of gave up um all right so why Insight face insightface is an integrated python library for 2D and 3D face and Analysis we like when things are python libraries because then we can kind of work with it and write code around it right Insight face efficiently implements a rich variety of state-of-the-art algorithms for face recognition face detection and face alignment so we I already on one of my streams looked up deep face we did I actually made a whole uh YouTube video about it if you look here this is my YouTube video about deep face which was at the time a state of the art uh face detection face recognition package but since this new one has come out and it's so popular I guess it's not that new because it has some commits that were like a year ago but it did win all these Awards look it got first in the eccv 2022 wcpa challenge what's that challenge from Face Body in fashion to 3D virtual avatars 2. okay so it's some sort of image based face detection competition and it got first place in that ranked first in all these things uh going back to 2019 it's also free and open source so uh they do have some web demos here uh the thing that looks the coolest to me honestly is the face swap so I'm gonna put that in the chat for you guys so you could see it you can follow along with this but uh they're web demos have insta face swapping and we want to do this locally so I was running into some issues when I tried to set it up locally and maybe you guys can help me with this uh it might be something we actually have to go into their code and change something so let's go here let's go here and uh actually I'm going to start a new terminal for you guys I'm gonna activate my uh what's this thing called Insight conduit environment and just to show you a condo list this will show everything that's installed here so I basically just started a new python environment with a 3.9 python installed so if I could do python version we could see it's 3.9.16 all the default stuff that's installed but also this Insight face package 0.7.3 maybe that's the issue I was running into but let's see if they have a releases if they have release version releases releases add Buffalo model on April 2nd um is that really version 0.7 I don't think they're maintaining their versioning I also noticed that I was looking at the requirements.txt and this is kind of sparse not only is it sparse but it was updated a year ago so the issue I was running into and we'll see this here in a second was with numpy we'll jump into that in a few seconds Okay so what do we need to do to actually try to get this running we need to make sure we've installed face Insight which we have I'm gonna just install upgrade face insight all right it doesn't seem like that's working let's go to their they they don't have great documentation um at least for what I'm trying to do single code for facial identity swapping in our python package version 0.7 why 0.7 though when I do this it doesn't say it's 0.7 oh 0.7.3 okay fair enough all right so pip install upgrade it's going to say it's already installed right all right so everything's already installed second download the in swanner.omex walking model from Google Drive and put it put it under Insight face Dash models um from Google Drive but this link doesn't take me to Google Drive it takes us to this exact same page for a detailed code example we need to use this okay let's see what this is doing folks nice haircut oh thank you big Larry you must must have not seen me in a while uh below thank you for saying you love this I love you you love me and we're a happy family okay so we're going here what are we doing some imports now here's the problem before is numpy ooh numpy core multi-array failed to import so let's let's go I'm in my inside conda directory I'm gonna install upgrade numpy just to be sure so I tried downgrading it before and that didn't work but I'm going to upgrade it to the latest version which is 1.24.3 versions are always annoying and then we're gonna try this I think it's gonna fail still but we'll see all right so here we go so if I print my uh Insight face version I hope this is gonna work and we print our numpy version all right let's see if this works so what their example code does is it asserts that Insight face version is greater than 0.7 which it is foreign this is weird though because this is going to be oh this is a string can you do greater than or equals with a string yeah I don't think this line of code is correct right when you need to like wrap these in floats and then you need to like split this on the periods and then do everything up until the second and then you need a this is getting crazy then we need to join this that's not gonna work oh wait it does okay so this is I think what they wanted to do but just so that's the version number that's like the base version number all right so that works we got the assert version uh your English is is perfectly perfect and smooth I can understand every word in other videos I don't understand this love from India all right hey I try to be clear all right so this is the main function of this but we're just gonna pull all this stuff out here uh so face analysis it's going to use buffalo L I think it might break here but let's see [Music] there's a problem fail to download this Onyx zip file there is no deep Insight releases vo7 face swapper come on we want to do some face swapping let's just go to the releases slash download okay there's no releases uh let's look and see if there's issues mmm Onyx helper error three weeks ago um Onyx is used to like transfer models from different architectures like pie torch to to tensorflow um so let's see what's going on here what basically what it's trying to do is it's trying to download from this URL I would love to see if this file exists still somewhere in this repo can't download okay so there's an issue from 28 days ago this is coding in real life guys hi Mr cagler hi not ninja ninja okay so they're trying to use the model Zoo to download this Onyx file cannot download cannot load zip file manually through this ring GitHub respond not found plus one swapping Deno has been moved to Discord bot foreign that's awesome so they're saying that they moved it to their Discord bot only and that's why it's no longer supported through the python version this guy's trying to do the exact same as me that's awesome but I want that model to test my photo locally can you share the model somewhere 128 does not perform as well as a Discord version at present the ability to run locally seems like a good reason let's give this a thumbs up there we go we thumbed that up it seems like Discord app is down at the moment I mean uh you can test your image by using the Discord service oh okay so maybe they closed all right so as of yesterday they close this issue or they closed it last week we might not be able to run this locally we might only be able to set this I wish someone had just saved it are we just not going to be able to do it has anyone out there saved it so much for the open source version should we try to find the Discord version all right let's see what this swapping Discord model is about all these licenses okay so what they're saying is if you wanted to do a face swap with mid-journey you couldn't really do it because you're not a celebrity I'm assuming none of you watching are celebrities so you couldn't just ask mid journey to create you looking like Cleopatra whoever that is but they're saying what you can do is use mid-journey and then swap your face in uh we have to find so now now we're just like adding a bot to our server uh that's not as fun let's search the internet for this for this Onyx zip file people on Reddit are asking it for it did someone download the ins thing oh look 10 days ago someone saved it to their they saved it to their local version thank you guy on Reddit thank you Tobe 2D everyone should go and upvote that guy on here on Reddit hello Kai welcome I'm here for a first time in your shorts video so uh so what about what time do you teach live I want to join your live lecture well this is it this is it below we're doing it on Tuesday nights sometimes Thursday night sometimes Sunday nights Nando welcome from Brazil you say that's awesome I wish I could get this little chat thing to be bigger on my screen if I stretch it out it just does that but I appreciate you all right so we were able to hack our way around that so what I did was if I go into my repositories to my twitch I like this music it's getting me pumped up and then I go to I already made this Insight face directory I'm going to move from the downloads this Onyx file this ins wrapper Onyx file to here it's 529 megabytes hopefully it was done downloading there all right so now we have that swapping Onyx file and we should be able to follow this so we were able to create we were able to create this app with the face and Analysis using Buffalo l I guess that's face recognition prepare it the detection size I think that's in pixels 640 by 640 then we're doing uh this get model download is false now download zip is going to be false because we're downloading this fault so we can actually look at this code base to see what it does and maybe maybe it'll load it locally all right so it I think that worked we're gonna make our swapper object there we go so we followed everything up until here this has been done okay we have two objects we have the app which does a face analysis we have the we prepared it and what's this CTX ID uh I don't know it looks like there's also a detection threshold which we could set but we did not um so let's go to let's go to the next stuff so image get image so it's gonna it pulls down this image which is of shape 86 by 1280 does Matt do we have Matt plot lib installed and import map plot lib Pi plot as PLT I am show this this image all right so it's got the channels it's got the channels will this work yeah so the the red green blue channels by default are different when you import it with CV2 so we just flip that around but we can see it's a picture of friends you guys are probably too young to know this show in chat tell me anyone just write y or n for yes or no y means you have seen friends live like when it was released when it was released not like a re repeat but when it was actually on TV all right we have some y's and N would mean no you've never seen it all right I'm expecting seeing more ends all right so this is our image delete those put this into my imports let's see what it is n-y-n can someone tell me what the in 27 does where the where's the n27 where are we talking about the n27 I need to find where you're talking about oh are you just talking about the cell number so confused well I'm surprised a lot of wise so some people have seen uh they're they're actually an older bunch here we're a bunch of old fogies here um so we pull this images all right so let's see if the app can actually get the faces all right it it succeeded so what did the faces app actually do so what we're doing here is detecting the faces we're using Buffalo L model let's also look up Buffalo L face detection it's just going to show me a buffalo's face yeah wise don't waste money on face recognition none of these actually have Buffalo l in it can someone in chat look up Buffalo l I guess it's the large Buffalo model Medallion stallion pasta carbona or pasta bogalency the second one second one you're ordering dinner I'm assuming all right so what does our faces have it has a bounding box uh so it's a list with the length of six so it found one two three four five six faces let's go to faces the first example let's go to the bounding box it has a score of 0.9 that's pretty good it has all the landmarks it looks for pose and landmark 2D okay so it does it looks for landmarks in 3D this is kind of like as it looks like that has six D eight and in 2D it has 106. this is very similar to um face mesh which we've used before right media pipes face mesh kind of does this um 500 some 400 some whatever it is it's a lot of detected points in it they also detect them in 3D but this might be a faster model I don't really know differences doesn't really matter um all right so here's the embedding oh so it's wow it's detecting age and gender so this looks like it's doing a lot what is this model app um when it downloaded this model Buffalo l I would be interested to see what this model is just a someone complaining about Onyx error all right so we detected faces I could write all the code to take this and try to like put a box around the faces manually do you guys want me to do that like we could go through each one take the bounding box uh we could take this image no you don't want to see me do it yeah I feel like I've done that on stream a lot before for other stuff like we could take this image now watch me like start to do it um you could I think we would have to take the find the upper left corner or something and then compute a height and a width and then we draw the boxes and basically what we would get out of it is what this Insight face does when it detects these I would love it if they showed how they displayed the faces um but let's just skip that let's just assume it's perfect apply mask oh some people do want me to okay so let's do it like this I guess the easy way to just plot part of it would be all right so with the way this image is if we know understand the shape right it's um height width and the number of channels so what we want to do is basically take this example take all of the channels but for the faces for face in faces and we'll break out of this we'll take the face be box and make this our bounding box we will take the bounding box and we'll take it from to this is where I don't know which is the like it could be this this slice of indices must be integers or none wait this is these should all be integers zero okay so that no they're not integers now I converted them to being integers and let's just keep this name be box not beatbox but be box all right so this returns nothing probably because I'm mixing up the that and that no it also could be like this oh this the two and one two three bro that is not right that's someone's leg that someone leg someone's like so I think what we need to do is this there we go after this session please upload this video I'm not able to join this time because it's oh it's it's early in India yes absolutely I'll I'll keep this up on YouTube all right so we found that was painstakingly hard and I probably should have just thought about it more but I was able to convert the detected uh I don't know if you understood what was going on but oh we also want to invert this so we converted this from a float the bounding boxes were in floats but when we slice the and these are the pixel values within the image where it's detected the face uh face detection other object detection does this a lot right um so we're going to make it really cool we have we have six faces so fig axes uh we're gonna make a subplot of one by six oh this song is crazy we're gonna put it for index in how's it music level by the way all right so we are enumerating over the faces now we have an index location we can now take this axes and we can make sure it goes into the associated location um um forget if this like axis off yeah there we go all right there we go do you see how pretty that is when it finally works all right so what do we do so this detected faces from our image then we looped over each face detection we pulled out the bounding box of what it detected it wasn't afloat so it wasn't specifically exact pixels I don't know why it wouldn't do that because it's it's not like it knows anything more it may be because it does by percent of the height and width and it does the multiplication anyways we just converted that into integers then we sliced our images in order to plot them now they're not all exactly Square you can see when it does the detection sometimes it's um sometimes it's oval or rectangular sometimes it's Square um now let's see what they're doing so now they're taking oh this is cool this is cool what are they doing here sorted faces okay so all they're doing here is they're sorting by faces I think left to right because they're looking at the B box location of each so they're just kind of looking at this uh and I think this is just sorts swords left to right all right so let's let's call this face swapping face swapping time we have our faces now that it should be sorted yeah so if we look at like the B box zero um this is just gonna confirm what we're what this line of code does so if we run this above code now we have our faces which are not sorted and then I run this line of code which will just print the B box zero location which um I think is the left how far it is on the left of the image like how far to the left it is and if I print it beforehand I mean it is incrementing anyways so then when we do this it just it just keeps it the same I don't know I don't get it maybe because they want this to be reproducible and they want to make sure that for some reason it doesn't change uh music is low okay I can turn up a little bit it's kind of intense music all right so we got the faces we now we're gonna make we're swapping time so this this line doesn't really do anything so now we just take this image and They're copying this image like this makes sense if you keep in mind in Python all you new python programmers out there why why use dot copy here it's because when you assign a new uh variable name from something else like if we take the image and we're going to make it called res if we didn't add this copy and then we modified res like we we're going to pretty soon and swap the faces it would actually have modified the original image which wasn't wasn't our attention so where this is basically ensuring that we don't mess up the initial code all right they're just asserting that the it there are six faces which we know it's already true um then they're making the source face number two and if we take the source face and we plot it we can confirm what it is so this is the source face which is Ross right isn't that Ross correct me if I'm wrong all you friends fans out there uh that's something for a silly amount of time yeah it's a good thing to learn at first especially when you're working with things like numpy arrays pandas data frames a lot of data intensive stuff you think if you're a newbie you think oh I can just make something else equal to this and then now I have a new thing to work with so it's not true unless you make a copy and by default yeah this will return a copy of the array Okay so whoa this this music is all right so we're gonna take Ross's face and we're going to swap it out with everyone else's face so for each face in the face swapper or sorry for each face in this image we're going to use the swapper to get that face and swap it with the source face let's look at the documentation there's no doc string for this but we can look in the code made for in swapper well this is intense music okay so swapper get so there should be a get method get method in here man I can't complain that they didn't write a doc string because I don't write doc strings a lot but um so they're doing this normalized crop not sure what this does come on GitHub I don't want all this stuff uh reshaping it um this is where they get the embedding of the face whoa changing the dot product of the latent space divide the latent session run image fake it almost be interesting to see exactly what's going on in each of these all right so if Pace back equals true equals false then it will just return this otherwise it does a lot of stuff gaussian blur wow yeah I mean I don't know what's going on there that's why this has so many likes on GitHub okay so we are doing face back equals true and let's see all right after swapper dot get this is our results we're gonna show this all right we want to do this oh it's already looking hilarious um all right so it looks like they're all swapped right they're all Ross they have been swapped and it's surprisingly good that is that is actually really impressive it's got the smiles still but it has it it has his face for sure it has like his facial features I am very impressed by this but then what is it doing here it's writing it and then I don't understand what this version does so now they're making a second version of the swapped and we can see how this works so this is swapping one by one and then concatenating the results by the way is this running on the GPU that's just OBS using it so I don't know if it's running on my CPU Maybe all right so let's show this second version okay so this is just showing that this is just uh paste back pays back just Returns the face that detected so this is just for them to show that example of the faces being swapped put your face on it you were one step ahead of me sir let's do it let's put my face on it uh so how do we want to do this we can use CV2 here here's the here's the simple way to do it let's just do this this is me uh I gotta take my glasses off to make it more fair I'm going to take a smile I can't really see my screen right now uh go to screenshot gonna select look at the camera all right now go back to this you can see my screenshot of myself I'm going to save it to my desktop and then I'm going to move it now I gotta put my glasses on so I can see man it sucks getting old I'm gonna go to here I'm gonna move from my desktop uh screenshot here and now if I go to uh uh CV2 I am read all right let's also delete this stuff below it because that was just the example code put my face on it I'm gonna read I'm going to read this file um screenshot I'm going to call this Rob right so we're going to do this and that's a picture of me it's got the chat even in it no it's got the other stuff uh time to do it Rob's gonna rob their face yeah you get ready get robbed get ready to get robbed so what do we do here what do we do to face swap me onto the friends faces we first need to detect my face so first we're gonna detect and save my face so my face oh my beddings are going to be on Rob faces Rob bases should just have a length of one we could make this a cert that it's only one face for me right so then just like they they created this Source face it's just going to be Rob face um so if I if I plot Rob face this is what it's going to look like so I'm gonna make this Rob face Rob face equals Rob faces I know this seems kind of weird but it's just because there could have been multiple faces I could wait no wait no no no no no no no oh yeah that's because I'm showing it I'm not showing it on my face there we go there's that guy we all see him what if it detects Small Faces in chat that would be impressive that would be impressive all right so my face is there now what do we do I mean it's pretty simple we just do this swap the faces all right so now oh sorry it's not that simple number two we're gonna detect the friends faces again just to have this complete uh we need to run this right now we have the friends faces and then we're going to uh swap my face for theirs on the image so then what we need to do first is make res as the image and remember we're gonna do copy here right because copy helps and we're going to Loop through their faces and we're gonna get their face and replace it with Rob face back is true and then we're gonna actually show it all right chat I you guys have a you guys have a um an assignment right now and that's to go find some good images out there for us to do face swap on all I'm asking of you whoa whoa he who's that Chandler yeah he uh he didn't change that much it looks a little bit chantillery but these are pretty good face swaps oh my goodness let's do this version of it let's do this version of it so if I delete this and then we do the same close up view all right so we're gonna do this it's going to concatenate the results and we're going to show all of these this one is like how did they get my mouth to open how are they getting these Expressions out of just a single shot view of my face now this one gotta admit is that Rachel it's not the best this this one's not the best like the forehead's kind of huge this one definitely looks like um like they phoned it in but I can't maybe you're just very chandlery yeah maybe maybe all right someone's requesting this oh this is great uh let's put this on my desktop too oh this is the AV f file I thought that looked too high quality what the what is it avif file hey by the way you guys have the new Google search with generative AI is anyone out there have that this or am I the only one Navy if file is an image file that use Avi image format it's like the chat gbt right in your search sometimes it's pretty bad though watch this write a function to mole multiple apply two numbers and subtract 3 subtract two all right so now it doesn't want to give me generative AI it just gives me results did they remove the code part of it maybe that's something they decided like python function add two numbers okay so they showed it here so this this works but I've seen some some results that are pretty bad from it yeah one of you weeks ago I use it sometimes when searching for a coding term nice yeah okay so we have this avif file that we want to convert to it let's just open this folder what's this going to open in let's export this export as jpeg now we've got it as a jpeg which I know opencv can handle man I'm really happy that person provided the Onyx file for this because otherwise we wouldn't have been able to do this thank you guy on Reddit um so swap with Monty Python all right we're gonna read in the jpeg version of it Monty we're gonna show it all right so this is existing one let's see if in a real world example it works that well how do you like the Google lab search results so far me personally I'm not impressed I'm just not used to it like even the font changes get to me it like confused me a little bit all right guys I finished my blue moon now it's time to go full summer white cloth then I'm done then I'm cutting myself off all right switching with Monty wait I already said that all right so we have that image we already have Rob face so now we basically just need to get the faces I could write functions for these we're just doing it quick and dirty so we're gonna take the Monty Python image get the faces from that oh let's assert that the link length of faces equals okay this is gonna be interesting because how many faces is it going to going to detect in this image there's actually one two three four five main faces but then we have like a face back here we have these little ones over here so we just kind of want to see what these faces look like so let's do this in a separate cell um so it detected the faces now if we look at the length of the faces there's nine so which nine did it decide to um to do let's uh let's do this code again let's do this code again which we wrote that can plot all the just the faces pre-swapped pre-swapped faces we're not going to do this because that's not our image and this is going to be it on the Monty image um and oh yeah our length of faces is nine it's not six so this needs to be nine and let's see okay so it detected the main faces that we care about it also detected this guy's face what are these These are these three three guys that's pretty impressive it found all the it found even these faces it it decided to ignore the Angels up high but I'll go with it well we can even try to swap our faces on like these five pixels back here I haven't had a white car ah Keenan says I haven't had a white claw in a while you should really you should really give it a try swallow your pride and enjoy it it's so it's summertime I mean if this was December and it was snowing outside I could not drink a white cloth but it's sunny till like eight o'clock it's warm outside granted it's nighttime now but you know I just you gotta do it all right so we're not gonna swap yeah now we're gonna swap faces so now we get the Monty Python faces we're gonna copy this here we're going to swap the faces Pace back and we're gonna show it should also time it and I should also make sure is it running on the GPU it's running on my CPU you see this there's got to be a way to make sure it runs on my GPU there we go pretty darn good it even deals with the beard it deals with the beard magnificent magnificently I can't speak it could have been better but hey yeah look at this it's got my mouth open in awe this is I mean that's fun face swapping people we're face swapping all right let's take two people who do not seem like they they would go together two people that don't go together and swap their faces any ideas we get I don't want to go political too political but we could like pick political rivals inside face is very strong they have a such difficult time fine tuning it to my data um what are you trying to do specifically I'm I'm interested to know Keenan try Tyrese and Emma stones I mean that's gonna be we that's gonna be weird I don't know is there some hiss like is there some is there some drama between those two or did you just pick people yeah the skin color difference is gonna be interesting Kanye and Taylor Swift uh I don't want to get too controversial here Kanye's been in the news for a lot of stuff I don't wanna delve into the territory um but let's do yeah I mean I don't really know Tyrese Gibson or MS stone for that matter the Kron look huh oh him versus Gary Marcus Mike Tyson and Brad Pitt that's a good one all right so Yawn is like very uh bullish I guess on like AI future is scary less so let's do this I know they're thought leader guys lecron both prominent figures field of artificial intelligence and made significant contributions however have different perspectives their areas all right so CNN's versus being critical of deep learning okay let's do it let's take the images from here uh let's just find this directory Insight face it says licensed image oh shoot I didn't know it does that when you download it makes me feel bad I don't want to download the full HTML no I don't want the full HTML I'm gonna call this Gary Lagoon I'm gonna call this okay how would we how would we swap two faces and retain the two images Forest Whitaker and Bruce Lee that's a good one or just yeah Spock and Obi-Wan oh that would be good back in college I had a friend who's really good I actually have a friend now who's really good at doing the face swap and like editing stuff that will be out hanging out and he'll take a picture of something we were just talking about and like paste my face on it and text it to a group chat chat yeah so I think we should make this into like a generic function but let's just make sure it works make it more wide than tall show the first image turn that axis off and then we'll do this same thing but to the second image and we'll show this that's right we need to when we show these invert the red green blue channels there we go so now we have image one and image two we're gonna swap these faces we're going to swap these faces by first detecting the two faces right so we need to take our we need to take our detector app to get face one let's just assume it's only going to find one face in these examples and we'll give it image one and image two that's gonna be our face one and phase two uh we won't worry about plotting them and all that stuff we're just going to go ahead and swap we're gonna make an image one underscore and an image to underscore with this will be where we swap the images so let's think about how we do this we take image one and we're gonna remove face one and we'll replace it with face two and then we're gonna do the opposite right we're gonna take image two take face two and swap it with face one and then we're gonna go ahead and do this plotting function again but with our underscores there we go there we go people we have successfully swapped two faces am hey Rob hey what's up am I like your username some of these names I don't recognize like MBA in Holland but I like the Spock in Obi One because they're two iconic people you know and that people get frustrated when you mix up if you're really into that thing so let's save this as Spock oh this is a web B image do like that image though so let's save Spock uh you're interested about the skin colors let's try that one too let's try that one too Obi-Wan Kenobi you're my only hope well this is like the young Obi One you want to go with the old Obi One feel like this is a fake Obi-Wan they have like no pictures of the oh gee all right we'll go with it I guess that's what people think of when they think of Obi-Wan these days all right so the problem here is that I'm gonna have to convert this web P image so there's some easy way to convert this online com webp to jpeg image converter uh uh repos repos stream projects no I clicked on the wrong one now it's trying to convert uh notebook which doesn't make sense okay here's the Spock one Spock upload let's go convert download Spock go back here to our code and now we're going to run it on Spock versus Obi One and we're going to make this into a function just to make it easier Swap and show we'll call it SWAT Swap and show image one file name image 2 file name so now we're gonna just move these out then we'll say like plot B4 and default that to true if plot before we'll do all this then we'll do the swap do the swap then we'll [Music] and then we'll if plot after is true we'll do this plotting and then we're going to return the images that have been swapped now there's one thing here this assumes that there's only one face in each image this function only works if there's one face please add doc string oh just for this quick function that we're writing okay uses face swapper to swap to image faces in two different images plot before if true shows the images before the swap lot after if true shows the images after this swap returns images with swapped faces assumes one face per image all right so Swap and show uh we're gonna do image one file name which is Obi-Wan image two file name which is Spock baby Spock baby and we're gonna show them oh man that's weird that is weird oh yeah and then we're also return this as underscore because we don't care about that I should also have it provide our app I mean because that wasn't created in this function and we should also provide it the swapper just to be just to be nice and I didn't talk about that in my doc string I apologize what is the library for face swapping read the title of the Stream not to be mean but I think it's in the title of the Stream it's called Insight face and it's uh open source library now it's not really open source weights because they decided to take those down but some guy in Reddit posted the model weights and thank you guy on Reddit we downloaded those and we were able to run the old cook yeah so here we are we swapped some faces now someone wants to do it with different complexions it would be interesting to see how it deals with the different complexions now before I do this I wanna I wanna just put this out there we're adults I hope we're adults you need you know if you're a kid turn this off but we're adults here we're mature We're not gonna like be immature about the fact that we're trying to swap faces with two people with different complexions we're just doing it as an experiment to see how the model performs okay I hope you add the link from our Reddit guy to YouTube post yes the other thing too is I now have that those models downloaded locally and I ain't deleting them I'm going to keep them I don't whose model this model even is it I don't know um okay uh I just realized you guys can't you guys can't seem let's see how it works alright so let's swap let's swap um I don't know I feel like it's bad territory but I feel bad if this guy uses his primary Google account isn't there a bandwidth limit on Google Drive now I mean I probably not probably but also there's not that many people um who are downloading this thing maybe there are um back in the day I had a podcast which I hosted on Dropbox before Google Drive existed in Dropbox it got popular enough that Dropbox eventually shut it down but it took them a few months it's like they never they never thought that I would host publicly like something like that can't can it swap animal faces yeah that might be well I don't think it's gonna detect an animal face because these models were trained to detect detect all right let's just call this swap faces try again yeah can you feel how uncomfortable I am um so who should we do Chris Tucker and oh yeah that's a good that's a good one that's a good one because those guys are in the same move movie together and Jackie Chan these are my guys these movies are hilarious um Rush Hour wow there's a fourth one and when I say these movies were hilarious I only know of the first one all right so this is a web p so we might have to modify our code to handle two people in the same in image so we'll do like a single image swap um let's open this directory oh yeah I'm gonna use our little swapper tool our webp to image converter let's go back to the main page of this Rush Hour upload I guess I could have just given it the URL choose file Rush Hour Rush Hour select upload there we go Jackie Chan Chris Tucker uh uh and this is Rush Hour um go into our code all right so we're gonna have to mod modify this Swap and show same image the same image found this channel for my YouTube video which hey welcome Masters student electrical engineering Computer Engineering I I got my masters in electrical engineering we're like two peas in a pod oh but you also did Computer Engineering and you're doing machine learning that's awesome what video did you watch that brought you here uh I still feel kind of uncomfortable about this okay so we're reading image one image one now we don't need to do this anymore if plop before we're just going to make this one by one and then this will just be the single axis we plot it in then we're gonna get the faces in here and then this is going to be face one and phase two equal faces zero and face faces one we copy the first image we're gonna swap face one with phase two phase two with phase one but we're gonna do it always on image one then we are going to plot this like that a little bit of this a little bit of that all right Rush Hour okay so this also needs the app and the swapper key error zero oh that's right because right here this isn't faces this is just a single face what it didn't didn't swap them so I did something wrong all right image one oh oh it's plotting the wrong one Swap and show same image okay like it's trying to it's trying to deal with it watching the video about cross validation nice if you're watching the video that doesn't didn't get a lot of views but I feel I'm very proud of I'm proud of that video yeah I don't know what to make of this it's kind of strange gotta be honest I this makes me uncomfortable I mean the same goes with like swapping yeah guys it goes hey Rob hey what's up Mr Gabriel how are you doing it really helped you I I'm glad cross validation one of the most important important things in machine learning came here from the cross validation video too nice let's see if cross validation video comes up if we Google it doesn't it's way down here but yeah this video I guess it's it's like a slow burn starting to get more views I guess but right after I released it like no one really liked it right away I guess this sort of thing you need to be learning about uh howdy what's up welcome to the chat um all right let's do one more swap feel like I can swap like my wife and I's face or something um top celebrity couples all right here's some celebrity couples can we swap their faces thanks for these videos thanks for watching subscribe tell a friend they'll tell another friend we really need to test the animal swap I'm fairly certain it's not gonna zero nine we could test it but I'm fairly certain that the face detection is just not gonna it's gonna say that's a cow it's not like a cow face uh image of a cow like if I save this please be a jpeg all right if I save this here cow and I do the test on cow it would be hilarious if it was like I guess that's what you could fine-tune the model on um but it would be hilarious if it could get animal faces so this is gonna be our cow right no way it finds a face on here so app app dot detect let's see what the function is that we detect app.get yeah it returns an empty list so just uh just to prove it to you I was wondering if crossed out validation is used when fine-tuning a model so I don't know it kind of depends like for a lot of the fine tuning of models you have like a base model that you know goes really well and then you're it's usually deep learning stuff where you have a lot of label data um but you could the thing about cross validation 2 is the larger your data set the less necessary it is because as long as you believe you can do splits that are representative of what your model will see worth the try yeah it was worth a try okay swap faces of celeb pretty couples let's take some images of celebrity couples this is going to be great who is this and I'm going to need some help because I don't know all these celebrity couples like who who are these people I wish the image name had their names in it I'm gonna call this couples one oh you gotta get wait Jennifer Lopez and and uh P Diddy had a thing uh it's a webp can I enforce that it's a jpeg oh yeah let's let's save this no it's webp gotta get their full face too who's Bieber with couples too would serve a great meme yeah I need to get a good one of um you need to get a good one of these two they're always kissing though these two are always kissing like do you think this is a good enough one to get a it's also definitely a webp yeah just start taking screenshots um what's that guy's name hi Rob big question I was thinking pursue MSC Ina because I like industry application instead of the cat academic world the thing is my teachers recommend me that's better apply for a PhD even if you want to dedicate my life to the industry what do you think about based on your experience I don't know I think that doing a PhD should be more about like you really want to do a PhD more than what you're worried about what comes after because you really have to devote your life to it what's going on here David J Jackson we're swapping faces look at this ah shoot I just closed the tab speaking of which let's let's do like a tablets here and delete all these tabs we're using this library to swap people's faces you can see here in the friends example everyone's gonna become a Ross in this example now they're all Rosses we took my face we put me on all the friends people there we go look at that look I even got my mouth open here we took Monty Python we dropped my face on all these guys actually really good result then we took these two guys who who disagree a lot on AI and theirs their faces swapped Obi-Wan and Spock we did the rush hour to see what the different in complexion would look like you kind of found a happy medium I guess I it did change like the whole face complexion which is which is interesting um we tried it on a cow and it didn't work and now we're trying to find celebrity couple images um there we go this is a good picture of them too please BJ bag yes all right this will be the last thing we do tonight foreign let's go for it we have these couple images and now that we wrote a function that should be pretty easy four four couple in couples we're gonna Swap and show each couple all right celeb couple guy from the office girl from other stuff there we go there we go I could make a whole blog post about this this could be like a like a viral trend the beard here it didn't do great with all right the probably the best looking couple of the whole thing oh my God that is disgusting I think the better looking you are when your face is swapped you then become the least best looking it's like there's a reason you look good that's because that face is on your body this is that the eyebrows are just killing me here all right uh Spider-Man and what's she from I don't know oh my gosh this one actually kind of works it kind of works it kind of works and uh Bieber and his celebrity girlfriend who I don't know the name of just because I'm not in the pop culture oh it looks like it always splits the difference and just decides to uh to keep the mustaches or the beard because we got a mustache kind of on both sides there we go are you entertained those are celebrity couple face swap um I think someone asked that I make this video public I will afterwards so thank you all for hanging out tonight hope you had fun let me know in the chat if you enjoyed this and the cow swap didn't work cow swap didn't work it did it needs to be a human face it would be hilarious if I could take a kaggle of geese and put my face on that but I don't think that would look that would work looking forward to YouTube post so the YouTube post goes up immediately it's just gonna be this video so just check it out thanks for the videos on YouTube I appreciate it yeah I hope you guys had fun I had fun with you put a big fat F in chat for fun uh I'm gonna also promote some things so youtube.com Rob Mulla will bring you to my YouTube page if you're not already subscribed you should be I'm going to show you it right there exclamation point Discord will bring you to a link and I'm going to paste this for you guys in uh in YouTube That's the link to our Discord that you can join and it's uh for people who are interested in data science so definitely subscribe on YouTube do that thanks um and then we got me on mullah not uh on Twitter not Super Active but yeah you should definitely join the Discord um and I think that's it we're not running a kaggle competition right now but it that's it alright so um with that we'll find someone on Twitch to raid Chrissy code star coder coding with strangers uh I love coding with strangers I feel like we raided him next last time Christy's not always online uh but is she doing is she doing non-python development says python but that's definitely not python code all right coding with strangers please read coding in Python he is my guy listen to his stories listen to his stories he's got good ones I think that's JavaScript yeah I think you're right all right so we're rating coding with strangers let them know that you came from here and that you're ready to party let's go ahead and get the ray going on all right thanks everyone for hanging out tonight have a good one I'll see you next time be kind to each other and have fun learning bye bye and Goodbye YouTube people
Info
Channel: Rob Mulla
Views: 2,922
Rating: undefined out of 5
Keywords:
Id: Qzj6Gq_NeTw
Channel Id: undefined
Length: 107min 35sec (6455 seconds)
Published: Wed Jun 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.