GAN Sketch to Image Model

TorchScript generator weights for sketch-to-image synthesis.

Overview

Optimized conditional Generative Adversarial Network (cGAN) framework for efficient sketch-to-image translation, specifically designed to support rapid visual prototyping in creative and industrial applications. Built as an enhanced variant of the Pix2Pix architecture.

Architecture

  • Generator: U-Net-based generator with skip connections
  • Discriminator: Spectral normalization-enhanced PatchGAN discriminator
  • Loss function: Composite loss combining adversarial loss, L1 pixel-wise reconstruction loss (λ=100), and VGG19 perceptual loss (weight 10)
  • Input resolution: 256 × 256 RGB
  • Framework: PyTorch

Training Enhancements

  • Data augmentations: Geometric flip/rotation (horizontal flip 50%, random rotation −5° to +5° at 30%) and sketch-specific noise injection (Gaussian + salt-and-pepper noise applied to sketch channel)
  • Stability techniques: Spectral normalization, gradient clipping, learning rate scheduling, train-validation split, and early stopping
  • Optimizer: Adam with label smoothing (real: 0.9, fake: 0.1)
  • Generator updates: 2 steps per discriminator step

Dataset

  • Source: Kaggle (kagglehub) — Sketch 2 Real Image (arsyadmuhammad/edge-2-real-image)
  • Content: Paired sketch-real fashion images across 7 categories (tops, bottoms, sandals, shoes, bags, glasses, watches)
  • Size: ~3,500+ paired images (subset used)
  • Preprocessing: Resize to 256 × 256 (cubic interpolation via OpenCV), BGR → RGB conversion, normalization to range [−1, 1]
  • Training hardware: Google Colab T4 GPU (12 GB VRAM)

Evaluation Metrics (Validation Set)

Metric Our Model Typical Reported Range Assessment
Avg L1 Loss 0.1218 0.15 – 0.25 Significant Good
Avg Perceptual Loss 0.8495 0.9 – 1.5 Slightly low
LPIPS 0.1817 0.20 – 0.30 Good
FID Score 103.85 45 – 170+ Moderate
Avg PSNR 17.98 dB 15 – 20 dB Good
Avg SSIM 0.7901 0.65 – 0.82 Very Good

Key Results

  • Strong structural preservation and perceptual realism
  • Realistic colorization and texture preservation even from noisy or varied input sketches
  • Stable training and faster convergence compared to standard Pix2Pix implementations
  • Effective distributional alignment between generated and real images (low FID)

Usage

Inference with PyTorch

import torch
from torchvision import transforms
from PIL import Image

# Load TorchScript generator
generator = torch.jit.load("generator.pt")
generator.eval()

# Preprocess input sketch
transform = transforms.Compose([
    transforms.Resize((256, 256)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])

sketch = Image.open("sketch.jpg").convert("RGB")
input_tensor = transform(sketch).unsqueeze(0)

# Generate photorealistic image
with torch.no_grad():
    fake_image = generator(input_tensor)

# Denormalize from [-1, 1] to [0, 1] and save
fake_image = fake_image * 0.5 + 0.5
transforms.ToPILImage()(fake_image.squeeze(0).clamp(0, 1)).save("output.jpg")

Applications

-Summary of Major Findings: The aforementioned metrics show effective structural preservation, perceptual realism, and reasonable distributional alignment between generated and real images. Qualitative results further confirmed the model’s ability to produce visually plausible photorealistic outputs from input sketches, even with added noise and geometric variations. The inclusion of targeted data augmentations, gradient clipping, learning rate scheduling, and early stopping contributed to stable training and improved generalization.

-Research Gaps Resolved: The work bridges several research gaps in traditional pix2pix-style models, including training instability, lack of robustness to sketch variations, and lower perceptual quality. Through spectral normalization, augmentations, and multi-objective loss optimization, the proposed model achieves better robustness and quality than standard implementations, while remaining computationally practical for prototyping tasks.

-Features and Future Enhancements: The current model accepts input at 256 × 256 pixel resolution; the model can be trained for higher quality images. The noise level is currently 1% and can be bumped up. Large-scale human perceptual studies can be included in evaluation.

-Scalability in Real-World Applications: In industrial settings, it could support rapid product prototyping, concept art generation, or virtual prototyping in automotive and fashion domains. Challenges related to computational cost at scale can be resolved through model compression, quantization, or cloud-based inference. With further improvements in efficiency, this technology has strong potential to become a standard tool in AI-assisted creative tasks.

Links

Files

generator.pt: Main TorchScript generator model

References

[1] Image-to-Image Translation with Conditional Adversarial Networks, Phillip Isola, Jun-Yan Zhu, 2016

[2] Donoso, D., et al. (2023). Survey on Sketch-to-photo Translation. ACM Computing Surveys.

[3] Zhao, X., et al. (2023). Image to Image Translation Based on Differential Image Pix2Pix Model. Computers, Materials & Continua.

[4] Shetty et al. (2022). Face Sketch to Image Generation Using Pix2Pix GAN.

[5] Handorfer, E. M. (2024). "From Sketches To Paintings": Image-to-Image Translation using Generative Adversarial Networks.

Usage Note

The Space downloads this model automatically at runtime when the local file is missing.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support