Introduction
AI-based filtering, face-changing and photo-editing software have taken the internet by storm. People today spend endless hours trying to find the perfect filters to beautify their photos, try quirky animal or rockstar filters or just try to anticipate how their future self would look like.
With the advancements in virtual reality and augmented reality, developers are trying to constantly inject more life into their models. This desire to generate realistic AI faces has been made easy by the development of anime face gan Generative Adversarial Networks (GANs for short) in 2014 by Ian J. Goodfellow and his co-authors. In this blog, we will learn how to utilise GANs and PyTorch to create anime faces.
Also Read, clustering in machine learning
What are Generative Adversarial Networks (GANs)?
As defined by Machine Learning Mastery, ‘Generative modelling is an unsupervised learning task in machine learning that involves automatically discovering and learning the regularities or patterns in input data in such a way that the model can be used to generate or output new examples that plausibly could have been drawn from the original dataset.’
What this essentially means is that GANs belong to a set of generative models which are able to produce novel content based on the data set provided to them. Although generative modelling is an unsupervised learning technique, the GAN architecture frames the training of the model as a supervised learning technique.
This can be described with the help of the following diagram:
Source: Machine Learning Mastery
Mostly used in the field of image transformation, GANs generate novel content with the help of two sub-models, Generator and Discriminator. The generator model takes in a random input vector and generates a new fake content, while the discriminator model tries to classify the examples as real (present in the training data) or fake (developed by the generator model).
These two models are trained together in tandem. The discriminator model is trained for a few epochs, followed by the generator model being trained for a few epochs, and this process is repeated continuously, ensuring both the generator model and discriminator model get better with each iteration. The two models compete against each other in a zero-sum adversarial game. This means that each time the discriminator model successfully distinguishes the real from the fake samples, it is rewarded. No change is made to the models’ parameters, while the generator is penalised and its parameters are updated.
Alternatively, each time the generator model fools the discriminator model, it is rewarded. No change is made to the models’ parameters, while the discriminator is penalised and its parameters are updated. Until the discriminator model is fooled more than 50% of the times, the process is continued to ensure that the generator model generates only plausible content. To get a sense of the power of these generative models, visit thispersondoesnotexist.com, which generates a new face of a person who does not exist every time the page is reloaded.
What is PyTorch?
PyTorch is a free and open-source machine learning library developed by Facebook’s AI Research Lab (FAIR) under the Modified BSD License. It is widely used for computer vision and natural language processing since it is an optimised tensor library used for complex deep learning solutions by utilising GPUs and CPUs. We generally use PyTorch for generating AI faces because it provides two high-level features – Tensor computing and deep neural networks.
Similar to NumPy arrays, the tensors help store and operate a tensor class on a homogeneous multidimensional rectangular array of numbers, while the deep neural networks are built on a tape-based automatic differentiation system. Hence, PyTorch perfectly suits our requirements to create the novel anime faces.