The Wayback Machine - https://web.archive.org/web/20240822105422/https://www.geeksforgeeks.org/stylegan-style-generative-adversarial-networks/
Open In App

StyleGAN – Style Generative Adversarial Networks

Last Updated : 05 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Generative Adversarial Networks (GAN) was proposed by Ian Goodfellow in 2014. Since its inception, there are a lot of improvements are proposed which made it a state-of-the-art method generate synthetic data including synthetic images. However most of these improvements made on the discriminator part of the model which refines the generation ability of generator. This also implies that there was not much focus on the generator part which causes the lack of control over the generator part of GAN. There are some parameters that can be changed during the generation part such as background, foreground and style or for human faces there are many features that can be altered in the generation of various images such pose, hair color, eyes color etc.

Style GAN proposes a lot of changes in the generator part which allows it to generate the photo-realistic high-quality images as well as modify some part of the generator part.

Architecture:

Style GAN uses the baseline progressive GAN architecture and proposed some changes in the generator part of it. However, the discriminator architecture is quite similar to baseline progressive GAN. Let’s look at these architectural changes one by one.

Style GAN architecture

  • Baseline Progressive Growing GANs: Style GAN uses baseline progressive GAN architecture which means the size of generated image increases gradually from a very low resolution (4×4) to high resolution (1024 x1024). This is done by adding a new block to both the models to support the larger resolution after fitting the model on smaller resolution to make it more stable..
  • Bi-linear Sampling:  The authors of paper uses bi-linear sampling instead of nearest neighbor up/down sampling (which was used in previous Baseline Progressive GAN architectures) in both generator and discriminator. They implement this bi-linear sampling by low pass filtering the activation with a separable 2nd order binomial filter after each of the upsampling layer and before each of the downsampling layer.
  • Mapping Network and Style Network: The goal of the mapping network is to generate the input latent vector into the intermediate vector whose different element control different visual features. Instead of directly providing latent vector to input layer the mapping is used. In this paper, the latent vector (z) of size 512 is mapped to another vector of 512 (w). The mapping function is implemented using 8-layer MLP (8- fully connected layers).  The output of mapping network (w) then passed through a learned affine transformation (A) before passing into the synthesis network which AdaIN (Adaptive Instance Normalization) module. This model converts the encoded mapping into the generated image.

Generator Architecture of Style GAN vs Traditional Architecture

  • The input to the AdaIN is y = (ys, yb) which is generated by applying (A) to (w). The AdaIN operation is defined by the following equation:

[Tex]AdaIN (x_i, y) = y_{s, i}\left ( \left ( x_i – \mu_i \right )/ \sigma_i \right )) + y_{b, i}   [/Tex]
where each feature map x is normalized separately, and then scaled and biased using the corresponding scalar components from style y. Thus the dimensional of y is twice the number of feature maps  (x) on that layer. The synthesis network contains 18 convolutional layers 2 for each of the resolutions (4×4 – 1024×1024).

  • Removing traditional (Latent) input: Most previous style transfer model uses the random input to create the initial latent code of the generator i.e. the input of the 4×4 level. However the style-GAN authors concluded that the image generation features are controlled by w and  AdaIN. Therefore they replace the initial input with the constant matrix of 4x4x512. This also contributed to increase in the performance of the network.
  • Addition of Noisy:Input  A Gaussian noise (represented by B) is added to each of these activation maps before the AdaIN operations. A different sample of noise is generated for each block and is interpreted on the basis of scaling factors of that  layer.
  • There are many aspects in people’s faces that are small and can be seen as stochastic, such as freckles, exact placement of hairs, wrinkles, features which make the image more realistic and increase the variety of outputs. The common method to insert these small features into GAN images is adding random noise to the input vector
  • Mixing Regularization:  The Style generation used intermediate vector at each level of synthesis network which may cause network to learn correlation between different levels. In order to reduce the correlation, the model randomly selects two input vectors (z1 and z2) and generates the intermediate vector (w1 and w2) for them. It then trains some of the levels with the first and switches (in a random split point) to the other to train the rest of the levels. This switch in random split points ensures that network don’t learn correlation very much.

Style on the Basis of Resolution:Images 

coarsefineresult-copy-2


