1 of 9

Soo Kyung Kim

Department of AI

GAN Implementation

2 of 9

GAN in a NutShell - High-level idea

3 of 9

GAN in a NutShell - Discriminator

  • Input: a real image in training data, or a fake image generated by Generator (G)
  • Output: probability that the input is a real image (with sigmoid)
  • Objective: real vs. fake binary classification (cross-entropy)
    • Note that we don’t have (-) sign at the beginning, so we maximize this instead of minimize.

z

G(z)

D(x)

p(real)

Discriminator

x

For real image x, the discriminator wants to output high p(real).

(Dθ(x) → 1)

For an image generated by G, the discriminator wants to output low p(real).

(Dθ(Gθ(z)) → 0)

4 of 9

GAN in a NutShell - Generator

  • Input: a random vector sampled from p(z)
  • Output: a real-like image (in training data)
  • Objective: Fooling the Discriminator
    • G tries to make D hard to distinguish real vs. fake by generating real-like images.

z

G(z)

D(x)

p(real)

Discriminator

x

Nothing to do when D takes a real example.

When G generates an image, its goal is to increase p(real) output of D with it, by producing a real-like image.

(Dθ(Gθ(z)) → 1)

Generator

5 of 9

Training GAN

6 of 9

GAN in a NutShell - DCGAN

Generator

Discriminator

5×5 deconv

stride=2

5×5 deconv

stride=2

5×5 deconv

stride=2

5×5 deconv

stride=2

5×5 conv

stride=2

5×5 conv

stride=2

5×5 conv

stride=2

5×5 conv

stride=2

7 of 9

Deconvolution layer

https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2DTranspose

Transposed convolutions to use a transformation going in the opposite direction of a normal convolution,

i.e., from something that has the shape of the output of some convolution to something that has the shape of its input while maintaining a connectivity pattern that is compatible with said convolution.

8 of 9

Gradient Tape: Record operations for automatic differentiation.��

https://www.tensorflow.org/api_docs/python/tf/GradientTape

  • Control gradient in code without using fit function.

  • Operations are recorded if they are executed within this context manager and at least one of their inputs is being "watched".

9 of 9

Step-by-Step guideline of DCGAN�implementation with Tensorflow