Review: Make your first GAN with Pytorch

Please note: As an Amazon Associate I earn from qualifying purchases.

Summary

The first time I learned that computers could create novel media was when I randomly found out about fractals. What were these strange shapes? I was amazed and quickly got a fractal wallpaper but didn’t explore much further. However, during this year, I became aware of content generation using machine learning! For example, researchers were able to generate human faces that didn’t even exist ? I was astounded.

What was this GAN they kept mentioning? How did they work? Even I couldn’t tell the difference between the fake and the real faces. Would I ever be able to trust my eyes again? Whilst I didn’t know how to resolve the trust issue, I wondered…could I create my own? Where would I start so I could make my own faces? My curiosity was piqued but I was stumped. How was I to enter this world of creative potential? Fortunately, algorithms are pervasive increasingly on point and Make your first GAN with Pytorch by Tariq Rashid surfaced on my Kindle recommendations; I could finally discover more!

With a mixture of excitement and uncertainty, I began tentative steps forward. Would my high expectations be met? Would I be able to understand the fundamentals of this model? Could I really learn enough Pytorch from this book to create something new? With the benefit of having completed this wonderful book, I’m glad to say that my expectations were exceeded, I have the intuition about how GANs work and I learned the basics of Pytorch! I even generated human faces!

You might be wondering by this point…what exactly is a GAN? Well, let’s break it down. Firstly, GAN stands for generative adversarial network. GANs are a type of machine learning model based on neural networks that can generate completely new data. For example, new faces that don’t exist or new artwork that’s never been seen before. With GANs being a relatively novel model, I’d say Tariq’s Make your first GAN with Pytorch is the best entry-level book that introduces you to creative machine learning, generative adversarial networks and Pytorch in a clear, explorative and fun way!

Evaluation


The book assumes familiarity with the fundamentals of neural networks and programming in python. With this foundation, you should be able to work each of the parts which take you from novice to GAN creator! Part 1 deals with the basics of Pytorch, Part 2 introduces the architecture of GANs and Part 3 extends this understanding with customisations to GANs for higher quality and and more targeted data generation! Throughout the book, the actual code is shown and explained thoroughly to make sure you can follow along on your own computer. This helps immensely in helping you translate the concepts into working models. There is also a github repo and website for the book which you can refer to as well.

For the projects, we get to use google’s colaboratory platform for hosting our code and running our models. With the recommended free tier, I was able to complete each of the mini-projects explored in the book:

  • MNIST classifier using Pytorch
  • GAN to make a simple 1010 pattern
  • GAN to produce handwritten digits similar to those in the MNIST dataset
  • Fully connected GAN to create human faces based on Celeb A dataset
  • Convolutional GAN to make more realistic human faces
  • Conditional GAN to make handwritten digits of a specific class

I really enjoyed how concepts were introduced gradually so that you could use them in the next project. The diagrams which are spread throughout the book helped massively in helping to impart intuition of tricky concepts ?? Furthermore, I was highly motivated by seeing my skill with Pytorch improving with each crafted model. I especially loved the moments where I was able to make connections between the diagrams and the accompanying code translation.

I was most excited when I’d start training a model then come back to see how a change in architecture e.g. activation function, loss function, layers etc impacted the generated output. When I created my first faces, I felt like I’d discovered a powerful digital paintbrush that worked with data as the paint!

Reflecting further, what kind of things did I glean from the above projects? Quite a lot actually! I learned:

  • Basics of Pytorch e.g. tensors, computational graphs, gradients, data loaders, cuda, etc
  • How to explore data with numpy, pandas and matplotlib to help build understanding
  • Combining neural network components together e.g layers, activation functions, loss functions, optimisers
  • Training neural networks e.g. basic tracking, plotting loss, performance, memory
  • Fundamentals of generative adversarial networks e.g. generator, discriminator, seeds, mode collapse
  • Convolutional neural network basics e.g. convolutional filters, kernels, stride, feature maps
  • And more!

Interested in my working code? Feel free to have a look at my github repo.

Recommendation

With the knowledge I gained from my exploration, I can confidently say I’m one step closer to becoming an artificial intelligence researcher. I have gained exposure to novel neural architectures, started learning how to use my first deep learning framework and learned the principles behind the cutting edge of machine learning creativity. Would I recommend the book? Absolutely! As long as you have the prerequisite knowledge then you’re ready for this fun adventure ? What do you need  to start?  Basics of neural networks, python programming and most importantly the desire to experiment with cool ideas! I’ve linked to courses which can help you learn the prerequisites below. Do you also want to learn how to use Pytorch to make GANs? Want your own copy of the book? Get it from Amazon here.

Resources

Bookmark the permalink.

One Comment

  1. Pingback: Machine learning scholar adventure: Chapter 2 - Azuremis

Leave a Reply

Your email address will not be published. Required fields are marked *