In order to have more control on the styles of the generated image, the synthesis network provides control over the style to different level of details (or resolution). These different levels are defined as: 

  1. Coarse – resolution of  ( 4×4 – 8×8) – affects pose, general hair style, face shape, etc
  2. Middle – resolution of (16×16 – 32×32) – affects finer facial features, hair style, eyes open/closed, etc.
  3. Fine – resolution of (64×64 – 1024×1024) – affects colors for (eye, hair and skin) and micro features.

The author of this paper also varied noise between these levels. Thus, noise will take over the control of changes in the style in these level. For Example: Noise in coarse level cause changes in broader structure while in Fine level cause changes in finer details of image.

Feature Disentanglement Studies: 

The aim of these feature disentanglement study to measure the variation of feature separation. In this paper author presents two separate metrics for feature disentanglement:

  • Perceptual path length : In this metric we measure the weighted difference between the VGG embedding of two consecutive images when interpolating between two random inputs.
    • The average perceptual path length over the latent space Z is defined over all possible endpoints is defined as

      [Tex]\begin{aligned} l_{ Z }= E \left[\frac{1}{\epsilon^{2}} d\left(G\left(\operatorname{slerp}\left( z _{1}, z _{2} ; t\right)\right)\right.\right.\\ \left.\left.G\left(\operatorname{slerp}\left( z _{1}, z _{2} ; t+\epsilon\right)\right)\right)\right] \end{aligned}   [/Tex]
       
  • where z1, z2 ? P(z), t ? U(0, 1), G is the generator (i.e., g ?f for style-based networks), and d(·, ·) evaluates the perceptual distance between the resulting images. Here slerp stands for spherical Interpolation. Drastic changes in perceptual distance means that multiple features have changed together and that they might be entangled
  • Linear separability: In this method we look at how well the latent-space points can be separated into two distinct sets via a linear hyperplane, so that each set corresponds to a specific binary attribute of the image. For Example Each of the face images belong to either male or female.

The authors of this paper applied these metrics to both w(intermediate mapping) and z(latent space) and concludes that w are more separable. This also underscores the importance of 8-layer mapping network.

Results: 


This paper generates state -of-the art results on Celeba-HQ dataset. This paper also proposes a new dataset of human faces called Flicker Face HQ (FFHQ) dataset which have considerably more variation than Celeba-HQ. this style-GAN architecture generates considerably good results also on FFHQ dataset. Below are the results (FID score) of this architecture on these two dataset. 

Here we calculate FID score using 50, 000 randomly chosen images from the training set, and take the lowest distance encountered over the course of training

References: 


 



Previous Article
Next Article

Similar Reads

