Update README.md
Browse files
README.md
CHANGED
|
@@ -1,200 +1,96 @@
|
|
| 1 |
---
|
| 2 |
-
title: BackgroundFX
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
hardware: T4 medium
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
**Professional
|
| 17 |
|
| 18 |
-
|
| 19 |
-
[](https://www.nvidia.com/en-us/data-center/tesla-t4/)
|
| 20 |
|
| 21 |
-
##
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
##
|
| 34 |
-
- **5-10x faster** than SAM2-based solutions
|
| 35 |
-
- Optimized for T4 GPU on Hugging Face Spaces
|
| 36 |
-
- Real-time preview of first frame
|
| 37 |
-
- Batch processing for maximum efficiency
|
| 38 |
|
| 39 |
-
|
| 40 |
-
- **
|
| 41 |
-
- **
|
| 42 |
-
- **
|
|
|
|
| 43 |
|
| 44 |
-
##
|
| 45 |
-
- **Ultra Fast**: Every 3rd frame, direct compositing (3x speed)
|
| 46 |
-
- **Fast**: Every 2nd frame (2x speed)
|
| 47 |
-
- **Balanced**: All frames, optimized pipeline
|
| 48 |
-
- **Quality**: Full processing with green screen workflow
|
| 49 |
|
| 50 |
-
|
| 51 |
-
- **
|
| 52 |
-
- **
|
| 53 |
-
- **
|
| 54 |
-
- **
|
| 55 |
|
| 56 |
-
##
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|-----------|---------|-------------------|
|
| 64 |
-
| **Rembg** | Person extraction | Base speed |
|
| 65 |
-
| **U2NET_human_seg** | Specialized human model | Optimized for people |
|
| 66 |
-
| **MatAnyone** | Edge refinement | +20% time, better edges |
|
| 67 |
-
| **OpenCV** | Video processing | Hardware accelerated |
|
| 68 |
-
| **Torch** | GPU acceleration | 5-10x speedup |
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
##
|
| 73 |
-
|
| 74 |
-
1. **Clone this repository**
|
| 75 |
-
2. **Create new Space** on Hugging Face
|
| 76 |
-
3. **Select T4 GPU** (medium or small)
|
| 77 |
-
4. **Push code** and wait for build
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
streamlit==1.48.0
|
| 83 |
-
opencv-python-headless
|
| 84 |
-
numpy
|
| 85 |
-
Pillow
|
| 86 |
-
rembg
|
| 87 |
-
torch
|
| 88 |
-
torchvision
|
| 89 |
-
onnxruntime-gpu
|
| 90 |
-
matanyone # Optional: for edge refinement
|
| 91 |
-
```
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
##
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
- Gradient: Instant custom gradients
|
| 103 |
-
- Color: Solid color backgrounds
|
| 104 |
-
- Image: URL or upload
|
| 105 |
-
|
| 106 |
-
3. **Select Speed & Process** β‘
|
| 107 |
-
- Pick your speed/quality tradeoff
|
| 108 |
-
- Optional MatAnyone refinement
|
| 109 |
-
- Download result
|
| 110 |
-
|
| 111 |
-
## π― Use Cases
|
| 112 |
-
|
| 113 |
-
- **Content Creation**: YouTube, TikTok, Instagram videos
|
| 114 |
-
- **Professional**: Video calls, presentations, demos
|
| 115 |
-
- **Education**: Online courses, tutorials
|
| 116 |
-
- **Marketing**: Product videos, advertisements
|
| 117 |
-
- **Personal**: Fun videos, memes, creative content
|
| 118 |
-
|
| 119 |
-
## ποΈ Architecture Decisions
|
| 120 |
-
|
| 121 |
-
### Why Rembg over SAM2?
|
| 122 |
-
|
| 123 |
-
| Aspect | Rembg | SAM2 |
|
| 124 |
-
|--------|-------|------|
|
| 125 |
-
| **Human Segmentation** | 92-95% accuracy | 85-90% accuracy |
|
| 126 |
-
| **Speed** | 15-20 FPS | 2-3 FPS |
|
| 127 |
-
| **Memory** | 500MB-1GB | 2-4GB |
|
| 128 |
-
| **Setup** | Simple | Complex |
|
| 129 |
-
| **Purpose** | Specialized for humans | General purpose |
|
| 130 |
-
|
| 131 |
-
### Why MatAnyone?
|
| 132 |
-
|
| 133 |
-
- Refines edges around hair and clothing
|
| 134 |
-
- Minimal performance impact (20%)
|
| 135 |
-
- Optional - can disable for speed
|
| 136 |
-
- Professional-quality output
|
| 137 |
-
|
| 138 |
-
## π Performance Optimization Tips
|
| 139 |
-
|
| 140 |
-
1. **For fastest processing**:
|
| 141 |
-
- Use "Ultra Fast" mode
|
| 142 |
-
- Disable MatAnyone
|
| 143 |
-
- Use gradient backgrounds
|
| 144 |
-
- Keep videos under 30 seconds
|
| 145 |
-
|
| 146 |
-
2. **For best quality**:
|
| 147 |
-
- Use "Quality" mode
|
| 148 |
-
- Enable MatAnyone
|
| 149 |
-
- Use green screen workflow
|
| 150 |
-
- Process at full resolution
|
| 151 |
-
|
| 152 |
-
3. **For best balance**:
|
| 153 |
-
- Use "Fast" mode
|
| 154 |
-
- Enable MatAnyone for important videos
|
| 155 |
-
- Gradient or simple backgrounds
|
| 156 |
-
|
| 157 |
-
## π Troubleshooting
|
| 158 |
-
|
| 159 |
-
| Issue | Solution |
|
| 160 |
-
|-------|----------|
|
| 161 |
-
| **Slow processing** | Switch to "Fast" or "Ultra Fast" mode |
|
| 162 |
-
| **GPU not detected** | Ensure T4 GPU is enabled in Space settings |
|
| 163 |
-
| **Out of memory** | Use "Ultra Fast" mode or shorter videos |
|
| 164 |
-
| **Poor edges** | Enable MatAnyone refinement |
|
| 165 |
-
| **Video won't play** | Check video codec compatibility |
|
| 166 |
-
|
| 167 |
-
## π Roadmap
|
| 168 |
-
|
| 169 |
-
- [ ] Batch video processing
|
| 170 |
-
- [ ] Custom model fine-tuning
|
| 171 |
-
- [ ] Real-time preview
|
| 172 |
-
- [ ] Mobile app
|
| 173 |
-
- [ ] API endpoint
|
| 174 |
-
- [ ] More background effects
|
| 175 |
-
|
| 176 |
-
## π€ Contributing
|
| 177 |
-
|
| 178 |
-
Contributions welcome! Please check our guidelines.
|
| 179 |
-
|
| 180 |
-
## π License
|
| 181 |
-
|
| 182 |
-
MIT License - feel free to use in your projects!
|
| 183 |
-
|
| 184 |
-
## π Acknowledgments
|
| 185 |
-
|
| 186 |
-
- **Rembg** team for the excellent segmentation models
|
| 187 |
-
- **MatAnyone** for edge refinement technology
|
| 188 |
-
- **Hugging Face** for GPU infrastructure
|
| 189 |
-
- **Streamlit** for the amazing framework
|
| 190 |
-
|
| 191 |
-
## π¬ Support
|
| 192 |
-
|
| 193 |
-
- [GitHub Issues](https://github.com/yourusername/backgroundfx/issues)
|
| 194 |
-
- [Hugging Face Discussion](https://huggingface.co/spaces/yourusername/backgroundfx/discussions)
|
| 195 |
-
|
| 196 |
-
---
|
| 197 |
-
|
| 198 |
-
**Built for speed, designed for quality.** π
|
| 199 |
-
|
| 200 |
-
*Optimized for T4 GPU on Hugging Face Spaces*
|
|
|
|
| 1 |
---
|
| 2 |
+
title: BackgroundFX Pro - SAM2 Powered
|
| 3 |
+
emoji: π₯
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
+
suggested_hardware: t4-small
|
| 12 |
+
suggested_storage: small
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# π₯ BackgroundFX Pro - SAM2 Powered
|
| 16 |
|
| 17 |
+
**Professional AI video background replacement with advanced segmentation**
|
| 18 |
|
| 19 |
+
Upload your video and let SAM2 AI automatically detect and replace the background with precision. Optimized for Hugging Face Spaces with smart memory management and lazy loading.
|
|
|
|
| 20 |
|
| 21 |
+
## β¨ Features
|
| 22 |
|
| 23 |
+
- **π€ SAM2 Integration**: State-of-the-art segmentation with Meta's SAM2
|
| 24 |
+
- **β‘ Smart Loading**: True lazy loading - models download only when needed
|
| 25 |
+
- **π¨ Background Options**: 8 built-in presets + custom image upload
|
| 26 |
+
- **π§ Advanced Settings**: Model size selection and edge smoothing
|
| 27 |
+
- **πΎ Memory Optimized**: Automatic cleanup and CUDA cache management
|
| 28 |
+
- **π± Professional UI**: Clean, intuitive interface with real-time progress
|
| 29 |
|
| 30 |
+
## π Quick Start
|
| 31 |
|
| 32 |
+
1. Upload a video (MP4, AVI, MOV, MKV, WebM - max 5 minutes)
|
| 33 |
+
2. Choose a background preset or upload custom image
|
| 34 |
+
3. Select AI model size (Tiny/Small/Base)
|
| 35 |
+
4. Click "Replace Background" and wait for processing
|
| 36 |
+
5. Download your professional video!
|
| 37 |
|
| 38 |
+
## π‘ Pro Tips
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
- **Best results**: Clear subject separation from background
|
| 41 |
+
- **Lighting**: Even lighting works best for accurate segmentation
|
| 42 |
+
- **Movement**: Minimal camera shake recommended
|
| 43 |
+
- **Processing time**: ~30-60 seconds per minute of video
|
| 44 |
+
- **GPU acceleration**: Automatically uses available GPU for faster processing
|
| 45 |
|
| 46 |
+
## π§ Technical Details
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
- **Models**: SAM2 Tiny (38MB), Small (185MB), Base (320MB)
|
| 49 |
+
- **Formats**: Supports all major video formats
|
| 50 |
+
- **Resolution**: Up to 1920x1080 (Full HD)
|
| 51 |
+
- **Duration**: Max 5 minutes on free tier
|
| 52 |
+
- **Memory**: True lazy loading with automatic cleanup
|
| 53 |
|
| 54 |
+
## π¬ Use Cases
|
| 55 |
|
| 56 |
+
- **Content Creation**: Remove messy backgrounds for professional videos
|
| 57 |
+
- **Virtual Meetings**: Create custom backgrounds for video calls
|
| 58 |
+
- **Education**: Clean backgrounds for instructional videos
|
| 59 |
+
- **Social Media**: Eye-catching backgrounds for posts and stories
|
| 60 |
|
| 61 |
+
## ποΈ Built With
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
- [SAM2](https://github.com/facebookresearch/segment-anything-2) - Meta's Segment Anything Model 2
|
| 64 |
+
- [Gradio](https://gradio.app/) - Machine learning web interface framework
|
| 65 |
+
- [OpenCV](https://opencv.org/) - Computer vision library
|
| 66 |
+
- [PyTorch](https://pytorch.org/) - Deep learning framework
|
| 67 |
|
| 68 |
+
## π System Requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
- **Recommended**: GPU-enabled Space (T4-small or better)
|
| 71 |
+
- **Minimum**: CPU-only mode supported but slower
|
| 72 |
+
- **Memory**: Automatic management with CUDA optimization
|
| 73 |
+
- **Storage**: No persistent storage needed (lazy loading)
|
| 74 |
|
| 75 |
+
## π― Background Presets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
Choose from 8 beautiful presets:
|
| 78 |
+
- **Ocean Blue** - Professional gradient
|
| 79 |
+
- **Sunset Orange** - Warm and vibrant
|
| 80 |
+
- **Forest Green** - Natural and calm
|
| 81 |
+
- **Purple Haze** - Creative and modern
|
| 82 |
+
- **Pure White** - Clean and minimal
|
| 83 |
+
- **Pure Black** - Dramatic effect
|
| 84 |
+
- **Chroma Green** - For further editing
|
| 85 |
+
- **Chroma Blue** - Alternative chroma key
|
| 86 |
|
| 87 |
+
## β‘ Performance Guide
|
| 88 |
|
| 89 |
+
| Hardware | Processing Speed | Best Model | Concurrent Users |
|
| 90 |
+
|----------|------------------|------------|------------------|
|
| 91 |
+
| CPU | 2-3 min/video min | Tiny | 1 |
|
| 92 |
+
| T4-small | 30-60s/video min | Small | 1-2 |
|
| 93 |
+
| T4-medium | 20-40s/video min | Base | 2-3 |
|
| 94 |
+
| A10G+ | 15-30s/video min | Base | 3-5 |
|
| 95 |
|
| 96 |
+
Check out the [configuration reference](https://huggingface.co/docs/hub/spaces-config-reference) for more details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|