This repository contains an implementation of a CycleGAN model that transforms sketches to realistic images and vice versa. The project includes both the training code and a Flask web application for deploying the model.
This project uses a Cycle-Consistent Generative Adversarial Network (CycleGAN) architecture to learn the mapping between two domains:
- Sketches (Domain X)
- Real images (Domain Y)
The implementation features:
- Two generators: G (Sketch→Real) and F (Real→Sketch)
- Two discriminators: D_X (for Real images) and D_Y (for Sketches)
- Cycle consistency loss to ensure that the transformations are invertible
- Identity mapping loss to preserve content
- U-Net-like architecture with encoder-bottleneck-decoder structure
- Uses convolutional layers, batch normalization, and ReLU/LeakyReLU activations
- Tanh activation in the output layer
- PatchGAN discriminator architecture
- Uses convolutional layers with batch normalization and LeakyReLU
- Sigmoid activation in the output layer
The model is trained using multiple loss components:
- Identity Loss: Encourages the generator to preserve content when given an image from its target domain
- GAN Loss: Makes the generated images look realistic
- Cycle Consistency Loss: Ensures that transforming an image to the other domain and back results in the original image
- generator_G.pth # Sketch to Real generator
- generator_F.pth # Real to Sketch generator
- discriminator_D_X.pth # Real image discriminator
- discriminator_D_Y.pth # Sketch discriminator
- DataLoader configuration for batching
- Loss function setup
- Training loop with regular progress updates
- Model checkpointing
- Loss visualization
Run the following command in your terminal:
python app.py
After starting the server, navigate to http://localhost:5000 in your web browser.
The Flask application allows users to:
- Upload sketches to generate realistic images
- Upload real images to generate sketches
- View the transformation results in real-time