XAI: A model to explain StyleGANs

Bart Teharomany from Eindhoven University explains how to interpret StyleGANs, the neural networks that generate realistic faces. He walks through generative adversarial networks, active shape models, and principal component analysis to show what these systems actually learn.
Chapters
Good morning or good afternoon, wherever you are. This is a talk about explainable AI, a model to explain style guns. And my name is Bart Teharomany from Eindhoven University in the Netherlands. I go talk about the faces that you see here. Gun generated faces in a. Yeah. To try to explain a little bit of the black box that we see in AI and what are style guns? Well, the classical movie by the Nvidia Corporation, Guy Terokaras showed some style change effects. And I have the movie here for you. Let's first see what these style changes are. There were sliders and you see, you could nicely change all kinds of features, even go from female to male and back. And how can we explain this? What happens? Well, that's what I like to discuss in this presentation. So we first go look a little bit. What are style guns and stutter at all. What happens there? It's a fighting between two the deep neural networks. And I give a computational essay to propose a little bit what might happen. I had a whole career in biomedical image analysis, mainly focused on the medical area. So Computer Aided Diagnosis. I recently begun to write a little bit about my career and I wrote a Mathematica book which was. Yeah, covering my live work on brain inspired computing. That's the best recognition system we can get. So can you mimic that and put this in Computer Aided Diagnosis techniques? It was nice to have a lot of students around me and I did a lot of teaching. I was with mathematica since version 1 and teaching I did for decades, always Mathematica. And Marcus van Amtrik was for eight years in my group, did his PhD also. Matijan Fruling was in my class and it was really nice to have collaboration with so many students. What are these generative adversarial networks? Well, they consist of a generator and a discriminator. And the generator generates a random vector and it generates something which might be right, but it is compared with something, a real sample. And the discriminator is updated until it says, yeah, this may be right. And if there's a loss, the generator and the discriminator will be updated. Well, this has been. And here you see, Let me load this image again. You see that if you go from a coarse resolution and you take a longer training time, you can get a higher resolution. But the training time is quite substantial. If you really go to 1000 square, you see that the training time may go up to 12 to 13 days at least. So if you go, let's say up to 82, what do you get? You get the pose, the general hairstyle, the face shape, you go to middle resolutions, you see, find the facial features, hairstyles, eyes open, etc. And the fine scale to really high resolution. But we look at the coarse scale today and we're going to focus on the pose only for faces and see if we can see the relation between this explainable computer vision and the learned internal. The internal, learned interpretation. I see small mistake and I go explain, try to explain this with active shape and appearance models. That means we need to represent this learned pose. And style and shape variations are typically described in computer vision by what's called an active shape model. That means key points. Variations of the objects in the training set are determined by principal component analysis. We can not only do principal components analysis on these key points, we can also do this and then it's called active appearance bubbles on sets of pixels, pixel intensities, and then we can look at texture variations. So what I'm going to do first I need a lot of faces and we're going to generate them from this website. This person does not exist and you know this website. Each time you refresh the website you get a new face. And this is easily used in harvesting images with Mathematica. Then we go do the active shape model, but some of the faces are not right. Some faces have sunglasses or they have glasses. So we write a small discriminator to discriminate them in glasses. No glasses and sunglasses. And then we go on the active appearance models and finally we're going to see, can we use them also to do the style, pose and face changes with these active shape models and active appearance models. Well, the generation of the GUN phase database is very easy. You do an import of this image and you ask just for the image. If I do it nine times, you get this small image collage. Actually I did it for 10,000 images. I actually have, I think now about 100,000 images. And it's really nice to work with it. So if I show how they look like, this took two hours to fill 10,000 images. So it's very reasonable and it's a very efficient way to get an enormous database of different faces. Okay. Having these faces, if you don't want to do all the loading yourself, just download these archives and you get all the images on your laptop or computer. Well, first we're going to look at the extraction of the key points. And what we do is we load a neural network, it's network with quite some RESNET features in it. And it's from the Wolfram repository. And what this network does is that it generates heat maps. And let me first show you these heat maps. It finds 68 landmarks on the image. And what it gives back is the probability of the location of this landmark. So here you see the first one, the second one, etc. So here we have the 468. But this probability is not really pixel accurate. It's a probability. So let's have a look at this small probability map. And what we see is actually quite surprising. It's almost without any noise. That means what we could do is find the center of gravity by just totaling. And now we get the subpixel position. If we do this now for different key points at different groups because they have some order, then we say, okay, now it's very easy to find from this space the eyebrows, the nose, the mouth, et cetera. So we have now 68 well defined key points on the image. And you can of course do this for all the images. And if you do this for the first, you see how nicely they describe in a certain sense the pose, the relation between the features in the face. Well, if you have that, and let's have a look at the particular face, let's look at this face. It turns out that if you rotate the image, the key points do not rotate with it. So suppose I rotate the image here 180 degrees, you see that, you get a mess. Why is this? It has never been trained for faces that are upside down because they, they don't occur. Here you see that it becomes reasonable, but upside down it doesn't work. So this is not a rotation invariant property we could look a little bit on. How do these faces that we generate, these are quite random faces. How do they look? Left or right? So I defined a pose angle. It's actually the distance between the tip of the nose and the most left and the most right. You can define it to some. Yeah, let's say angle of which the person is looking. If you make a histogram of all these angles, you see, okay, zero is in looking straightforward and it's looking a little bit more to the right than they are looking to the left. So it's easy to write a small manipulate that go through thumbnails. And if I go in this direction, you see, it's, it's very nicely to see. I take a random selection from these faces and you see how they indeed change the pose from looking all the way from this side, all the way to that side. And what I really like is that everything That I almost do is a one liner. Okay, then we want to look at. Can we say something about the age? We download the age. Net. I already did this before because it takes quite some time to do this for all the thousand images. And here we see a small data set. And you see from this image I could nicely find ages 50, female, 20. And I have now a nice data set which is extended not only with the faces, but I have the age and I have the gender. If I make a paired histogram and you look at the different cases, all this code is available in the handout. You see the nice distribution of in this case the women and the men. It's interesting that we had a little bit more younger women in this set than younger men. Okay, if we look at the oldest and the youngest and the oldest, nine and seven. And if you look at a random sample of each. I have now here I just import a random choice and I look at a certain age and here you see what type of face was generated by this gum, 9 years old, 10 years old, etc. And you see all the different faces coming up. And this is the oldest one, 67. So we have a nice cross section of the population in our data set. But the problem is we have also people with glasses, as you see here. Sorry. And we need a little bit classification and of course we can use classify. And I thought, well, why not try it and write a small modified Lynette. That's the simplest neural network that exists. It only has a very few layers and let's see how well it does. So we have the network here, convolution layer, ramp pooling layer and that goes a couple of times. And the only thing we have to do is that we change the outputs net decoder into a range of three classes and and the input encoder into an input image. And we just feed it a thumbnail, a color thumbnail. So this defines our network. It is uninitialized and it's really small as you see. And we just have to train it for these red indicated layers. I made a training set by hand. I took out several dozens of glasses and sunglasses. I put them in this data set. Is it running? Yes. I have target device on my GPU. I have a regular Windows 11 laptop with Nvidia GPU. I think I have 1900 cores. It's reasonably workable that this is quite fast. And you see this network designed to recognize digits can also easily work for recognizing in this case, glasses and sunglasses. And it does a reasonable job See, we get errors that are really nice. And if I try the images. Oh, it is already done. And I take a random set. You see that this data set function is really nice. You see, this has glasses. No glasses. Glasses. And we have a very nice classifier here. I did this for all the images. And now you see, these are all the images that I found automatically. They have glasses. And of course, I have the same set for sunglasses. Well, it was also nice. Can I find which face looks best like me? And all these things is. This is what I mean with playing with. And that's exactly what you can do. So nice in Mathematica. So you just say, let's make an element feature vector from this image. And this network does that. Let's see, from this particular face. Yes. It gives me a vector of 2048. And what's the closest match? I already calculated this. And this is the closest match that was from this 10,000 images. And it's. It's not too bad. It gives the same glasses and the same shape of the face. So that was kind of curious. Okay, let's talk active shape models. An active shape model is based on principal component analysis. And we all know principal component analysis is. It's one of the most used techniques for redundancy reduction or dimension reduction. And it finds in data sets the natural axis of least variability. And it's a nice animation to show this least variability. Here I have a set of points. And in these points, you see, I have the. This is the standard deviation in the two directions of how it was generated. And if I show you the projection, the red points are the projection of the points to the rotating line. You see that they have a minimal variance here and a maximum variance there. And these are the principal axis from this data set. So you rotate the data set until you have the natural axis. It's really nice in Q2. Show that in Mathematica. And the elegant thing is that you have the projection operator here. Well, if I import all the key points and these key points are pairs of numbers, I can flatten them into 1000 long column vectors. And you see, I have now a matrix of 1,000 vectors that are 138 long. Because at 68 of these key points in these pairs, so if I look at how are these key points distributed? And if I take the mean of of all these position factors, this is the mean pose the mean phase from all these 1000 faces that I put as input. I take the covariance matrix from these data, I get the square matrix And I calculate the eigenvectors and eigenvalues. So it's extremely easy to do this. The eigenvectors are 136. I have 136 eigenvectors are 136 long and 136 eigenvalues. Well, let's have a look at how these eigenvectors. And of course, These eigenvectors are 138. I have to chop them up again. So I do a partition here in two. So these vectors, I make them into groups, and that means I have a group of two. That means they are coordinates again. And now I can see what is the first eigenmodes from these points. This is the first eigenmode. And you see, okay, the main variation in this set is looking from left to right. It's more or less expected. The second eigenmode is this one. And you see what I do. I have the mean here plus W, the first eigenmode. And W is changed in my manipulate. So I Change W from 0.3 to. From. From minus 3 to 0.3. So the mean plus or minus the first eigenMode, second eigenMode gives me a change. You see, the second eigenMode keep me looking up and down. The third eigenMode is already a little bit more face shape here. You see, I have a quite a lot of shape changes in the mouth. So all these eigenmodes, they represent in order. This is the biggest that has the most influence. It has the highest eigenvalue, give different variations. And 10 is a more exotic one. You see, this is more to make with facial changes in the eyebrows. So that's called the eigenmode representation. And if I now show the. It was a locator and I just move the locator from left to right. I can now go a little bit further. And the interesting part is that I can go really much further than what was in my data. I can extrapolate. You see, it's quite nice that the nose and the occlusion that takes place in the nose can be represented by this data set. So in the data set is only faces that look, we saw that before left and right like this. But if you continue, you can go even to occluding areas, so you can extrapolate all the eigenvalues they describe. It's interesting if we look at the eigenvalues and we can already see that if we take the first 10 eigenmodes, and we add the first 10 eigenmodes here, relative to all the eigenmodes, we already get 96% of everything is described. So I only need a very few set of eigenmodes to describe most of my variations. And this is crucial. This means the representation is so efficient and it's highly likely that the brain uses this at lots of places to have a very efficient representation. And that representation learning is very much based on just this. It boils down to the, the internal representation of what this PCA is actually doing. It's also represented to a Taylor expansion that you only need. It's a very fast decreasing set of derivatives and that is described with this very small set of eigenvalues. If we plot the eigenvalues, it's called a so called scree plot, you see the very fast decrease of the eigenvalues. And with all eigenvalues higher than 10, you can easily discard because the addition to the representation is negligible. So let's have a look at the. For all, only the faces that really look forward. So this phi, the angle that I presented between these, these, these key points are limited between minus 0.2 and plus 2. So I have now more or less faces that look forward because I can now pick out pixels. That means the faces have to be more or less the same. So I'm going to warp the faces in such a way that they all look more or less forward. And I start with a set that's reasonably forward looking, 461 of these faces. So now I have the faces that only look forward. And you see that I have the first eigenmode is no longer left and right looking because I took that out and now I get this as a change. This is the second eigenmode. And it's very easy. You see, this is a very short piece of code to study. What are these eigenmodes actually doing? I looked at all these eigenmodes and you see the interpretation. Cervical flexion camera motion up and down. Four is smiling. So let's look at four and you see that there's a quite big change in the mouth. So all of these have representations in our eigenmodes. If I want to warp the images to a normal image, a mean image, I need a warping technique. And it's pretty well known, it's done by radial basis interpolation technique. Marcus van Object wrote a very nice demonstration, a dynamic module in which he used the radial basis transform. And you see how short it Is it is using the image transformation, but then in particular use the radial basis transform. And in our case we use the R log R radial representation around each point. It's called thin plate splines. And what it does on an image like this, you can move these particular points and you get immediately the deformation, but the deformation is interpolated between all the other points. So you can now easily let her or him smile. And it's quite nice to see how fast Mathematica can do this. So I had a small test. If you take a grid and you have coordinate lines, you want to see how does it move. If all the red points are moved to the green points, you get a. These points are random. So I do now a random representation. And of course later I go do this for the 68 points in our faces. I already did this. And it's very nice to use the parallelize. If you want to make a movie and generate each frame of the movie. I import the movie here. And now you see that I have a very nice representation of the image. And come on. And you see the local coordinates actually changing. And that's exactly what I'm going to force on the image. So if I take an image here and I import this particular image, I have the key points on the image with highlight image. And now I import all these particular key points and I have now the mean and I'm going to deform this face to the mean. So how much should I deform? Well, that is the shift that just targets minus the forces. And here I generate a movie. It was already done. Now you see here, this is what I could do. And now you see how this particular face is moved to the standard face looking forwards. And I of course do this for all the 1000 images and have done the whole 1000 deformed images. If I take this particular area and what I do here is here I have all the images that are deformed to this face. And sometimes you see it goes a little bit wrong. If the face was not particular looking straightforward, you see, it's sometimes a little bit artificial here the head is not exactly as it should be, but it's more or less reasonable. I have a lot of faces the same. I go estimate a particular piece of image with a manipulate. You can just say, okay, let's take this, this particular part. I take the eyes and I did this already for the 1000 images and I make the mean of these eyes and this is now the mean of all these pixel values of the eyes. I do PCA again, that means I subtract the mean, I flatten the sets of pixels into set. So this is quite a lot of pixels into one big column vector. I calculate the covariance matrix and I calculate the eigenvectors and I show these particular eigen eyes, as you call it, that are here. And these are the eigen eye images that I get from this particular area. If you look at the first eigenmodes, you want to make it variable. So what I do again I take the mu, the mean close lambda1, the first eigenvalue, lambda1, the second eigenvalue and put this in and manipulate. You can easily see. Okay, this is what we can do. And this changes the overall intensity. This changes the lighting position. But this is nice, this changes the eye position. So you see, we have the variation in the data can not only be according to the shape, but also to the appearance. And if you go a little step further and we look at the whole image, I took now all the faces. So what I do here I take the images with no glasses that more or less look forward. So I define this forward looking angle, select them and then do principal component analysis again from all these. So this is the mean phase. And now I'm going to do principal component analysis again on these big images. Well, this is quite a long calculation because the first eigenvector is quite long. If you make this whole image into one big column vector. The covariance matrix was over 150 million entries and it took 93 seconds. I won't do it. Given the time. I have two minutes left. I'll import the result and I show you the first 25 eigenfaces. Here we have the eigenfaces and you already see that there are all kinds of shading variations, etc. So. Let's now manipulate this array and see what happens if, if I now change the eigenfaces from and this is the 23rd eigenvalue, I, I could take all kinds of other vectors, but this changes the sex, this changes from a girl to a boy, another one changes the hairstyle, et cetera. So I think this might give a pretty intuitive explanation of what these style guns actually internally represent. So if I take random eigenmodes and I take this from what happens if you take this randomly? And that's exactly what this phase generator on the website is doing. It generates all kind of faces. This could be more elaborate if you take higher resolution and more eigenvalues. But you see we have male, female, we have light hair, we have dark hair. So all these representations are in there. So I have not much time left. The main conclusion is that deep learning and possibly brain learning, is representation learning. And I've shown hope to have shown that PCA is very elegant way to see what these systems in this particular case are doing. And I'm extremely pleased with Mathematica for designing and playing with concepts. Like I showed you today, that was the purpose of today as a user. I want to give you just one example. There's a whole book coming up. I wrote the earlier book, but there's a new book coming up that describes much more of these explainable AI pieces for neural networks. So this ends my talk, and thank you very much. I go have a look if there are for. I will answer the Q and A later on. Thank you very much.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






