Skip to content

ShubhamKNIT/DeepRazor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DeepRazor: AI-Powered Object Removal Tool

Streamlit App Demo Video

Remove unwanted objects from photos with AI - No coding required!

DeepRazor makes professional photo editing accessible to everyone. Simply upload your image, mark what you want to remove, and let our AI seamlessly fill in the background. Perfect for social media, real estate, e-commerce, or just cleaning up your personal photos.


🎯 For Users: Get Started in 2 Minutes

What DeepRazor Can Do

  • 🎨 Remove Any Object: People, cars, text, unwanted items - anything!
  • πŸ–ŒοΈ Smart Background Fill: AI automatically reconstructs what was behind the object
  • πŸš€ Multiple Ways to Select: Draw masks manually or let AI detect objects automatically
  • πŸ’» Web Interface: No coding needed - just point, click, and download
  • ⚑ Fast Results: Get professional results in seconds

Quick Start (Zero Setup Required)

# 1. Clone and install
git clone https://github.com/ShubhamKNIT/DeepRazor.git
cd DeepRazor
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Only for Linux/Ubuntu 
sudo apt-get update
sudo apt-get install freeglut3-dev libgtk2.0-dev

# 2. Launch the app
cd Deployment
streamlit run app.py

# 3. Open http://localhost:8501 in your browser and start editing!

🎭 Four Easy-to-Use Tools

Tool What It Does Best For
πŸŽ“ How to Use Interactive tutorial with demo video First-time users
✏️ Draw Mask Manually draw what to remove Precise selection, complex shapes
🎯 YOLO Detection AI detects mask of 80+ object types automatically Common objects (people, cars, animals)
🎨 Inpaint Anything Upload image + mask for instant results Quick masked object removal

Supported File Types

  • Input: JPG, JPEG, PNG images
  • Output: High-quality PNG images
  • Mask: PNG images (black = keep, white = remove)

πŸ’Ό For Developers: Integration & Customization

Python API Usage

from inpaint_anything_predicts import make_inference

# Basic usage
image_bytes = open("photo.jpg", "rb").read()
mask_bytes = open("mask.png", "rb").read()
result = make_inference(image_bytes, mask_bytes, "onnx_gen_models/ia_gen_39.onnx")

# Save result
with open("result.png", "wb") as f:
    f.write(result)

Project Structure

DeepRazor/
β”œβ”€β”€ Deployment/                         # 🌐 Web Application
β”‚   β”œβ”€β”€ app.py                         # Main Streamlit app
β”‚   β”œβ”€β”€ how_to_use.py                  # Tutorial page
β”‚   β”œβ”€β”€ draw_mask.py                   # Manual mask drawing
β”‚   β”œβ”€β”€ segment_anything.py            # YOLO object detection
β”‚   β”œβ”€β”€ inpaint_anything.py            # Core inpainting interface
β”‚   └── onnx_gen_models/               # Pre-trained models
β”‚       β”œβ”€β”€ ia_gen_10.onnx ... ia_gen_59.onnx
β”‚       └── run_onnx.py                # ONNX inference
β”œβ”€β”€ InpaintingModule/                   # πŸ”¬ Research & Training
β”‚   β”œβ”€β”€ train.py                       # Training entry point
β”‚   β”œβ”€β”€ test.py                        # Testing entry point
β”‚   β”œβ”€β”€ validate.py                    # Validation entry point
β”‚   β”œβ”€β”€ src/dataset/                   # Dataset preparation scripts
β”‚   β”œβ”€β”€ src/model/                     # Model architectures
β”‚   β”œβ”€β”€ src/utils/                     # Training utilities
β”‚   └── Logs and Results               # Training Logs and Results
└── requirements.txt                    # Dependencies

πŸ”¬ For Researchers: Technical Architecture & Training

Model Architecture Overview

DeepRazor implements a two-stage Generative Adversarial Network using Contextual Residual Aggregation (CRA):

Input Image + Mask
       ↓
Coarse Generator (256Γ—256) β†’ Coarse Inpainting
       ↓
Refinement Generator (512Γ—512) β†’ Final Result
       ↓
Discriminator β†’ Quality Assessment

Key Technical Innovations

1. Two-Stage Generator Design

  • Coarse Generator: Fast 256Γ—256 initial inpainting with gated convolutions
  • Refinement Generator: High-quality 512Γ—512 enhancement with contextual attention
  • Progressive Training: Coarse stage first, then joint refinement training

2. Advanced Components

  • Gated Convolutions: Dynamic feature selection based on mask validity
  • Contextual Attention Module (CAM): Transfers context from valid to masked regions
  • Multi-Scale Dilated Blocks: Capture context at rates [1, 2, 4, 8, 16]
  • Swin Transformer Integration: Global context modeling in final training epochs (experimental)

