Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

SRGAN: 16x Image Super-Resolution

This repository implements a Super-Resolution Generative Adversarial Network (SRGAN) designed to upscale low-resolution (LR) images (96x96) to high-resolution (HR) outputs (384x384), achieving a 16x increase in total pixel area. The architecture and training methodology are based on the paper: Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network.

🚀 Overview

Traditional super-resolution methods like bicubic interpolation often result in blurry images. This SRGAN implementation utilizes Perceptual Loss (VGG-19 based) and an Adversarial Loss to recover photo-realistic textures and high-frequency details that pixel-wise loss functions (like MSE) typically fail to capture.

Key Features

  • 16x Enlargement: Upscales images from 96x96 to 384x384.
  • Residual Architecture: Generator features 8 residual blocks for deep feature extraction.
  • Pixel Shuffle Upsampling: Efficient spatial resolution enhancement.
  • Perceptual Loss: Leverages VGG-19 block5_conv4 activations to ensure structural fidelity.
  • LSGAN Loss: Uses Mean Squared Error for adversarial stability.

🏗️ Architecture

Generator

  • Input: (96, 96, 3) image.
  • Blocks: 9x9 initial convolution, 8 residual blocks with Batch Normalization and PReLU.
  • Upsampling: Two upsampling stages using a pixel-shuffle style approach to reach 384x384.
  • Output: Tanh-activated convolution for normalized pixel values.

Discriminator

  • A deep CNN utilizing strided convolutions (strides=2) to progressively downsample the 384x384 HR image.
  • Uses LeakyReLU activation and Global Average Pooling to output a single scalar realism score.

🧪 Loss Functions

The Generator is optimized using a weighted combination of two losses:

  1. Content Loss (Weight: 1.0): MSE between VGG-19 feature maps of HR and SR images.
  2. Adversarial Loss (Weight: 1e-3): Pushes the generator to produce images that reside on the manifold of real natural images.

📈 Performance & Results

The model was evaluated using Peak Signal-to-Noise Ratio (PSNR) and Structural Similarity Index (SSIM).

Metric Value
Mean PSNR 27.70 dB
Mean SSIM 0.8916
Best PSNR 31.61 dB

Results based on evaluation of a test subset within the provided notebook.

🛠️ Requirements

  • Python 3.x
  • TensorFlow 2.x
  • NumPy, Pandas, Matplotlib
  • Pillow (PIL)
  • tqdm

🚦 Usage

1. Training

The notebook supports both fresh training and resuming from checkpoints stored in Google Drive:

# To start training
train_gan_full(lr_images, hr_images, epochs=100, batch_size=4)

# To resume from a checkpoint
resume_training(lr_images, hr_images, epochs=100, batch_size=4)

2. Inference

To upscale a single image:

from tensorflow.keras.models import load_model

gen = load_model('srgan_generator.keras', compile=False)
sr_output = gen.predict(lr_input_tensor)

📁 Project Structure

  • SRGAN__Image_Enlargement.ipynb: Complete implementation including data preprocessing, model building, training loops, and evaluation.
  • checkpoints/: Directory for saving .keras model weights during training.

Note: This implementation was developed and tested on a T4 GPU environment.

About

16x Image Enlargement using a Super Resolution Generative Adversarial Network

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages