Convolutional neural networks (CNNs) are powerful tools for image classification and object detection, but they can also be used to generate images. There are myriad image generation tasks and applications, ranging from generating potential mass lesions in radiology scans to creating landscapes or artistic scenes. In our project, we address the problem of generating faces based on certain desired facial characteristics. Potential facial characteristics fall within the general categories of raw attributes (e.g., big nose, brown hair, etc.), ethnicity (e.g., white, black, Indian), and accessories (e.g. sunglasses, hat, etc.). The problem can be stated as follows: Given a set of facial attributes as input, produce an image of a well-formed face as output that contains these characteristics.
In our face generation system, we fine-tune a CNN pre-trained on faces to create a classification system for facial characteristics. We employ a novel technique that models distributions of feature activations within the CNN as a customized Gaussian mixture model. We then perform feature inversion using the relevant features identified by this model. The primary advantage of our implementation is that it does not require any deep learning architectures apart from a CNN whereas other generative approaches do. Our face generation system has many potential uses, including identifying suspects in law enforcement settings as well as in other more generic generative settings.
2 Related Work
Work surrounding generative models for deep learning has mostly been in developing graphical models, autoencoder frameworks, and more recently, generative recurrent neural networks (RNNs). Specific graphical models that have been used to learn generative models of data are Restricted Boltzmann Machines (RBMs), an undirected graphical model with connected stochastic visible and stochastic hidden units, and their generalizations, such as Gaussian RBMs. Srivastava and Salakhutdinov use these basic RBMs to create a Deep Boltzmann Machine (DBM), a multimodal model that learns a probability density over the space of multimodal inputs and can be effectively used for information retrieval and classification tasks. Similar work done by Salakhutdinov and Hinton shows how the learning of a high capacity DBM with multiple hidden layers and millions of parameters can be made more efficient with a layer-by-layer ”pre-training” phase that allows for more reasonable weight initializations by incorporating a bottom-up pass . In his thesis, Salakhutdinov also adds to this learning algorithm by incorporating a top-down feedback pass as well as a bottom-up pass, which allows DBMs to better propagate uncertainty about ambiguous inputs .
Other generative approaches involve using autoencoders. The first ideas regarding the probabilistic interpretation of autoencoders were proposed by Ranzato et al.; a more formal interpretation was given by Vincent, who described denoising autoencoders (DAEs) . A DAE takes an input
and first maps it, with an encoder, to a hidden representationthrough some mapping, , where is a non-linearity such as a sigmoid. The latent representation is then mapped back via a decoder into a reconstruction of the same shape as , i.e. . The parameters, , , , and are learned such that the average reconstruction loss between and is minimized . Bengio et al. show an alternate form of the DAE: given some observed input and corrupted input , where has been corrupted based on a conditional distribution
, we train the DAE to estimate the reverse conditional. With this formulation, Vincent et al. construct a deeper network of stacked DAEs to learn useful representations of the inputs .
An alternate model has been posited by Gregor et al., who propose using a recurrent neural network architecture to generate digits. This architecture is a type of variational autoencoder, a recent advanced model that bridges deep learning and variational inference, since it is comprised of an encoder RNN that compresses the real images during training and a decoder RNN that reconstitutes images after receiving codes .
Finally, another approach for estimating generative models is via generative adversarial nets  . In this framework, two models are simultaneously trained: a generative model that captures the distribution of the data and a discriminative model that estimates the probability that a sample came from the training data rather than . is trained to maximize the probability that makes a mistake.
Our workflow consists of two steps. Firstly, we finetune a pre-trained model to classify facial and image characteristics for an input image. Secondly, we generate faces given some description. We describe our approach for each step in the forthcoming sections.
To facilitate the discussion of our methods, we introduce some notation. Let denote our set of training images, and let denote the set of 73 facial attributes. From this point forward, we use the word attribute to refer strictly to one of the 73 facial characteristics in our system.
For finetuning, we employ the VGG-Face net, a 16-layer CNN that was trained on 2 million celebrity faces and evaluated on faces from the Labeled Faces in the Wild and YouTube faces datasets . Using the VGG-Face net as our base architecture, we then attach
heads to the end of the fc-7 layer of the VGG-Face net, each of which consists of a fully connected fc-8 layer and a softmax layer. Each softmax head is a multilabel classifier for a group of attributes that are highly correlated. For example, one group of attributes includes hair color (black, gray, brown, and blond); in general, someone usually only has one color of hair, which makes grouping these particular attributes together as one multilabel classification reasonable. Furthermore, grouping together highly correlated attributes for our classification task in lieu of having binary classifiers provides the network with implicit information on the relationship between grouped features.
During training, we freeze certain layers in the CNN and learn the weights and biases on the unfrozen layers. To determine which layers to freeze, we run several experiments with different sets of frozen layers and choose the set with the optimal performance. We describe the experiments to assess our architecture and the results of the fine-tuning in Section 5.
3.3.1 Baseline Approach
We begin the generation phase of our project with a simple baseline approach that uses class visualization. This approach begins with the mean image , which is the pixel-wise and channel-wise mean of all images in our training set. We add small Gaussian noise to and use this image as our input to our baseline algorithm. Suppose we wish to produce a face with a set of attributes . In each iteration of our algorithm, we do the following:
Perform a forward pass with as input;
Set the gradients at each softmax layer to either 1 or 0, depending on our target attributes ;
Perform a backward pass through the network with these gradients;
using stochastic gradient descent (SGD) and regularization.
This baseline serves primarily to demonstrate that our CNN correctly represents important facial structures such as eyes, noses, mouths, etc., even after fine-tuning on specific facial attributes. This approach is not comprehensive enough because boosting certain features from the last layer in the network does not limit the number of facial structures that appear in the image. A more complete discussion of the results of the baseline approach can be found in the Section 5,6.
Our next and final approach uses a customized variant of a Gaussian Mixture Model (GMM). We opt for this technique over more traditional generative approaches discussed in Section 2 for two main reasons. Firstly, to our knowledge, this method is novel and has not been used in context of image generation using CNNs. Secondly, this approach does not require complex structures in addition to our existing CNN, so the model is simpler and has far fewer parameters to train.
3.3.2 Custom Gaussian Mixture Model
This approach behaves similarly to the baseline in that we begin with an input image that consists of random noise and boost this image toward a set of attributes . The primary difference is that instead of class visualization, we use feature inversion with respect to a layer in the CNN. We also begin with random noise instead of the mean image.
Intuitively, feature inversion tries to minimize the difference in the activations of an input image and some target activations in a certain layer of the CNN. These target activations are the activations that we believe an input image with the desired attributes will have when passed through the CNN.
More formally, Let be the activations at layer when an image is passed through the CNN. Let denote the target activations for layer and suppose we have a way of determining from . We wish to find an image by solving the optimization problem
where is the squared Euclidean norm and is a regularizer such as blurring and/or jitter. Given and , feature inversion does the following:
Perform a forward pass with as input up to layer ;
Set the gradients at by taking the gradient of the objective function above with respect to the activations in layer ;
Perform a backward pass from with these gradients;
Update using SGD and regularization.
The challenge of this approach is determining an appropriate set of target activations given . To our knowledge, there is no established way to automatically detect these target activations given solely the desired facial attributes.
To address this problem, we introduce a custom Gaussian Mixture Model (cGMM), in which we model the distribution of for a given attribute
as a multivariate Gaussian distribution. For each
, we estimate the mean and covariance matrix of its Gaussian by sampling images in our training set that are positive examples for this attribute. For computational simplicity, we assume the covariance matrix for each distribution is diagonal. This assumption implies that we effectively treat each multivariate Gaussian as a stacking of many independent Gaussians that model the distribution of activations for a single neuron in.
Specifically, for each attribute , we select 73 random sets of images of equal size such that for each , every image in has attribute . Then for each
, we compute a mean vectorand covariance matrix based on the activations at layer of the images in . These mean vectors and covariance matrices define 73 independent multivariate Gaussian distributions.
Thus, according to our model, if we wish to produce possible activations at of an image that has attribute and no other , we can simply sample from . More generally, we can estimate the target activations for a set of attributes by performing a weighted sum of samples from the Gaussians, which we assume to be independent. If we wish to estimate the target activations at for a subset of attributes, we would produce a sample given by
where if and 0 otherwise, is the weight assigned to the th Gaussian, and
is a random variable. Thiscan be used in place of for feature inversion.
Now we must determine the weights vector . In our approach, we learn this weights vector by trying to find weights that minimize the difference between the target activations produced by the sampling method above and the actual activations for images. We wish to find these weights by solving the optimization problem
and indicates whether , the attribute set for image . We learn the weights by taking derivatives of this objective function with respect to and iteratively updating using SGD.
4 Datasets and Features
We are currently using the PubFig dataset , which is a collection of faces from public photos of 200 individuals. The dataset includes 58K images scraped from various sources on the Internet, and bounding boxes around the face for each of these images. However, to avoid copyright issues, the authors provide links to the images, instead of hosting the images themselves. We have roughly images in our training set and images in our test set. The missing images include those that do not exist at the given links, those that have changed and a few that had incorrect bounding boxes for the faces.
Since these images are scraped from public photographs, there are several variations in faces. Most faces are frontal, while some are at slight angles. There is also a wide spectrum of lighting conditions in the dataset.
For each image in the dataset, we also have a list of 73 attributes including gender, eye color, face shape and ethnicity. Many of these attributes are interdependent. For example, only one of the attributes within black hair, blond hair and brown hair is positively labeled for each individual.
5 Experiments & Analysis
5.1 Finetuning Experiments
To understand the data better, we first run some experiments to find out what the distribution of our data looks like. For each image, we are given information about the presence or absence of 73 attributes. In Figure 7
we see that the distribution is quite skewed towards certain attributes. For example, aroundof the people in the dataset are white, while only are black. The number of people of other ethnicities is even lower, so a large portion of the images do not have any ethnicity labeling. Another prime example of such a disparity is eyewear. Around of the people in the dataset have no form of eyewear in the photos. As another example of the incompleteness of our dataset, only of the people have age information associated with their faces. These numbers give us a good idea of the limits of the system we are building and how certain attributes might generate better faces than others.
As mentioned in Section 3.2, we use the VGG-Face net as our base for finetuning. Before training the network, we perform some analysis to support the validity of VGG-Face net as our base architecture. Specifically, we perform a forward pass for a set of images from our dataset and obtain activations at the fc-7 layer. We then transform the space of these activations into two dimensions using t-SNE. As evidenced by Figure 3
(a), we see clustering even when using the weights directly from VGG-Face net. This gives us confidence that the network is a good candidate for transfer learning. However, clustering does not occur for all of the attributes, as seen in Figure3(b). This is also expected, since the VGG-Face net learned attributes that were important in distinguishing celebrity faces from each other, and certain attributes like soft-lighting
may not provide the discriminatory power to do so. After looking at the overall results across the attributes, we decided that we need to backpropagate our gradients into at least some of the layers in the network.
Next, we tune hyperparameters to get the best results from transfer learning. We try a wide range of learning rates, diagnosing the learning process by looking at the loss curve. We also try various configurations of freezing layers in the network. As we can see from Figure4, backpropagating into more layers in the network helps the learning process, but the final loss is very similar across all trials. We also try different learning rates for the layers based on their distance to the heads. Results were similar to the previous trials, with the network converging to more or less the same loss.
5.2 Image Generation Experiments
We first run several experiments using our baseline class visualization approach. For our primary experiment, we attempt to boost several features that vary in frequency of appearance in our dataset, including black (ethnicity) and black hair, for which there are fewer images, and middle-aged, smiling, and male, for which the frequency of images is much higher. A resultant image of this experiment is shown in Figure 5. We see that the final image has multiple facial structures, i.e. multiple sets of noses, eyes, eyebrows, etc. However, the image also contains some semblance of black hair and a facial structure that is more masculine. Our baseline demonstrates that the trained CNN has learned what these general structures in the images look like.
Because class visualization seems to boost any part of the image whose activations are close to the desired features, we shift our approach to feature inversion. For some image with desired attributes, there exist corresponding activations at an arbitrary layer that we can use to generate the image. To sanity check this idea, we perform an experiment where we use the ground truth activations at a convolutional layer for a Barack Obama image and attempt to reconstruct Obama using these activations. We obtain these activations by performing a forward pass on the image and stopping at the desired convolutional layer. The resultant Barack Obama image is shown in Figure 5. This result shows that the feature inversion method is a reasonable approach as long as we have access to the ”target” activations of an image with selected attributes. As described in our methods, we use a cGMM to estimate these target activations.
To justify modeling each attribute by an independent multivariate Gaussian, we take the images in set for label and for each image, plot a single element of the activation at the fc-6 layer. We then plot the distribution of that particular element in the activation across all the images for that label . Looking at two distributions representing two elements of the fc-6 activation in Figure 6
, we see that the distributions are reasonably close to a normal distribution. In general, after plotting distributions for each element across a sample of images for an arbitrary label, any arbitrary distribution of elementof the fc-6 activation for label seems to be normal (not all graphs are shown). Thus, because we have some confidence that the true distribution of the target activations is Gaussian, we can proceed with our cGMM formulation.
Now, we perform experiments to learn the weights in our cGMM. The forward and backward passes of are written from scratch, so we use numerical gradient checking to validate the analytic gradients. To choose the learning rate and regularization parameters, we start by arbitrarily setting the learning rate and regularization parameter to 1e-6 and 1e-5, respectively. Then, we incrementally reduce the learning rate until the loss starts to decrease instead of diverging to infinity. Finally, we use the trained model to generate several faces of differing attributes.
|training set||test set|
Our final training parameters for the finetuning are 5e-6 for the learning rate and 50 for the number of epochs. As a form of regularization, we utilize dropout after every layer. The average classification accuracies are shown in Table1. The classification accuracy for every facial attribute is above , while most are around or .
For our cGMM training, our final learning rate and regularization parameter are 1e-11 and 1e-5, respectively. We generate faces for sets of attributes that are defined by several images in the test set (i.e. we plug in these target attributes into our system and compare the image we generate with the ground truth image). One example of a generated image is in Figure 8. To measure how ”reasonable” our faces are, we use a similarity metric implemented by the PicTriev software, which uses common facial features to measure similarity . This quantitative evaluation of our faces is shown in Table 2.
Although our classification accuracies are generally quite high, there are some facial attributes such as lighting (e.g., soft lighting, harsh lighting) and photo type (e.g., color photo, posed photo) that have low accuracies (roughly 55-60%). We do not attempt to improve these attributes, since they are not as important as other, more face-related characteristics, such as nose shape and forehead visibility, that have high classification accuracies.
The most obvious result from our generation experiments is that each resultant image is very close to the mean image of our training set. Despite this, the fact that we successfully generate a coherent face from random noise indicates that our feature inversion process could work if the activations for each attribute were more discriminative.
We hypothesize several reasons why our activations are not discriminative enough. One possibility is that the distributions for different attributes are very similar and clustered around the mean image in this abstract space. Another possibility is that the distributions lie in different manifolds in this space, but that they are not normal yet roughly centered around the mean-image. This means that the act of averaging these activations and approximating them as Gaussian blurs the distinctions between these distributions.
This bring us to the assumptions about the feature activations upon which the cGMM approach relies. Our first assumption is that the distribution of activations for each attribute in a given layer is indeed Gaussian. Additionally, we assume that these Gaussians are independent. This is perhaps the least justified assumption the model makes, because clearly many attributes are correlated, such as middle-aged and white hair. Despite this, we hope that our model approximates the true distribution sufficiently for our purposes. We also assume that the variables in the multivariate Gaussian are themselves distributed normally and are independent. We believe this assumption is valid because we examined several of these distributions for individual variables as described in Section 5.
One way to improve our cGMM technique would be to estimate the target activations of a desired image by taking a weighted sum of samples from the Gaussians instead of a weighted sum of the means of the Gaussians. We opted for the latter approach because it was far more computationally efficient, but the former approach could allow for more variation from the mean image.
8 Conclusion & Future Work
In this work, we have trained an architecture that classifies facial attributes of images with high accuracy. We have also shown the effectiveness of the custom Gaussian Mixture Model in generating well-formed faces from random noise. Although the faces themselves were not discriminative enough for the desired features, we posit that we can train a model that generates discriminative faces if our dataset contained more diversity across the attributes.
Alternatively, we might implement a variational autoencoder structure as in  and compare the results with those of the cGMM. We expect that since the variational autoencoder has a higher capacity, it might give more discriminative faces but would also take longer to train. More efficient generative models open up exciting possibilities in other applications, including medicine and law enforcement.
-  AppliedDevice. Pictriev: searching faces on the web, 2010. [Online; accessed 2016-03-14].
-  Y. Bengio, L. Yao, G. Alain, and P. Vincent. Generalized denoising auto-encoders as generative models. In Advances in Neural Information Processing Systems, pages 899–907, 2013.
-  J. Gauthier. Conditional generative adversarial nets for convolutional face generation. Class Project for Stanford CS231N: Convolutional Neural Networks for Visual Recognition, Winter semester, 2014, 2014.
-  I. Goodfellow, J. Pouget-Abadie, M. Mirza, B. Xu, D. Warde-Farley, S. Ozair, A. Courville, and Y. Bengio. Generative adversarial nets. In Advances in Neural Information Processing Systems, pages 2672–2680, 2014.
-  K. Gregor, I. Danihelka, A. Graves, and D. Wierstra. Draw: A recurrent neural network for image generation. arXiv preprint arXiv:1502.04623, 2015.
-  Y. Jia, E. Shelhamer, J. Donahue, S. Karayev, J. Long, R. Girshick, S. Guadarrama, and T. Darrell. Caffe: Convolutional architecture for fast feature embedding. arXiv preprint arXiv:1408.5093, 2014.
-  E. Jones, T. Oliphant, P. Peterson, et al. SciPy: Open source scientific tools for Python, 2001–. [Online; accessed 2016-03-14].
N. Kumar, A. C. Berg, P. N. Belhumeur, and S. K. Nayar.
Attribute and Simile Classifiers for Face Verification.
IEEE International Conference on Computer Vision (ICCV), Oct 2009.
-  L. Lab. Denoising autoencoders (da). 2016.
C. P. Marc’Aurelio Ranzato, S. Chopra, and Y. LeCun.
Efficient learning of sparse representations with an energy-based model.In Proceedings of NIPS, 2007.
A. Z. O. M. Parkhi, A. Vedaldi.
Deep Face Recognition.In British Machine Vision Conference (BMVC), 2015.
-  R. Salakhutdinov. Learning deep generative models. PhD thesis, University of Toronto, 2009.
R. Salakhutdinov and G. E. Hinton.
Deep boltzmann machines.
International conference on artificial intelligence and statistics, pages 448–455, 2009.
-  N. Srivastava and R. R. Salakhutdinov. Multimodal learning with deep boltzmann machines. In F. Pereira, C. J. C. Burges, L. Bottou, and K. Q. Weinberger, editors, Advances in Neural Information Processing Systems 25, pages 2222–2230. Curran Associates, Inc., 2012.
-  P. Vincent. A connection between score matching and denoising autoencoders. Neural computation, 23(7):1661–1674, 2011.
P. Vincent, H. Larochelle, I. Lajoie, Y. Bengio, and P.-A. Manzagol.
Stacked denoising autoencoders: Learning useful representations in a
deep network with a local denoising criterion.
The Journal of Machine Learning Research, 11:3371–3408, 2010.