CODECENTRIC.AI BOOTCAMP

Generative Adversarial Networks (GAN)

@tsabsch

@moseroli

Brock, A., Donahue, J., & Simonyan, K. (2018). Large Scale GAN Training for High Fidelity Natural Image Synthesis

  • Was sind Generative Adversarial Networks?
  • Wofür kann man verwenden?
  • Beispiel in Keras + TensorFlow
    • Deep Convolutional GAN (DCGAN)
    • Wasserstein GAN (WGAN)
    • Conditional GAN (cGAN)

Gabi

Diana

Ludwig

Auktionshaus Miller's

Quelle Icons: freepik.com

Kunstfälscherin

Junior

Senior

Eine kleine Analogie ...

Generieren, Bewerten und Lernen

Ist das echt?

Quelle Icons: freepik.com

Generative Adversarial Network

Generator

Diskriminator

/

Quelle Icons: freepik.com

Generative Adversarial Network

Quelle Icons: freepik.com

Generator

Diskriminator

Generative Adversarial Network

Quelle Icons: freepik.com

\sum{w_i x_i}
\sum{w_i x_i}

Generative Adversarial Network

Quelle Icons: freepik.com

\sum{w_i x_i}
\sum{w_i x_i}

Generative Adversarial Network

Quelle Icons: freepik.com

\sum{w_i x_i}
\sum{w_i x_i}

Anwendungen

Aktives Forschungsfeld

Quelle Icons: freepik.com

Anwendungen

Erhöhung der Bildauflösung

Original

Bicubic

GAN

Ledig, C., Theis, L., Huszár, F. et al. Photo-realistic single image super-resolution using a generative adversarial network. CVPR 2017

Anwendungen

Einfärben von Schwarzweiß-Bildern

Original

SW

GAN

Nazeri, K., Ng, E., & Ebrahimi, M. Image colorization using generative adversarial networks. LNCS 2018

Anwendungen

Stil-Übertragung

Zhu, J., Park, T., Efros, A. et al. Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks.

Anwendungen

Automatisierte Fotobearbeitung

Original

GAN

Zhu, J., Park, T., Efros, A. et al. Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks.

Anwendungen

Edmond de Belamy

 

von GAN generiertes Bild

verkauft für 432.500 $ (Auktionshaus Christie's)

 

Künstler: Obvious (Gruppe)

 

 

 

Copyright Obvious

Implementation

from keras.models import Sequential
from keras.layers import Dense, LeakyReLU, Reshape, MaxoutDense

img_shape = (28, 28)  # image height, width
res = 28 ** 2
noise_res = int(res / 4)

G = Sequential()
G.add(Dense(int(res/4), input_shape=(noise_res,)))
G.add(LeakyReLU())
G.add(Dense(int(res/2)))
G.add(LeakyReLU())
G.add(Dense(int(res)))
G.add(LeakyReLU())
G.add(MaxoutDense(res))
G.add(Reshape(img_shape))

Quelle Icons: freepik.com

Implementation

from keras.layers import Flatten

D = Sequential()
D.add(Flatten(input_shape=img_shape))
D.add(Dense(int(res/2)))
D.add(LeakyReLU())
D.add(Dense(int(res/4)))
D.add(LeakyReLU())
D.add(Dense(int(res/8)))
D.add(LeakyReLU())
D.add(Dense(1, activation='sigmoid'))

Quelle Icons: freepik.com

Implementation

from keras.datasets import mnist
import numpy as np

(images, _), (_, _) = mnist.load_data()

# normalise data
images = (images - np.min(images)) / (np.max(images) - np.min(images))
from keras.models import Model
from keras.layers import Input
from keras.optimizers import Adam

optimizer = Adam(0.0002, 0.5)
D.compile(loss='binary_crossentropy', optimizer=optimizer)

D.trainable = False
z = Input(shape=(noise_res,))
full_gan = Model(z, D(G(z)))
full_gan.compile(loss='binary_crossentropy', optimizer=optimizer)

Quelle Icons: freepik.com

Implementation

epochs = 30000
batch_size = 32
half_batch_size = int(batch_size / 2)

for epoch in range(epochs):
    # get half the batch from real images
    real_idxs = np.random.randint(images.shape[0], size=half_batch_size)
    real_batch = images[real_idxs]
    
    # get other half from generated images
    noise = np.random.normal(size=(half_batch_size, noise_res))
    fake_batch = G.predict(noise)
    
    # train discriminator
    D.train_on_batch(real_batch, np.ones(half_batch_size))
    D.train_on_batch(fake_batch, np.zeros(half_batch_size))

    # train generator
    noise = np.random.normal(size=(batch_size, noise_res))
    full_gan.train_on_batch(noise, np.ones(batch_size,))

Quelle Icons: freepik.com

Implementation

Quelle Icons: freepik.com

Deep Convolutional GAN

Quelle Icons: freepik.com

Radford, A., Metz, L., & Chintala, S. Unsupervised Representation Learning
with Deep Convolutional Generative Adversarial Networks

  • Convolutional-Architektur
  • Batchnormalisierung
  • (Leaky) Rectified Linear Unit
  • Strided Convolutions statt Pooling
  • Fügt sinnvolle Fehlerfunktion hinzu: Wasserstein-Distanz
  • Horizontale statt vertikale Abweichung

Wasserstein GAN

Arjovsky, M., Chintala, S., & Bottou, L. (2017). Wasserstein GAN.

Wasserstein GAN

  • Bedingung: 1-Lipschitz-Funktion
    • Gewichte eingrenzen (WGAN)
    • Graduelle Strafe (WGAN-GP)

Arjovsky, M., Chintala, S., & Bottou, L. (2017). Wasserstein GAN.

Conditional GAN

Mirza, M., & Osindero, S. (2014). Conditional Generative Adversarial Nets.

  • Erlaubt Kontrolle über das Ergebnis des Generators
  • Zusätzlich zum Rauschsignal wird Klasseninformation übergeben

Conditional GAN

Quelle Icons: freepik.com

Generative Adversarial Networks

By cc_ai

Generative Adversarial Networks

Einführung in das Thema GANs

  • 137
Loading comments...

More from cc_ai