3. Comprehensive Loss Design

# Coarse Stage
L_coarse = Ξ»_L1 * L1_loss + Ξ»_FFT * Fourier_loss + Ξ»_TV * TV_loss

# Refinement Stage  
L_refine = Ξ»_L1 * L1_loss + Ξ»_FFT * Fourier_loss + Ξ»_adv * Adversarial_loss + 
           Ξ»_perceptual * VGG_loss + Ξ»_FM * Feature_matching_loss

# Discriminator
L_disc = Hinge_loss + Gradient_penalty

Dataset Information (RORD)

  • Source: Real-world Object Removal Dataset
  • Size: 236GB original β†’ 41.5GB prepared subset
  • Training: ~24K high-quality triplets [Image, Mask, Ground Truth]
  • Validation: ~4K instances for evaluation
  • Resolution: 512Γ—512 for training, supports higher resolutions

Training Your Own Models

DeepRazor Module Documentation

Detailed explanation of all core modules, functions, and architectural breakdown.

πŸ“„ Read the full Module Documentation (PDF)

Setup Training Environment

# 1. Prepare dataset
cd RORD-dataset-preparation
python prepare_dataset.py  # Follow dataset preparation guide

# 2. Configure training
cd InpaintingModule
vim env_var.py  # Set dataset paths and hyperparameters

# 3. Start training
python train.py --start_epoch 1 --num_epochs 50 --batch_size 16 --device cuda

Advanced Training Features

  • Modular Design: Easily extend or replace components
  • Mixed Precision Training: 50% memory reduction with AMP
  • Resume Training: Automatic checkpoint loading
  • Real-time Monitoring: Live loss tracking and GPU usage
  • Validation Metrics: PSNR, SSIM, FID, LPIPS evaluation
  • Result Visualization: Sample outputs saved during training

Export to ONNX

cd Deployment/onnx_gen_models
python export_to_onnx.py --chkpt_no 50 --model_path ../../InpaintingModule/checkpoints/

Performance Metrics

Metric Value Description
PSNR 21.5+ dB Peak Signal-to-Noise Ratio
SSIM 0.86+ Structural Similarity Index
FID 20-28 FrΓ©chet Inception Distance
LPIPS 0.25-0.26 Learned Perceptual Image Patch Similarity

Research Applications

  • Image Inpainting: Core inpainting research and benchmarking
  • Object Removal: Real-world object removal in natural images
  • Context Understanding: Studying contextual attention mechanisms
  • GAN Training: Advanced adversarial training techniques
  • Loss Function Design: Multi-objective optimization in computer vision

🀝 Contributing & Community

Ways to Contribute

  • πŸ› Bug Reports: Found an issue? Create a detailed bug report
  • πŸ’‘ Feature Requests: Suggest new functionality or improvements
  • πŸ”§ Code Contributions: Submit pull requests for bug fixes or features
  • πŸ“– Documentation: Improve tutorials, examples, or API docs
  • πŸŽ“ Research: Share new architectures, loss functions, or training techniques

Development Workflow

# 1. Fork and clone
git fork https://github.com/ShubhamKNIT/DeepRazor.git
git clone https://github.com/YourUsername/DeepRazor.git
cd DeepRazor

# 2. Create feature branch
git checkout -b feature/amazing-improvement

# 3. Make changes and test
pip install -r requirements.txt
# Test your changes thoroughly

# 4. Submit pull request
git commit -am "Add amazing improvement"
git push origin feature/amazing-improvement
# Create PR on GitHub

πŸ“š References & Acknowledgments

Core Research

  1. Sagong, M.-C., et al. (2022)
    RORD: A Real-world Object Removal Dataset
    BMVC 2022 - Paper

  2. Yi, Z., et al. (2020)
    Contextual Residual Aggregation for Ultra High-Resolution Image Inpainting
    arXiv:2005.09704 - Paper

  3. Yu, J., et al. (2019)
    Free-form Image Inpainting with Gated Convolution
    ICCV 2019 - Paper

Special Thanks

  • RORD Dataset creators for high-quality training data
  • Ultralytics YOLO team for object detection capabilities
  • Streamlit community for the amazing web framework
  • PyTorch and ONNX teams for ML infrastructure
  • FastSAM contributors for rapid segmentation
  • Open Source Community for inspiration and support

🎨 Turn any photo into a masterpiece - Try DeepRazor today!

Made with ❀️ by Shubham Kumar | Star ⭐ if you find this useful!