This project implements a Generative Adversarial Network (GAN) to automatically colorize grayscale landscape images. The model learns to generate visually pleasing color versions of black-and-white images using paired grayscale and color training data.
- The model is trained on a dataset of landscape images consisting of paired grayscale and color images.
- Images are resized to 128×128 pixels for efficient training.
- Dataset source: https://www.kaggle.com/datasets/theblackmamba31/landscape-image-colorization
- Generator: A convolutional encoder-decoder network with skip connections (similar to U-Net) that takes a grayscale image as input and outputs a 3-channel RGB color image.
- Discriminator: A convolutional PatchGAN classifier that distinguishes between real color images and those generated by the generator.
- Loss Functions:
- GAN loss encouraging the generator to produce realistic images.
- L1 loss (mean absolute error) to enforce pixel-level similarity between generated and real images.
- Framework: TensorFlow 2.x and Keras API
- Optimizers: Adam with learning rate 2e-4 and beta1=0.5 for both generator and discriminator
- Batch Size: 32
- Number of Epochs: 20 (modifiable)
- Image preprocessing includes normalization to [0,1].
- You need a Kaggle account to download the dataset using the Kaggle API.
- Download your Kaggle API key (
kaggle.json) from your Kaggle account:- Go to Kaggle Account
- Scroll down to "API" section and click Create New API Token
- This will download
kaggle.jsonfile to your computer.
- Upload
kaggle.jsonfile to your Colab environment. - Set up Kaggle API and download the dataset
- Run your training and evaluation scripts as per the notebook or script provided.
- Google Colab provides free access to GPU runtime (Tesla T4/P100/K80) which significantly speeds up training deep learning models.
- To enable GPU:
- Go to Runtime > Change runtime type in Colab
- Select GPU as hardware accelerator
- Note:
- GPU sessions are limited to approximately 12 hours and may disconnect after periods of inactivity.
- You can restart the runtime and run your notebook again; however, you may need to re-download datasets and reload/save your model.
- Colab’s runtime environment is ephemeral — files and models stored in
/contentwill be deleted after disconnect or idle timeout. - To preserve your trained models and data, consider mounting your Google Drive and saving/loading from there.
- Each time you restart, your environment (dataset, models) needs to be set up again (downloaded or loaded from Drive).