Successfully reported this slideshow.
Your SlideShare is downloading. ×

Generative Adversarial Networks (GANs)

Ad

A friendly introduction to
Generative Adversarial Networks
Luis Serrano

Ad

thispersondoesnotexist.com

Ad

Python (no packages!)
www.github.com/luisguiserrano/gans

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Upcoming SlideShare
Unity Valley
Unity Valley
Loading in …3
×

Check these out next

1 of 57 Ad
1 of 57 Ad

More Related Content

Generative Adversarial Networks (GANs)

  1. 1. A friendly introduction to Generative Adversarial Networks Luis Serrano
  2. 2. thispersondoesnotexist.com
  3. 3. Python (no packages!) www.github.com/luisguiserrano/gans
  4. 4. General idea
  5. 5. Generative Adversarial Networks DiscriminatorGenerator
  6. 6. Generative Adversarial Networks DiscriminatorGenerator Nope!
  7. 7. Generative Adversarial Networks DiscriminatorGenerator Nope!
  8. 8. Generative Adversarial Networks DiscriminatorGenerator Nope!
  9. 9. Generative Adversarial Networks DiscriminatorGenerator Nope!
  10. 10. Yup! Generative Adversarial Networks DiscriminatorGenerator AHA!! ?
  11. 11. DiscriminatorGenerator Real images ?AHA!!
  12. 12. Build the simplest GAN
  13. 13. Slanted Land Slanted people 2x2 screens 1-layer Neural networks
  14. 14. Faces
  15. 15. No faces (noise)
  16. 16. Tell them apart Faces Noise
  17. 17. 0.25 0 1 0.75 0.25 1 0.5 0.75 0.75 0.5 0.75 0 1 1 0 0.75 0.75 0 0 0.75 1 0.25 0.25 0.75 1 0 0 1 0.75 0 0.25 0.75 Faces Noise 10
  18. 18. Building the Discriminator
  19. 19. Building the discriminator Faces Noise 1 0 0 1 0.25 1 0.5 0.75 Big Big small small any any any any
  20. 20. Building the discriminator Faces Noise 1 0 0 1 0.25 1 0.5 0.75 + + + + -- - - 1*1 + 0*(-1) + 0*(-1) + 1*1 = 2 0.25*1 + 1*(-1) + 0.5*(-1) + 0.75*1 = -0.5Threshold = 1 More than 1: face. Less than 1: no face
  21. 21. Discriminator 1 0 0 1 +1 -1 +1 -1 1 -1 Bias 1*1 +0*(-1) +0*(-1) +1*1 -1 1σ( ) = 0.73 σ(x) = 1 1 + e−x 1 1 0.73
  22. 22. Discriminator 1Bias 0.25*1 +1*(-1) +0.5*(-1) +0.75*1 -1 -0.5σ( ) 0.25 1 0.5 0.75 = 0.37 +1 -1 +1 -1 -1
  23. 23. Building the Generator
  24. 24. Building the generator Faces Noise 1 0 0 1 0.25 1 0.5 0.75 Big Big small small any any any any
  25. 25. Generator 0.85 0.15 0.15 0.85 Bias 1 -1 +1 -1 -1 +1 +1 +1 -1 z 0 1 0.7 +1*0.7 + 1 +1*0.7 + 1 -1*0.7 - 1 -1*0.7 - 1 1.7 -1.7 -1.7 1.7 σ( ) σ( ) σ( ) σ( ) = 0.85 = 0.15 = 0.85 = 0.15
  26. 26. The training process: Error functions
  27. 27. Log-loss error function Label: 1 Prediction: 0.1 Error: large Label: 1 Prediction: 0.9 Error: small −ln(0.1) = 2.3 −ln(0.9) = 0.1 Error = -ln(prediction)
  28. 28. Log-loss error function Label: 0 Prediction: 0.1 Error: small Label: 0 Prediction: 0.9 Error: large −ln(0.1) = 2.3 −ln(0.9) = 0.1 Error = -ln(1 - prediction)
  29. 29. Summary If we want a prediction to be 1: Log-loss = -ln(prediction) y = − ln(x) High error Low error
  30. 30. Summary If we want a prediction to be 0: Log-loss = -ln(1-prediction) y = − ln(1 − x) High error Low error
  31. 31. The training process: Backpropagation
  32. 32. Backpropagation Error Prediction
  33. 33. Backpropagation Error Prediction Error plot
  34. 34. Training the generator and the discriminator
  35. 35. σ 1 Bias z σ σ σ σ 1 z 0 1 0.25 1 0.5 0.75 0.68 Want 0 Error = -ln(1-0.68) Want 1 Error = -ln(0.68) Generated image Bias Generator Discriminator −ln (D(G(z))) −ln (1 − D(G(z)))
  36. 36. σ 1 Bias 0.44 Error = -ln(0.44) 1 0 0 1 Real image Want 1 Discriminator 0 z σ σ σ σBias 1 z 1 Generator −ln (D(x))
  37. 37. Repeat many times…
  38. 38. σ 1 Bias z σ σ σ σBias 1 z 0 1 Generator Discriminator
  39. 39. σ 1 Bias z σ σ σ σBias 1 z 0 1 1 0 0 1 Real image Generator Discriminator
  40. 40. After many of these iterations (epochs)
  41. 41. σ 1 Bias z σ σ σ σBias 1 z 0 1 Generator Discriminator 0.7 0.6 0.8 0 -0.5 2.5 2.8 -3.4 -2.9 -0.3 -0.4 0.4 -0.9
  42. 42. z σ σ σ σBias 1 Generator z 0 1
  43. 43. Math and Code www.github.com/luisguiserrano/gans
  44. 44. Discriminator 1 0 0 1 w1 w2 w4 w3 1 b Bias σ x1 x2 x3 x4 Prediction D(x) = σ(x1w1+x2w2+x3w3+x4w4 + b) ∂E ∂wi = ∂E ∂D ⋅ ∂D ∂wi Loss function (error) from images E = − ln(D(x)) = −1 D(x) ⋅ σ( 4 ∑ j=1 xjwj + b)[1 − σ( 4 ∑ j=1 xjwj + b)]xi = −1 D(x) ⋅ D(x)[1 − D(x)]xi Derivatives ∂E ∂b = ∂E ∂D ⋅ ∂D ∂b = − [1 − D(x)] = − [1 − D(x)]xi
  45. 45. Discriminator 0.25 1 0.5 0.75 w1 w2 w4 w3 1 b Bias σ x1 x2 x3 x4 ∂E ∂wi = ∂E ∂D ⋅ ∂D ∂wi Loss function (error) from noise E = − ln(1 − D(x)) = 1 1 − D(x) ⋅ σ( 4 ∑ j=1 xjwj + b)[1 − σ( 4 ∑ j=1 xjwj + b)]xi = 1 1 − D(x) ⋅ D(x)[1 − D(x)]xi Derivatives ∂E ∂b = ∂E ∂D ⋅ ∂D ∂b = D(x) Prediction D(x) = σ(x1w1+x2w2+x3w3+x4w4 + b) = D(x)xi
  46. 46. Generator Predictions G(z) = (G1, G2, G3, G4) ∂E ∂wi = ∂E ∂D ⋅ ∂D ∂G ⋅ ∂G ∂z Loss function (error) E = − ln(D(G(z)) Derivatives = −1 D(G(z)) ⋅ σ( 4 ∑ j=1 Giwi + b)[1 − σ( 4 ∑ j=1 Giwi + b)]G(z) ⋅ σ(wiz + bi)[1 − σ(wiz + bi]z = −1 D(G(z)) ⋅ D(G(z))[1 − D(G(z))] ⋅ Gi(1 − Gi)z = (σ(v1z+c1), σ(v2z+c2), σ(v3z+c3), σ(v4z+c4)) D(G(z)) = σ(G1w1 + G2w2 + G3w3 + G4w4 + b) = − [1 − D(G(z))] ⋅ Gi(1 − Gi)z Biases 1 z v1 v2 v4 v3 c1 c2 c4 c3 σ σ σ σ G1 G2 G3 G4 ∂E ∂b = − [1 − D(G(z))] ⋅ Gi(1 − Gi)
  47. 47. Error function plots
  48. 48. Acknowledgements
  49. 49. With a little help from my friends… Sahil Juneja @sjuneja90 Diego Gomez Mosquera https://medium.com/@diegoalejogm Alejandro Perdomo @aperdomoortiz
  50. 50. https://medium.com/@diegoalejogm
  51. 51. Conclusion
  52. 52. https://www.manning.com/books/grokking-machine-learning Discount code: serranoyt Grokking Machine Learning By Luis G. Serrano
  53. 53. Thank you! @luis_likes_math Subscribe, like, share, comment! youtube.com/c/LuisSerrano http://serrano.academy

×