Deeplearning - Ai Deeplearning - Ai
Deeplearning - Ai Deeplearning - Ai
DeepLearning.AI makes these slides available for educational purposes. You may not use or
distribute these slides for commercial purposes. You may make copies of these slides and
use or distribute them for educational purposes as long as you cite DeepLearning.AI as the
source of the slides.
Edges to photo
Paired images
Paired
images
Paired Unpaired
images images
Real
Fake
Real
Fake
Fake
Real
Fake
Cycle consistency
GAN Z → H
GAN H → Z
GAN H → Z
Fake
GAN H → Z GAN Z → H
Fake Fake
Discriminator:
PatchGAN
0.8
Generator ≈
U-Net
Generator ≈
U-Net + DCGAN
generator
Generator ≈
U-Net + DCGAN
generator
GAN Z → H
GAN Z → H
GAN H → Z
GAN Z → H
GAN H → Z
GAN Z → H
GAN H → Z
Generator H → Z
Discriminator Z
Images available from: https://github.com/togheppi/CycleGAN
GAN Z → H
Real Fake
Generator
Z→H
Generator Discriminator
Z→H H
Real Discriminator
H
Generator Discriminator
Z→H H
Classification
matrix
Real Discriminator
H
Generator
H→Z
Generator Discriminator
H→Z Z
Classification
matrix
Real Discriminator
Z
Generator
H→Z
Fake
Images available from: https://github.com/togheppi/CycleGAN
Cycle Consistency Loss
Real
Generator Fake
Z→H
Take pixel
difference for
Z → H→ Z
Generator
H→Z
Fake
Images available from: https://github.com/togheppi/CycleGAN
Cycle Consistency Loss
Real
Generator Fake
H→Z
Take pixel
difference for
H→ Z → H
Generator
Z→H
Fake
Images available from: https://github.com/togheppi/CycleGAN
Cycle Consistency Loss
+
Z→H→Z H→Z→H
+
Adversarial Loss +
Z→H→Z H→Z→H
Without Adversarial
GAN Loss, outputs are
not realistic
4 A B
3
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares
6
4 A B
3
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares
6
4 A B
3
1
2 2 4
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares
6
4 A B
3
1 1
2 2² = 4 2 4² = 16 4
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares Sum of squares is 4 + 1 + 16 = 21
6
4 A B
3
1 1
2 2² = 4 2 4² = 16 4
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares Sum of squares is 4 + 1 + 16 = 21
6
4 A B
Minimize
3
sum of squares 1 1
2 2² = 4 2 4² = 16 4
1
C
0 1 2 3 4 5 6 7 8 9 10 11
Least Squares Loss: Discriminator
Discriminator classification
of real image x
Least Squares Loss: Discriminator
Least Squares Loss: Discriminator
Discriminator classification
of fake image G(z)
Least Squares Loss: Discriminator
Least Squares Loss: Discriminator
Least Squares Loss: Generator
Least Squares Loss
Discriminator
Loss
Least Squares Loss
Discriminator
Loss
Generator
Loss
Least Squares Loss
Discriminator
Loss
Generator
Loss
Discriminator
Loss
Generator
Loss
● More stable than BCELoss, since the gradient is only flat when
prediction is exactly correct
CycleGAN:
Identity Loss
deeplearning.ai
Outline
● Identity Loss
○ How it works
○ Impact on outputs
Identity Loss
Real input Ideal output
Generator
Z→H
“Opposite”
generator
Generator
Z→H
“Opposite”
generator
Pixel distance
Generator
Z→H
“Opposite”
generator
Generator
Z→H
“Opposite”
generator
Discourage mapping Z → H
Pixel distance to distort colors
Images available from: https://github.com/togheppi/CycleGAN
Context of Identity Loss
+ Generator
Z→H + Generator
H→Z
+ Identity Loss
Context of Identity Loss
+ λ * Identity Loss
2
Identity Loss Example: Photo → Monet
Input No Identity Loss With Identity Loss
Generator
Z→H
Generator Discriminator
Z→H H
Discriminator
H
Classification matrix
Real
Generator Discriminator
Z→H H
Least Squares
Loss
Discriminator
H
Classification matrix
Real
Generator Discriminator
Z→H H
Least Squares
Loss
Discriminator
H
Generator
H→Z
Classification matrix
Fake Real
Generator Discriminator
Z→H H
Fake Real
Generator Discriminator
H→Z Z
Fake Real
Generator
H→Z
Identity Loss
Generator
Z→H
Identity Loss