In the previous tasks of the project, you have learned how to build and train neural networks to classify images. In this question, you will explore a different type of neural network architecture, called Generative Adversarial Networks (GANs), that can be used to generate images (often called deep fakes).
GANs are composed of two neural networks, a generator and a discriminator, that are trained together in an adversarial way. The generator takes as input a random noise vector and generates an image, while the discriminator takes as input an image classifies it as real (from the training set) or fake (generated by the generator). The generator is trained to fool the discriminator, while the discriminator is trained to correctly classify real and fake images.
GAN (Generative Adversarial Network) methodology has previously been used to produce deepfakes capable of deceiving people. By studying GANs in this project, we do not endorse or encourage such deceptive applications. On the contrary, training a robust discriminator represents one promising avenue for automating the detection of fake images — illustrating how the min-max framework at the heart of GAN learning reflects an ongoing race between generation and detection.
Students should be fully aware of this broader context and are under no circumstances encouraged to misuse these techniques. Any such misuse would be their sole responsibility and may carry serious legal consequences.
You can load the data with the following code snippet. Note that, for this task, you will only need the training images, and not the labels. You may also load the test images to assess the quality of your discriminator.
x_train = np.load("p4_2026_svhn_train.npz")["images"].transpose(3, 0, 1, 2)
x_test = np.load("p4_2026_svhn_test.npz")["images"].transpose(3, 0, 1, 2)
INGInious