MogensR commited on
Commit
6391dff
·
1 Parent(s): 84ac472
Files changed (1) hide show
  1. README.md +71 -37
README.md CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  title: 🎬 BackgroundFX Pro - SAM2 + MatAnyone
2
  emoji: 🎥
3
  colorFrom: indigo
@@ -22,19 +25,26 @@ MatAnyone
22
  🎬 BackgroundFX Pro — Professional Video Background Replacement
23
 
24
  BackgroundFX Pro is a GPU-accelerated app for Hugging Face Spaces (Docker) that replaces video backgrounds using:
25
- • SAM2 — high-quality object segmentation
26
- MatAnyone temporal video matting for stable alpha over time
 
 
27
 
28
  Built on: CUDA 12.1.1, PyTorch 2.5.1 (cu121), torchvision 0.20.1, Gradio 4.41.0.
29
 
30
  ✨ Features
31
 
32
- Upload a video and replace its background with Solid color, AI-generated image, your own uploaded image, or an Unsplash search.
33
- • Optimized for T4 GPUs (HF Spaces).
34
- Caching & logs stored in the repository volume for reliability:
35
- – HF cache: ./.hf
36
- Torch cache: ./.torch
37
- – App data & logs: ./data (see data/run.log)
 
 
 
 
 
38
 
39
  🚀 Try It
40
 
@@ -57,23 +67,35 @@ Tip: Start with 720p/1080p on T4; 4K can exceed memory.
57
 
58
  🗂️ Project Structure (key files)
59
 
60
- Dockerfile
61
- • requirements.txt
62
- • ui.py
63
- • ui_core_interface.py
64
- • ui_core_functionality.py
65
- • two_stage_pipeline.py
66
- • models/sam2_loader.py
67
- • models/matanyone_loader.py
68
- • utils/init.py
69
- • data/ (created at runtime for logs and outputs)
70
- • tmp/ (created at runtime for jobs and temp files)
 
 
 
 
 
 
 
 
 
 
71
 
72
  ⚙️ Runtime Notes
73
 
74
- The app binds to the port from PORT or GRADIO_SERVER_PORT (defaults to 7860).
75
- • A heartbeat writes every ~2s to logs with memory and disk stats.
76
- If the process dies without a final “PROCESS EXITING” line, it was likely an OOM or hard kill.
 
 
77
 
78
  🧪 Local Development (Docker)
79
 
@@ -89,29 +111,39 @@ Run the container and map port 7860.
89
 
90
  🔧 Space Settings
91
 
92
- SDK: docker
93
- • App port: 7860
94
- Hardware: T4 GPU (or better)
 
 
95
 
96
  📦 Key Versions
97
 
98
- Gradio: 4.41.0
99
- • PyTorch: 2.5.1 (cu121)
100
- • torchvision: 0.20.1
101
- • SAM2: installed from source at build time in third_party/sam2
102
- • MatAnyone: installed from GitHub
 
 
 
 
103
 
104
  🧯 Troubleshooting
105
 
106
  Container exits after ~20s:
107
- • Check data/run.log — heartbeat shows RSS and cgroup memory limit.
108
- If OOM is suspected: use lower-resolution videos, keep concurrency low (already set to max_threads=1 and queue(max_size=2)), and ensure GPU hardware is selected.
 
 
109
 
110
  “Could not open video” or empty output:
111
- • Verify the uploaded file codec/container. Re-encode to H.264/AAC in .mp4 if needed.
 
112
 
113
  Weights not found / slow first run:
114
- • First run downloads model assets into ./.hf and ./.torch. Subsequent runs are faster.
 
115
 
116
  🔐 Privacy
117
 
@@ -123,6 +155,8 @@ MIT — see LICENSE or the Space’s license field.
123
 
124
  🙌 Credits
125
 
126
- SAM2 by Meta FAIR
127
- • MatAnyone by Peiqing Yang et al.
128
- Built with Gradio and PyTorch
 
 
 