Basics of Generative Adversarial Networks (GANs)
GANs is an approach for generative modeling using deep learning methods such as CNN (Convolutional Neural Network). Generative modeling is an unsupervised learning approach that involves automatically discovering and learning patterns in input data such that the model can be used to generate new examples from the original dataset. GANs is a way of
3 min read
Use Cases of Generative Adversarial Networks
Image synthesis: Generating new, realistic images from a given data distribution, such as faces, landscapes, or animals. Text-to-Image synthesis: Generating images from text descriptions, such as scene descriptions, object descriptions, or attributes.Image-to-Image translation: Translating images from one domain to another, such as converting grays
5 min read
Building a Generative Adversarial Network using Keras
Prerequisites: Generative Adversarial Network This article will demonstrate how to build a Generative Adversarial Network using the Keras library. The dataset which is used is the CIFAR10 Image dataset which is preloaded into Keras. You can read about the dataset here. Step 1: Importing the required libraries import numpy as np import matplotlib.py
4 min read
Cycle Generative Adversarial Network (CycleGAN)
GANs was proposed by Ian Goodfellow . Cycle GAN is used to transfer characteristic of one image to another or can map the distribution of images to another. In CycleGAN we treat the problem as an image reconstruction problem. We first take an image input (x) and using the generator G to convert into the reconstructed image. Then we reverse this pro
8 min read
What is so special about Generative Adversarial Network (GAN)
Fans are ecstatic for a variety of reasons, including the fact that GANs were the first generative algorithms to produce convincingly good results, as well as the fact that they have opened up many new research directions. In the last several years, GANs are considered to be the most prominent machine learning research, and since then, GANs have re
5 min read
Selection of GAN vs Adversarial Autoencoder models
In this article, we are going to see the selection of GAN vs Adversarial Autoencoder models. Generative Adversarial Network (GAN)The Generative Adversarial Network, or GAN, is one of the most prominent deep generative modeling methodologies right now. The primary distinction between GAN and VAE is that GAN seeks to match the pixel level distributio
6 min read
Signed Networks in Social Networks
Prerequisite: Introduction to Social Networks In Social Networks, Network is of 2 types- Unsigned Network and Signed Network. In the unsigned network, there are no signs between any nodes, and in the signed network, there is always a sign between 2 nodes either + or -. The '+' sign indicates friendship between 2 nodes and the '-' sign indicates enm
4 min read
The Difference Between Generative and Discriminative Machine Learning Algorithms
Machine learning algorithms allow computers to learn from data and make predictions or judgments, machine learning algorithms have revolutionized a number of sectors. Generic and discriminative algorithms are two essential strategies with various applications in the field of machine learning. We will examine the core distinctions between generative
6 min read
Depth wise Separable Convolutional Neural Networks
Convolution is a very important mathematical operation in artificial neural networks(ANN's). Convolutional neural networks (CNN's) can be used to learn features as well as classify data with the help of image frames. There are many types of CNN's. One class of CNN's are depth wise separable convolutional neural networks. These type of CNN's are wid
4 min read
Recurrent Neural Networks Explanation
Today, different Machine Learning techniques are used to handle different types of data. One of the most difficult types of data to handle and the forecast is sequential data. Sequential data is different from other types of data in the sense that while all the features of a typical dataset can be assumed to be order-independent, this cannot be ass
8 min read
Long Short Term Memory Networks Explanation
Prerequisites: Recurrent Neural Networks To solve the problem of Vanishing and Exploding Gradients in a Deep Recurrent Neural Network, many variations were developed. One of the most famous of them is the Long Short Term Memory Network(LSTM). In concept, an LSTM recurrent unit tries to "remember" all the past knowledge that the network is seen so f
7 min read
Gated Recurrent Unit Networks
Gated Recurrent Unit (GRU) is a type of recurrent neural network (RNN) that was introduced by Cho et al. in 2014 as a simpler alternative to Long Short-Term Memory (LSTM) networks. Like LSTM, GRU can process sequential data such as text, speech, and time-series data. The basic idea behind GRU is to use gating mechanisms to selectively update the hi
8 min read
Introduction to Residual Networks
Recent years have seen tremendous progress in the field of Image Processing and Recognition. Deep Neural Networks are becoming deeper and more complex. It has been proved that adding more layers to a Neural Network can make it more robust for image-related tasks. But it can also cause them to lose accuracy. That's where Residual Networks come into
3 min read
Understanding of LSTM Networks
This article talks about the problems of conventional RNNs, namely, the vanishing and exploding gradients, and provides a convenient solution to these problems in the form of Long Short Term Memory (LSTM). Long Short-Term Memory is an advanced version of recurrent neural network (RNN) architecture that was designed to model chronological sequences
9 min read
Residual Networks (ResNet) - Deep Learning
After the first CNN-based architecture (AlexNet) that win the ImageNet 2012 competition, Every subsequent winning architecture uses more layers in a deep neural network to reduce the error rate. This works for less number of layers, but when we increase the number of layers, there is a common problem in deep learning associated with that called the
10 min read
Dropout in Neural Networks
The concept of Neural Networks is inspired by the neurons in the human brain and scientists wanted a machine to replicate the same process. This craved a path to one of the most important topics in Artificial Intelligence. A Neural Network (NN) is based on a collection of connected units or nodes called artificial neurons, which loosely model the n
3 min read
DeepPose: Human Pose Estimation via Deep Neural Networks
DeepPose was proposed by researchers at Google for Pose Estimation in the 2014 Computer Vision and Pattern Recognition conference. They work on formulating the pose Estimation problem as a DNN-based regression problem towards body joints. They present a cascade of DNN-regressors which resulted in high precision pose estimates.. Architecture: Pose V
5 min read
Introduction to Social Networks using NetworkX in Python
Prerequisite - Python Basics Ever wondered how the most popular social networking site Facebook works? How we are connected with friends using just Facebook? So, Facebook and other social networking sites work on a methodology called social networks. Social networking is used in mostly all social media sites such as Facebook, Instagram, and LinkedI
4 min read
Different dataset forms in Social Networks
Prerequisite: Python Basics For constructing any network we need a good dataset and every network has a different format for data of datasets. Basically a dataset is nothing but a huge collection of data that can be used further for any analysis. Data in dataset can be in many formats. Example of Network datasets: Ingredients network.Synonymy netwo
3 min read
Single Layered Neural Networks in R Programming
Neural networks also known as neural nets is a type of algorithm in machine learning and artificial intelligence that works the same as the human brain operates. The artificial neurons in the neural network depict the same behavior of neurons in the human brain. Neural networks are used in risk analysis of business, forecasting the sales, and many
5 min read
Activation functions in Neural Networks | Set2
The article Activation-functions-neural-networks will help to understand the use of activation function along with the explanation of some of its variants like linear, sigmoid, tanh, Relu and softmax. There are some other variants of the activation function like Elu, Selu, Leaky Relu, Softsign and Softplus which are discussed briefly in this articl
3 min read
Implementation of Erdos-Renyi Model on Social Networks
Prerequisite: Introduction to Social Networks, Erdos-Renyi Model Erdos Renyi model is used to create random networks or graphs on social networking. In the Erdos Reny model, each edge has a fixed probability of being present and being absent independent of the edges in a network. Implementing a Social Network using the Erdos-Renyi model:Step 1) Imp
3 min read
Selection and Social Influence-Homophily in Social Networks
Homophily is the tendency in social groups of similar people connected together. We often hear similar voices interact with like-minded people. Homophily has a significant impact on social media. Example - Birds with feather flock together. Assume there are 1000 people in a party out of which 500 are of age ranges from 18-25 and the other 500 peopl
2 min read
Basic Understanding of Bayesian Belief Networks
Bayesian Belief Network is a graphical representation of different probabilistic relationships among random variables in a particular set. It is a classifier with no dependency on attributes i.e it is condition independent. Due to its feature of joint probability, the probability in Bayesian Belief Network is derived, based on a condition — P(attri
4 min read
Fatman Evolutionary Model in Social Networks
Prerequisite: Introduction to Social Networks In the Fatman evolutionary model, there are 3 main concepts to make an evolutionary model i.e Homophily, Social influence, and closure. Homophily- People who are similar to each other, they tend to make friends with each other.Social Influence- People change their behavior and properties because of soci
4 min read
Spatial Segregation in Social Networks
Prerequisite - Introduction to Social Networks Segregation refers to the act of separation of people from others or the main group. Spatial Segregation refers to the distribution of social groups or any other elements in space. In Spatial Segregation, people tend to migrate to other places where they have more neighbors who are like them. According
6 min read
Cascading Behavior in Social Networks
Prerequisite: Introduction to Social Networks, Python Basics When people are connected in networks to each other then they can influence each other's behavior and decisions. This is called Cascading Behavior in Networks. Let's consider an example, assume all the people in a society have adopted a trend X. Now there comes new trend Y and a small gro
7 min read
Training Neural Networks with Validation using PyTorch
Neural Networks are a biologically-inspired programming paradigm that deep learning is built around. Python provides various libraries using which you can create and train neural networks over given data. PyTorch is one such library that provides us with various utilities to build and train neural networks easily. When it comes to Neural Networks i
8 min read
Episodic Memory and Deep Q-Networks
Episodic Memory: Episodic Memory is a category of long-term memory that involves recent recollection of specific events, situations, and experiences. For Example Your first day at college. There are two important aspects of episodic memory are Pattern Separation and Pattern Completion. Semantic Memory is used in many ways in machine learning such a
7 min read
Numpy Gradient - Descent Optimizer of Neural Networks
NumPy Gradient Descent Optimizer is a commonly used optimization algorithm in neural network training that is based on the gradient descent algorithm. It is used to minimize the cost function of a neural network model, by adjusting the model's weights and biases through a series of iterations. The basic steps of NumPy Gradient Descent Optimizer are
6 min read
three90RightbarBannerImg