MogensR commited on
Commit
76b6368
Β·
1 Parent(s): a226dc7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +69 -173
README.md CHANGED
@@ -1,200 +1,96 @@
1
  ---
2
- title: BackgroundFX Fast
3
- emoji: πŸš€
4
  colorFrom: blue
5
- colorTo: green
6
- sdk: docker
 
 
7
  pinned: false
8
  license: mit
9
- models:
10
- - rembg/u2net_human_seg
11
- hardware: T4 medium
12
  ---
13
 
14
- # πŸš€ BackgroundFX - Lightning-Fast Video Background Replacement
15
 
16
- **Professional-quality background replacement in seconds, not minutes!** Powered by specialized AI models optimized for T4 GPU performance.
17
 
18
- [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/yourusername/backgroundfx)
19
- [![GPU Optimized](https://img.shields.io/badge/GPU-T4%20Optimized-green)](https://www.nvidia.com/en-us/data-center/tesla-t4/)
20
 
21
- ## ⚑ Performance Benchmarks
22
 
23
- | Video Length | Ultra Fast | Fast | Balanced | Quality |
24
- |-------------|------------|------|----------|---------|
25
- | 10 seconds | 5 sec | 10 sec | 15 sec | 20 sec |
26
- | 30 seconds | 15 sec | 30 sec | 45 sec | 60 sec |
27
- | 60 seconds | 30 sec | 60 sec | 90 sec | 120 sec |
 
28
 
29
- *Benchmarks on T4 GPU with 1080p video*
30
 
31
- ## 🎯 Key Features
 
 
 
 
32
 
33
- ### **πŸƒβ€β™‚οΈ Speed-First Design**
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
- ### **🎨 Intelligent Segmentation**
40
- - **Rembg U2NET**: Purpose-built for human segmentation (92-95% accuracy)
41
- - **MatAnyone Integration**: Optional edge refinement for hair and clothing
42
- - **Automatic fallback**: Works even without GPU
 
43
 
44
- ### **🎬 Flexible Processing Modes**
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
- ### **πŸ–ΌοΈ Background Options**
51
- - **Gradient backgrounds**: Instant generation
52
- - **Solid colors**: Simple and clean
53
- - **Image URL**: Direct from web
54
- - **Upload**: Your own images
55
 
56
- ## πŸ”§ Technology Stack
57
 
58
- ```
59
- Pipeline: Rembg β†’ MatAnyone (optional) β†’ Compositing β†’ Output
60
- ```
 
61
 
62
- | Component | Purpose | Performance Impact |
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
- ## πŸ“¦ Installation
 
 
 
71
 
72
- ### Quick Deploy to Hugging Face Spaces
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
- ### Requirements
 
 
 
80
 
81
- ```txt
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
- ## πŸš€ Usage
 
 
 
 
 
 
 
 
94
 
95
- ### Simple 3-Step Process
96
 
97
- 1. **Upload Video** πŸ“Ή
98
- - Supports MP4, AVI, MOV, MKV
99
- - Recommended: Under 30 seconds for fastest processing
 
 
 
100
 
101
- 2. **Choose Background** 🎨
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.