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
Metadata
Release files for neuro-deblur 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neuro_deblur-0.1.1.tar.gz | 16.5 kB | Without provenance | Details for neuro_deblur-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neuro_deblur-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for neuro_deblur-0.1.1-py3-none-any.whl |
Total release size: 29.8 kB
Release files / neuro_deblur-0.1.1.tar.gz
| Download URL | neuro_deblur-0.1.1.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac8f388543721961f4c88637949c777dde5ad559376315b5d5c54cc55f359933
|
|
BLAKE2b-256 checksum How to use checksums |
37e54430d6c3c1e1bcc77a56132db9df830a61b618ab6ea29c0a5181ad3ca71d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / neuro_deblur-0.1.1-py3-none-any.whl
| Download URL | neuro_deblur-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f43e01f7492b984446de7e3b136e75437d8f89710f90eb729f312e5c212d5960
|
|
BLAKE2b-256 checksum How to use checksums |
0ac71fa54282f720562861c8fff5ffcb148506ee30826d0a540d9197de8931a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for neuro-deblur 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.