Professional image and video deblurring using NAFNet
Project description
neuro-deblur ๐
Professional image and video deblurring using NAFNet (Nonlinear Activation Free Network).
A production-ready Python package for motion deblurring with CUDA acceleration support. Perfect for enhancing blurry photos and videos with state-of-the-art deep learning.
๐ Features
- โ Image Deblurring - Restore sharp details from blurry images
- โ Video Deblurring - Process videos frame-by-frame
- โ CUDA Acceleration - GPU support for fast processing
- โ CPU Fallback - Works on systems without GPU
- โ Simple API - 3 lines of code to deblur
- โ Pre-trained Model - Ready to use out of the box
- โ Production Ready - Clean, tested, and documented
๐ฆ Installation
From PyPI (Recommended)
pip install neuro-deblur
Note: Model weights (~334 MB) will be downloaded automatically on first use.
From Source
git clone https://github.com/Parshva2605/neuro-deblur.git
cd neuro-deblur
pip install -e .
Requirements
- Python >= 3.9
- PyTorch >= 2.0.0
- CUDA (optional, for GPU acceleration)
First Use - Automatic Model Download
On first use, the model weights will be downloaded automatically:
from neuro_deblur import DeblurModel
# First time - downloads model (~334 MB, one-time only)
model = DeblurModel(device="cuda")
# Downloading model weights from GitHub...
# best_model.pth: 100% |โโโโโโโโ| 334MB/334MB [30s]
# โ Model downloaded successfully!
# Later uses - instant (uses cached model)
model = DeblurModel(device="cuda")
# โ Using cached model
Cache Location:
- Windows:
C:\Users\YourName\AppData\Local\neuro_deblur\weights\ - Linux/Mac:
~/.cache/neuro_deblur/weights/
๐ Quick Start
Deblur an Image
from neuro_deblur import DeblurModel
# Initialize model (auto-detects CUDA)
model = DeblurModel(device="cuda")
# Deblur image
model.deblur_image("blurry_photo.jpg", "sharp_photo.jpg")
Deblur a Video
from neuro_deblur import DeblurModel
# Initialize model
model = DeblurModel(device="cuda")
# Deblur video (with progress bar)
model.deblur_video("blurry_video.mp4", "sharp_video.mp4")
Process Multiple Images
from neuro_deblur import DeblurModel
# Initialize model
model = DeblurModel(device="cuda")
# Deblur all images in a folder
model.deblur_folder("input_folder/", "output_folder/")
๐ก Usage Examples
Command Line (Using Examples)
Image Processing
cd examples
python run_image.py input.jpg output.jpg
python run_image.py input.jpg output.jpg --device cpu
Video Processing
cd examples
python run_video.py input.mp4 output.mp4
python run_video.py input.mp4 output.mp4 --device cuda
Python API
Basic Usage
from neuro_deblur import DeblurModel
# Auto-detect device (prefers CUDA)
model = DeblurModel()
# Or specify device explicitly
model = DeblurModel(device="cuda") # Use GPU
model = DeblurModel(device="cpu") # Use CPU
# Deblur image
output = model.deblur_image("input.jpg", "output.jpg")
Advanced Usage
from neuro_deblur import DeblurModel
from pathlib import Path
# Use custom checkpoint
model = DeblurModel(
checkpoint_path="path/to/custom_model.pth",
device="cuda"
)
# Process without saving (get tensor)
output_tensor = model.deblur_image("input.jpg")
# Process multiple videos
video_files = Path("videos/").glob("*.mp4")
for video in video_files:
output = f"deblurred/{video.name}"
model.deblur_video(video, output)
Direct Tensor Processing
import torch
from neuro_deblur import DeblurModel
model = DeblurModel(device="cuda")
# Process tensor directly
input_tensor = torch.rand(1, 3, 256, 256) # [B, C, H, W]
output_tensor = model.process_tensor(input_tensor)
๐ฅ๏ธ GPU Support
Automatic CUDA Detection
The package automatically detects and uses CUDA if available:
# Auto-detects GPU
model = DeblurModel() # Uses CUDA if available, else CPU
# Force CPU
model = DeblurModel(device="cpu")
# Force GPU (raises error if unavailable)
model = DeblurModel(device="cuda")
Performance Benchmarks
Processing a 1920ร1080 video on RTX 3070:
| Device | FPS | Speed |
|---|---|---|
| CUDA | ~3-5 FPS | 20-30x faster |
| CPU | ~0.1-0.2 FPS | Baseline |
Recommendation: Use GPU for videos, CPU works fine for images.
๐ Model Details
NAFNet Architecture
- Paper: Simple Baselines for Image Restoration
- Architecture: NAFNet (Nonlinear Activation Free Network)
- Parameters: ~29M parameters
- Training: GoPro dataset (motion deblurring)
- Performance: 30.33 dB PSNR on validation set
Model Configuration
NAFNet(
width=32,
middle_blk_num=12,
enc_blk_nums=[2, 2, 4, 8],
dec_blk_nums=[2, 2, 2, 2]
)
๐ Project Structure
neuro_deblur/
โโโ neuro_deblur/
โ โโโ __init__.py # Public API
โ โโโ model.py # NAFNet architecture
โ โโโ inference.py # DeblurModel class
โ โโโ utils.py # Image/video utilities
โ โโโ weights/
โ โโโ best_model.pth # Pre-trained weights
โโโ examples/
โ โโโ run_image.py # Image deblurring example
โ โโโ run_video.py # Video deblurring example
โโโ setup.py # Package setup
โโโ pyproject.toml # Build configuration
โโโ requirements.txt # Dependencies
โโโ MANIFEST.in # Include data files
โโโ README.md # This file
โโโ LICENSE # MIT License
๐ ๏ธ Development
Install in Development Mode
git clone https://github.com/yourusername/neuro-deblur.git
cd neuro-deblur
pip install -e ".[dev]"
Run Tests
pytest tests/
Code Formatting
black neuro_deblur/
flake8 neuro_deblur/
๐ API Reference
DeblurModel
Main class for deblurring operations.
Constructor
DeblurModel(checkpoint_path=None, device="cuda", width=32)
Parameters:
checkpoint_path(str, optional): Path to custom checkpoint. Uses bundled weights if None.device(str): Device to use ("cuda" or "cpu"). Auto-detects if CUDA unavailable.width(int): Model width (must match training, default: 32).
Methods
deblur_image(input_path, save_path=None)
Deblur a single image.
Parameters:
input_path(str): Path to blurry imagesave_path(str, optional): Path to save output
Returns: torch.Tensor - Deblurred image tensor [1, 3, H, W]
deblur_video(input_path, output_path, show_progress=True)
Deblur a video file.
Parameters:
input_path(str): Path to blurry videooutput_path(str): Path to save outputshow_progress(bool): Show progress bar
deblur_folder(input_folder, output_folder, extensions=(...), show_progress=True)
Deblur all images in a folder.
Parameters:
input_folder(str): Input folder pathoutput_folder(str): Output folder pathextensions(tuple): Valid image extensionsshow_progress(bool): Show progress bar
process_tensor(input_tensor)
Process a tensor directly.
Parameters:
input_tensor(torch.Tensor): Input tensor [1, 3, H, W] or [3, H, W]
Returns: torch.Tensor - Deblurred tensor, clamped to [0, 1]
๐ฏ Use Cases
- Photography: Restore blurry photos (motion blur, camera shake)
- Video Enhancement: Stabilize and sharpen video footage
- Security Footage: Enhance low-quality surveillance videos
- Medical Imaging: Improve clarity of medical scans
- Autonomous Vehicles: Preprocess camera feeds
- Sports Analytics: Enhance fast-motion sports footage
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository at github.com/Parshva2605/neuro-deblur
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- NAFNet: Simple Baselines for Image Restoration
- GoPro Dataset: Motion deblurring benchmark dataset
- PyTorch: Deep learning framework
๐ง Contact
Parshva Shah - shahparshva2005@gmail.com
Project Link: https://github.com/Parshva2605/neuro-deblur
โญ Star History
If you find this project useful, please consider giving it a star! โญ
Made with โค๏ธ for the computer vision community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neuro_deblur-0.1.1.tar.gz.
File metadata
- Download URL: neuro_deblur-0.1.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac8f388543721961f4c88637949c777dde5ad559376315b5d5c54cc55f359933
|
|
| MD5 |
dae8628a9f7909913a082457efcf4f9e
|
|
| BLAKE2b-256 |
37e54430d6c3c1e1bcc77a56132db9df830a61b618ab6ea29c0a5181ad3ca71d
|
File details
Details for the file neuro_deblur-0.1.1-py3-none-any.whl.
File metadata
- Download URL: neuro_deblur-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f43e01f7492b984446de7e3b136e75437d8f89710f90eb729f312e5c212d5960
|
|
| MD5 |
22cc65f1d5675b7decb36798833f98f2
|
|
| BLAKE2b-256 |
0ac71fa54282f720562861c8fff5ffcb148506ee30826d0a540d9197de8931a6
|