1
+ Here’s a cleaned, single README.md you can paste in as-is.
2
+ (It includes the required YAML metadata at the very top and fixes your tags/list formatting.)
3
+
4
  title: 🎬 BackgroundFX Pro - SAM2 + MatAnyone
5
  emoji: 🎥
6
  colorFrom: indigo
 
25
  🎬 BackgroundFX Pro — Professional Video Background Replacement
26
 
27
  BackgroundFX Pro is a GPU-accelerated app for Hugging Face Spaces (Docker) that replaces video backgrounds using:
28
+
29
+ SAM2high-quality object segmentation
30
+
31
+ MatAnyone — temporal video matting for stable alpha over time
32
 
33
  Built on: CUDA 12.1.1, PyTorch 2.5.1 (cu121), torchvision 0.20.1, Gradio 4.41.0.
34
 
35
  ✨ Features
36
 
37
+ Upload a video and replace its background with: solid color, AI-generated image, your own uploaded image, or an Unsplash search
38
+
39
+ Optimized for T4 GPUs (HF Spaces)
40
+
41
+ Caching & logs stored in the repository volume for reliability:
42
+
43
+ HF cache: ./.hf
44
+
45
+ Torch cache: ./.torch
46
+
47
+ App data & logs: ./data (see data/run.log)
48
 
49
  🚀 Try It
50
 
 
67
 
68
  🗂️ Project Structure (key files)
69
 
70
+ Dockerfile
71
+
72
+ requirements.txt
73
+
74
+ ui.py
75
+
76
+ ui_core_interface.py
77
+
78
+ ui_core_functionality.py
79
+
80
+ two_stage_pipeline.py
81
+
82
+ models/sam2_loader.py
83
+
84
+ models/matanyone_loader.py
85
+
86
+ utils/init.py
87
+
88
+ data/ (created at runtime for logs and outputs)
89
+
90
+ tmp/ (created at runtime for jobs and temp files)
91
 
92
  ⚙️ Runtime Notes
93
 
94
+ The app binds to the port from PORT or GRADIO_SERVER_PORT (defaults to 7860).
95
+
96
+ A heartbeat writes every ~2s to logs with memory and disk stats.
97
+
98
+ If the process dies without a final “PROCESS EXITING” line, it was likely an OOM or hard kill.
99
 
100
  🧪 Local Development (Docker)
101
 
 
111
 
112
  🔧 Space Settings
113
 
114
+ SDK: docker
115
+
116
+ App port: 7860
117
+
118
+ Hardware: T4 GPU (or better)
119
 
120
  📦 Key Versions
121
 
122
+ Gradio: 4.41.0
123
+
124
+ PyTorch: 2.5.1 (cu121)
125
+
126
+ torchvision: 0.20.1
127
+
128
+ SAM2: installed from source at build time in third_party/sam2
129
+
130
+ MatAnyone: installed from GitHub
131
 
132
  🧯 Troubleshooting
133
 
134
  Container exits after ~20s:
135
+
136
+ Check data/run.log heartbeat shows RSS and cgroup memory limit.
137
+
138
+ If OOM is suspected: use lower-resolution videos, keep concurrency low (already set to max_threads=1 and queue(max_size=2)), and ensure GPU hardware is selected.
139
 
140
  “Could not open video” or empty output:
141
+
142
+ Verify the uploaded file codec/container. Re-encode to H.264/AAC in .mp4 if needed.
143
 
144
  Weights not found / slow first run:
145
+
146
+ First run downloads model assets into ./.hf and ./.torch. Subsequent runs are faster.
147
 
148
  🔐 Privacy
149
 
 
155
 
156
  🙌 Credits
157
 
158
+ SAM2 by Meta FAIR
159
+
160
+ MatAnyone by Peiqing Yang et al.
161
+
162
+ Built with Gradio and PyTorch