GANs Demystified — What the hell do they learn?

Visualising Generative Adversarial Networks

This article is a summary of the research paper “GAN Dissection: Visualising And Understanding Generative Adversarial Networks”. The paper provides an excellent insight into the internal representation of GANs and gives a close answer to the following question.

What the hell do GANs learn? I’m specifically referring to the generator. We’ve all seen stunning results produced by GANs, almost indistinguishable from human work in some cases. But how they represent learned knowledge is still a mystery. Do they simply learn pixel patterns and composite what they see? Or do they actually capture complex relationships from training data?

This paper attempts to decipher the representation of GANs and illustrates techniques to visualize and debug them. It does so using two phases.

Overview of the work. Watch the demo video here

Dissection

Dissection aims to identify object classes that outputs of a layer in generator represents. E.g. Does a particular unit in G represent trees?

Some terminology:

Unit: Each channel of the featuremap of generator G

r: Output of a layer of the generator

Based on Bau et al. (2017), the feature map of a filter gives a good approximation of the segmentation of the object class. For each object class we’re interested in, we first calculate the segmentation mask of the class in the generated image. We upsample and threshold the feature map of unit u using the formula below. We then take the IOU between this thresholded, upsampled featuremap and the segmentation mask of the class.

∧ represents intersection and ∨ represents union. s_c(x) represents segmentation mask for a particular class c in image x. The formula for calculating the threshold value for a particular unit and class is also mentioned above. In a nutshell, the above formula gives a measure of how much a unit u represents class c. You can read more about the intuition behind the threshold value formula in the paper.

1

So ranking concepts (object classes) represented by the unit by sorting these scores for values obtained for each class c.

TLDR; Dissections allows you to discover the units which match closely with an object class. But it doesn’t necessarily mean that they are responsible for generating them.

Intervention

Intervention aims to find whether a set of units cause an object class c. This is done by toggling the units on and off and observing the effects on the generated image G.

r: Tensor output (activation map) from a specific layer of G

U: Set of units

P: Pixels in the generated image G

Ablation refers to turning off units in U by setting them to 0. On the other hand, insertion forces units in U to equal k, a per class constant. k for a class c is calculated by taking the mean of feature map of units that cause c.

The above formula gives a measure of how much units U are responsible for generating class c. This measure is named average causal effect (ACE). Here, s_c(x) denotes the segmentation map of class c in the image x at pixels P. So basically the difference between causal effects on segmentation map of class c in G on insertion and ablation.

But how do we know how to pick the optimal set of units U? It is intractable to do an exhaustive search to pick the optimal combination.This is done by using a clever objective function and outsourcing this work to gradient descent.

We set U to be the entire set of units but weigh them with a parameter vector alpha. Stochastic gradient descent is then used to maximize the objective function (ACE) and minimize the number of units in the optimal set (By using L2 regularisation term for alpha).

L2 regularisation term is added to minimize number of units in the optimal set

The figure below shows how ablating units that cause trees successfully removes trees from the generated image.

Ablating units to remove trees

Results in a nutshell

Differences between layers: Based on the results, first layer doesn’t match well object classes. This makes intuitive sense since early layers usually represent primitive features. Mid layers have many units that match semantic objects and object parts. Ending layers match local pixel patterns such as materials, edges and colors.

Differences between GAN architectures: The paper also discusses how different architectures compare in internal representation by examining the units.

Contextual Relationships via Insertion: The paper also describes insertion of features into specific locations of the generated image by forcing units. One interesting observation is that an object like door can only be inserted at specific locations where it visually makes sense (e.g buildings near windows, bricks). This suggests that GANS infact capture relationships between objects, not simply pixel patterns.

The above image illustrates how the generation of object classes is highly dependant on local context. The actual effect of insertion differs based on where it occurs.

Diagnosing GANs

By using intervention technique, we can study the causation of erroneous / undesirable parts and artifacts in the generated images. Through manual annotation and ablating the causing units, results of your GAN can be considerably improved. The image below illustrates how ablating artifact causing unit produces visible results.

Using this framework, you can manually tailor and influence the results of your GAN. It is relatively simple to enhance or reduce the presence of certain object classes (to an extent).

Final Thoughts

The paper makes an excellent attempt to demystify GANs, a relatively unexplored topic so far. Their framework enables researches and practitioners to better debug, improve and understand their models.

The discussed debugging methods involves are mostly based on manual supervision. However, I believe the reasoning and techniques presented in the paper could potentially be used in developing more automated techniques to improve GANs (The paper discusses one such technique for automatic identification of artifact units).

Credits: Ideas, formulas and images taken from the paper.

References

GAN Dissection: Visualizing and Understanding Generative Adversarial Networks

Project Official Website (With Github code, demo video, slides, e.t.c)

Interactive GAN Paint Tool