This section covers the steps required to download and prepare the dataset for training the GAN model.
- Install Kaggle Library: The Kaggle library is installed using
pip install kaggle. - Upload Kaggle API Key: The user is prompted to upload the
kaggle.jsonfile. - Move Kaggle API Key: The API key is moved to
~/.kaggle/and permissions are set. - Download Dataset: The dataset
pretty-faceis downloaded from Kaggle. - Extract Dataset: The downloaded ZIP file is extracted to a folder.
- Verify Dataset: The extracted files are listed to confirm successful extraction.
This section involves loading and processing images into a format suitable for training.
- Load Image using OpenCV: A sample image is loaded and displayed using
cv2_imshow. - Resize Image: The image is resized to
(256,256)using OpenCV. - Convert Images to NumPy Array:
- Images from the dataset folder are loaded using Pillow (PIL).
- Images are converted to RGB and resized to
(64,64). - Images are stored as a NumPy array for efficient processing.
- Check Array Shape: The final dataset shape is printed for verification.
This section covers defining, compiling, and training the Generative Adversarial Network (GAN).
- Define Generator Model: A deep learning model is created to generate
64x64x3images from random noise. - Define Discriminator Model: A convolutional neural network (CNN) is built to classify images as real or fake.
- Define GAN Model: The Generator and Discriminator are combined into a GAN model.
- Compile Models:
- The Discriminator is compiled using
binary_crossentropyloss. - The GAN is compiled using an Adam optimizer.
- The Discriminator is compiled using
- Normalize Dataset: The images are normalized to the range
[-1,1]for better training. - Train the GAN:
- The Discriminator is trained on real and fake images.
- The Generator is trained to improve image quality.
- Training progress is displayed every few epochs.
- Save and Display Generated Images: Every few epochs, sample images generated by the GAN are saved and displayed.
- Run Training: The GAN training process is executed for 500 epochs.
- The model will generate face-like images based on the dataset.
- Over time, the generated images should become more realistic.
- The training process may take around an hour on a T4 GPU.
- Adjusting hyperparameters (learning rate, batch size, etc.) can improve results.
- Ensure the dataset is properly downloaded before running the GAN training.
Author: [Sumit Modanwal]
Date: [17 January 2025]
