Skip to content

An application to convert rough sketches into an equivalent photorealistic versions. Runs locally with low overhead.

License

Notifications You must be signed in to change notification settings

Cosmic-Infinity/draw2pix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

47 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

draw2pix

Near real-time conversion for sketches into flower drawings using pix2pix GAN ๐ŸŽจ โ†’ ๐ŸŒธ

Transform rough sketches of flowers into photorealistic images through an interactive web interface. Built on the pix2pix architecture and trained on a custom dataset of 9.5k+ curated flower images.

License: MIT Python 3.8+ PyTorch


โœจ Features

  • ๐Ÿ–Œ๏ธ Interactive Drawing Canvas - Draw sketches directly in your browser
  • โšก Near real-time Inference - See results instantly (GPU: ~100ms, CPU: ~1-2s)
  • ๐ŸŽจ Multiple Variations - Generate up to 4 different outputs from one sketch with diversity and noise strength settings
  • ๐Ÿ”„ Model Switching - Load and switch between multiple trained models at runtime
  • ๐Ÿ“ฅ Auto-Updates - Automatically downloads pretrained models from GitHub releases
  • ๐Ÿ” Auto-Detection - Intelligently reads model parameters from binaries

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10.x

Installation [Windows/Linux/Mac]

  1. Clone the repository

    git clone https://github.com/Cosmic-Infinity/draw2pix.git
    cd draw2pix
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the web application

    # Windows
    start.bat
    
    # Linux/Mac
    python app/web_app.py --model_dir pretrained_models
  4. Open your browser

    http://127.0.0.1:5000
    

๐Ÿ“ธ Screenshots

Web Application UI Application interface

Sample Usage Application in use

Sample Outputs

Input Sketch Generated Output
Sketch 1 Generated 1
Sketch 2 Generated 2

Drawing and their corresponding transformation samples

Training result samples [Model: Flower 15]

Input Sketch Generated Output Ground Truth
Epoch 187 Input Epoch 187 Generated Epoch 187 Ground Truth
Epoch 193 Input Epoch 193 Generated Epoch 193 Ground Truth

Training validation samples showing model's ability to generate realistic flower images from sketches


๐ŸŽฏ Usage

Web Interface

  1. Draw your sketch on the sketch canvas using your mouse or stylus
  2. Click "Generate" (or leave Auto-Generate ON) to convert your sketch to a photo
  3. Adjust settings (optional):
    • Enable/Disable Dropout
    • Perturbation strength (low/medium/high)
  4. Clear the canvas to start over or save your results

Command Line Options

python app/web_app.py [options]

Options:
  --model_dir       Directory containing .pth model files (default: pretrained_models)
  --input_nc        Input channels: 1 for grayscale, 3 for RGB (default: 1)
  --output_nc       Output channels: 3 for RGB (default: 3)
  --port            Port to run server on (default: 5000)
  --host            Host to run server on (default: 127.0.0.1)

๐Ÿ—๏ธ Project Structure

draw2pix/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ index.html              # Frontend interface
โ”‚   โ”œโ”€โ”€ web_app.py              # Flask backend application
โ”‚   โ””โ”€โ”€ test_setup.py           # Setup verification script
โ”œโ”€โ”€ pretrained_models/          # Trained model weights (.pth files)
โ”‚   โ”œโ”€โ”€ *.pth                   # Model binaries (15 models)
โ”‚   โ”œโ”€โ”€ version.txt             # Version tracking for updates
โ”‚   โ””โ”€โ”€ MODELS_RELEASE.md       # Model release notes
โ”œโ”€โ”€ pix2pix/                    # Pix2pix framework (PyTorch-CycleGAN-pix2pix)
โ”‚   โ”œโ”€โ”€ models/                 # Model architectures (networks, base model)
โ”‚   โ”œโ”€โ”€ options/                # Configuration options (base, test)
โ”‚   โ”œโ”€โ”€ data/                   # Data loading utilities
โ”‚   โ”œโ”€โ”€ util/                   # Helper functions
โ”‚   โ”œโ”€โ”€ train.py                # Training script
โ”‚   โ”œโ”€โ”€ test.py                 # Inference script
โ”‚   โ””โ”€โ”€ THIRD_PARTY_LICENSES.txt
โ”œโ”€โ”€ docs/                       # Comprehensive documentation
โ”‚   โ”œโ”€โ”€ WEB_APP_README.md       # Web app usage guide
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md         # System architecture details
โ”‚   โ”œโ”€โ”€ MODEL_REFERENCE.md      # All 15 trained models reference
โ”‚   โ””โ”€โ”€ RELEASE_GUIDE.md        # Release creation guide
โ”œโ”€โ”€ Progress Tracker/           # Training logs and progress
โ”‚   โ”œโ”€โ”€ Shubham.md              # Model training tracker
โ”‚   โ”œโ”€โ”€ Sourajit.md             # Frontend development tracker
โ”‚   โ””โ”€โ”€ train_graphs/           # Training visualization graphs
โ”œโ”€โ”€ flowers Dataset/            # Custom curated dataset (9.5k images)
โ”œโ”€โ”€ screenshots/                # Application screenshots & samples
โ”œโ”€โ”€ UI Design/                  # UI mockups and designs
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ start.bat                   # Quick start script (Windows)
โ””โ”€โ”€ LICENSE                     # MIT License

๐Ÿ”ฌ Model Details

Architecture

  • Base: pix2pix (Conditional GAN)
  • Generator: U-Net-256 or ResNet-9blocks
  • Discriminator: PatchGAN (Basic)
  • Input: 256ร—256 grayscale sketches (1 or 3 channel)
  • Output: 256ร—256 RGB images (3 channels)
  • Training Dataset: 9.5k curated flower image pairs

Available Pretrained Models (15 Total)

All models are automatically downloaded via start.bat or available from GitHub Releases.

Model Architecture Epochs Time LR ฮป_L1 Batch Notes
U256_Flower_1 UNet-256 300 14h 4m 0.0002 100 85 Discriminator flatline
U256_Flower_2 UNet-256 150 2h 31m 0.00015 100 72 Good discriminator stability
U256_Flower_3 UNet-256 200 3h 13m 0.0002 50 70 Low ฮป_L1
U256_Flower_4 UNet-256 250 9h 18m 0.0001 50 70 Low learning rate
U256_Flower_5 UNet-256 100 3h 44m 0.00025 65 70 Quick training
U256_Flower_6 UNet-256 250 9h 19m 0.00022 85 70 Severe collapse
U256_Flower_7 UNet-256 50 1h 53m 0.0008 85 70 High LR experiment
U256_Flower_8 UNet-256 75 2h 48m 0.0015 85 70 Extreme LR
U256_Flower_9 UNet-256 120* 13h 8m 0.0002 100 1 Batch size = 1
U256_Flower_10 UNet-256 210* 22h 18m 0.0002 80 1 Batch size = 1
U256_Flower_11 UNet-256 200 20h 56m 0.0004 100 1 Label smoothing + noise
U256_Flower_12 UNet-256 200 7h 39m 0.0003 100 32 Regularization techniques
R9_Flower_13 ResNet-9 50* 7h 15m 0.0032 100 16 High LR instability
R9_Flower_14 ResNet-9 107* 15h 39m 0.0002 75 8 LSGAN + no dropout
U256_Flower_15 UNet-256 200 21h 16m 0.0002 100 1 RGB input (experimental)

* = Training stopped early

๐Ÿ“˜ For detailed training commands and loss curves, see docs/MODEL_REFERENCE.md


๐Ÿ› ๏ธ Technical Stack

Backend

  • Flask - Web framework
  • PyTorch - Deep learning framework
  • torchvision - Image transformations
  • Pillow - Image processing
  • NumPy - Numerical operations

Frontend

  • HTML5 Canvas - Drawing interface
  • Vanilla JavaScript - No framework dependencies
  • CSS3 - Modern styling with gradients and animations

Model

  • Input: 256ร—256 grayscale sketch
  • Output: 256ร—256 RGB photorealistic image
  • Inference Time: ~100ms (GPU) / ~1-2s (CPU)

๐Ÿ“– Documentation


๐ŸŽ“ Training Details

The models were trained on a custom dataset of flower images with the following characteristics:

  • Dataset Size: 9.5k manually curated image pairs (cleaned from original 12.5k)
  • Resolution: 256ร—256 pixels
  • Format: Aligned paired images (sketch | photo)
  • Hardware: NVIDIA A2000 12GB GPU. courtesy IoT Lab, KIIT
  • Framework: PyTorch with pix2pix implementation
  • Training Time: 50-300 epochs (1h 53m to 22h 18m per model)
  • Total Experiments: 15 model variants with different hyperparameters

Training Challenges

Training GANs proved inherently complex due to adversarial dynamics. Key observations:

  • Discriminator Collapse: Persistent flatlining of discriminator losses across most models
  • GAN Instability: Multi-objective optimization creates non-convex landscape
  • Data Quality: Edge thickness inconsistencies and natural lighting variations
  • Color Bias: Dataset overrepresentation of yellow/white flowers

๐Ÿ“Š For complete training details and analysis, see docs/MODEL_REFERENCE.md and Progress Tracker/Shubham.md


๐Ÿค Contributing

This is an academic project. For questions or suggestions:

  1. Open an issue on GitHub
  2. Check existing documentation
  3. Review the Progress Tracker for known limitations

๐Ÿ“ License


โš ๏ธ Known Limitations

  • Output quality varies based on sketch complexity.
  • Some models may show bias towards yellow/white flowers. Probable overfitting.
  • Texture details may appear stylized rather than photorealistic
  • Some models may provide best results with clear, simple flower sketches
  • Dropout may drastically improve output in some instances, while ruining colours/texture in others.

๐Ÿ”ฎ Future Improvements?

  • Expand dataset with more diverse flower colors and species
  • Experiment with higher resolution models (512ร—512) and upscaling techniques
  • Test alternative loss functions (Wasserstein GAN, Hinge loss)
  • Add progressive rendering? for better UX on slower hardware
  • Implement model quantization for faster CPU inference
  • Mobile-responsive UI for tablet/phone drawing

๐Ÿ‘ฅ Team

A project made in collaboration

Shubham
Shubham
๐ŸŽ“ Model Training
๐Ÿ—๏ธ System Architecture
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Sourajit
Sourajit
๐ŸŽจ Frontend and Design
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Tanmay
Tanmay
๐Ÿ•ท๏ธ Web Scraping
๐Ÿ”ง Data Preprocessing
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Shivam
Shivam
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Alok
Alok
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Snigdha
Snigdha
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Upasana
Upasana
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Urshita
Urshita
๐Ÿ“Š Dataset Curation
๐Ÿ“ Report & Presentation
Ankit
Ankit


Abhijeet
Abhijeet



About

An application to convert rough sketches into an equivalent photorealistic versions. Runs locally with low overhead.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •