not-lain commited on
Commit
2ca1442
·
verified ·
1 Parent(s): 61f5a46

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +229 -15
README.md CHANGED
@@ -14,40 +14,254 @@ tags:
14
  <img src="https://usefeyn.com/feyn/feyn_mark.svg"/>
15
  </p>
16
 
17
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration.
18
 
19
- Library: [nobg](https://github.com/feyninc/nobg)
20
 
21
- ## how to load
22
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  pip install nobg
24
  ```
25
 
26
- use the AutoModel class
 
27
  ```python
28
  from nobg import AutoModel, AutoProcessor
 
29
  model = AutoModel.from_pretrained("feyninc/multimatte")
30
  processor = AutoProcessor.from_pretrained("feyninc/multimatte")
31
- model.predict(processor, image)
32
- ```
33
- or you can use the model class directly
34
- ```python
35
- from nobg import Sam3
36
- model = Sam3.from_pretrained("feyninc/multimatte")
37
  ```
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  ## Citation
41
- If you use this model, please cite:
 
 
 
 
 
 
 
 
 
 
 
42
  ```bibtex
43
  @article{sam3,
44
  title={SAM 3: Segment Anything with Concepts},
45
  author={Carion, Nicolas and Gustafson, Laura and Hu, Yuan-Ting and Debnath, Shoubhik and Hu, Ronghang and Suris, Didac and Ryali, Chaitanya and Alwala, Kalyan Vasudev and Khedr, Haitham and Huang, Andrew and Lei, Jie and Ma, Tengyu and Guo, Baishan and Marks, Markus and Greer, Joseph and Wang, Meng and Sun, Peize and R{\"a}dle, Roman and Afouras, Triantafyllos and Mavroudi, Effrosyni and Dollar, Piotr and Ravi, Nikhila and Saenko, Kate and Zhang, Pengchuan and Feichtenhofer, Christoph},
46
- journal={arXiv preprint},
47
  year={2025},
48
  url={https://ai.meta.com/research/publications/sam-3-segment-anything-with-concepts/},
49
  }
 
 
 
 
 
 
 
50
  ```
51
 
52
- ## Contributions
53
- Any contributions are welcome at https://github.com/feyninc/nobg
 
 
 
 
14
  <img src="https://usefeyn.com/feyn/feyn_mark.svg"/>
15
  </p>
16
 
17
+ <h1 align="center">MultiMatte</h1>
18
 
19
+ <p align="center"><b>Cut anything you can name.</b></p>
20
 
21
+ <p align="center">
22
+ <a href="https://usefeyn.com/blog/multimatte"><img src="https://img.shields.io/badge/Blog-Read%20the%20post-black"></a>
23
+ <a href="https://github.com/feyninc/nobg"><img src="https://img.shields.io/badge/GitHub-nobg-black?logo=github"></a>
24
+ <a href="https://pypi.org/project/nobg/"><img src="https://img.shields.io/pypi/v/nobg?color=blue&label=pip%20install%20nobg"></a>
25
+ <a href="https://usefeyn.com/multimatte"><img src="https://img.shields.io/badge/Demo-usefeyn.com%2Fmultimatte-orange"></a>
26
+ </p>
27
+
28
+ MultiMatte is a **promptable matting model**: name an object and it returns an alpha matte for it.
29
+ It is a LoRA fine-tune of [SAM 3](https://huggingface.co/facebook/sam3), retrained to produce
30
+ continuous opacity instead of binary masks, with the adapter merged into the released weights.
31
+
32
+ ## Prompt steering
33
+
34
+ The same photograph, four prompts.
35
+
36
+ <table>
37
+ <tr>
38
+ <td width="25%"><img src="https://usefeyn.com/blog/multimatte/dog-input.webp" width="100%" alt="A bulldog looking up at a bowl held by a person in jeans."></td>
39
+ <td width="25%"><img src="https://usefeyn.com/blog/multimatte/dog-the-dog.webp" width="100%" alt="The dog cut out of the photograph."></td>
40
+ <td width="25%"><img src="https://usefeyn.com/blog/multimatte/dog-the-bowl.webp" width="100%" alt="The metal bowl cut out of the same photograph."></td>
41
+ <td width="25%"><img src="https://usefeyn.com/blog/multimatte/dog-the-jeans.webp" width="100%" alt="The person's jeans cut out of the same photograph."></td>
42
+ </tr>
43
+ <tr>
44
+ <td align="center"><code>input</code></td>
45
+ <td align="center"><code>"the dog"</code></td>
46
+ <td align="center"><code>"the dog bowl"</code></td>
47
+ <td align="center"><code>"the jeans"</code></td>
48
+ </tr>
49
+ </table>
50
+
51
+ Plural concepts return every match in one matte, and small objects stay addressable.
52
+
53
+ <table>
54
+ <tr>
55
+ <td width="33%"><img src="https://usefeyn.com/blog/multimatte/cats-input.webp" width="100%" alt="Two tabby cats sprawled on a pink couch beside two remote controls."></td>
56
+ <td width="33%"><img src="https://usefeyn.com/blog/multimatte/cats-the-cats.webp" width="100%" alt="Both cats cut out together."></td>
57
+ <td width="33%"><img src="https://usefeyn.com/blog/multimatte/cats-the-remote.webp" width="100%" alt="Only the two remote controls cut out."></td>
58
+ </tr>
59
+ <tr>
60
+ <td align="center"><code>input</code></td>
61
+ <td align="center"><code>"the cats"</code></td>
62
+ <td align="center"><code>"the remote"</code></td>
63
+ </tr>
64
+ </table>
65
+
66
+ The output is a continuous alpha matte, not a threshold, so edges hold up at 1:1 zoom.
67
+
68
+ <table>
69
+ <tr>
70
+ <td width="50%"><img src="https://usefeyn.com/blog/multimatte/truck-crop-input.webp" width="100%" alt="Full-resolution crop of a white vehicle's front fender against a red wall."></td>
71
+ <td width="50%"><img src="https://usefeyn.com/blog/multimatte/truck-crop-cutout.webp" width="100%" alt="The same crop with the red wall removed and the fender edge intact."></td>
72
+ </tr>
73
+ <tr>
74
+ <td align="center"><code>input (crop)</code></td>
75
+ <td align="center"><code>cutout (crop)</code></td>
76
+ </tr>
77
+ </table>
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
  pip install nobg
83
  ```
84
 
85
+ ## Usage
86
+
87
  ```python
88
  from nobg import AutoModel, AutoProcessor
89
+
90
  model = AutoModel.from_pretrained("feyninc/multimatte")
91
  processor = AutoProcessor.from_pretrained("feyninc/multimatte")
92
+
93
+ # Prompt-free: uses the processor's default_prompt ("the main foreground subject").
94
+ model.predict(processor, "photo.jpg").save("output.png")
95
+
96
+ # Named concept.
97
+ model.predict(processor, "photo.jpg", "the dog").save("dog.png")
98
  ```
99
 
100
+ `predict` runs the whole pipeline — load, preprocess, forward under `no_grad` in eval mode,
101
+ post-process, composite — and returns an RGBA cutout at the input's original resolution.
102
+ `image` accepts anything [`loadimg`](https://github.com/not-lain/loadimg) takes: a path, URL,
103
+ base64 string, numpy array or PIL image.
104
+
105
+ The signature is `predict(processor, image, prompt, boxes)`, everything optional after `image`.
106
+ Useful keywords: `batch_size` (images per forward pass, default 1 to keep peak memory flat) and
107
+ `return_type="alpha"` for the raw `(H, W)` matte tensor instead of a cutout.
108
+
109
+
110
+ ## Results
111
+
112
+ S-measure (`S_α`), prompt-free, higher is better. Both columns come from one scoring harness on
113
+ identical rows, so the difference isolates the weights — the SAM 3 numbers are a fresh rescore, not
114
+ values copied from a paper. Changes below 0.002 `S_α` are treated as measurement noise.
115
+
116
+ <table>
117
+ <thead>
118
+ <tr>
119
+ <th>Split</th>
120
+ <th style="text-align: right;">SAM 3</th>
121
+ <th style="text-align: right;">MultiMatte</th>
122
+ <th style="text-align: right;">Δ</th>
123
+ </tr>
124
+ </thead>
125
+ <tbody>
126
+ <tr>
127
+ <td colspan="4"><strong>Dichotomous (DIS5K)</strong></td>
128
+ </tr>
129
+ <tr>
130
+ <td>DIS-VD</td>
131
+ <td style="text-align: right;">0.667</td>
132
+ <td style="text-align: right;"><strong>0.901</strong></td>
133
+ <td style="text-align: right;">+0.233</td>
134
+ </tr>
135
+ <tr>
136
+ <td>DIS-TE1</td>
137
+ <td style="text-align: right;">0.667</td>
138
+ <td style="text-align: right;"><strong>0.901</strong></td>
139
+ <td style="text-align: right;">+0.234</td>
140
+ </tr>
141
+ <tr>
142
+ <td>DIS-TE2</td>
143
+ <td style="text-align: right;">0.703</td>
144
+ <td style="text-align: right;"><strong>0.923</strong></td>
145
+ <td style="text-align: right;">+0.220</td>
146
+ </tr>
147
+ <tr>
148
+ <td>DIS-TE3</td>
149
+ <td style="text-align: right;">0.685</td>
150
+ <td style="text-align: right;"><strong>0.921</strong></td>
151
+ <td style="text-align: right;">+0.236</td>
152
+ </tr>
153
+ <tr>
154
+ <td>DIS-TE4</td>
155
+ <td style="text-align: right;">0.649</td>
156
+ <td style="text-align: right;"><strong>0.893</strong></td>
157
+ <td style="text-align: right;">+0.245</td>
158
+ </tr>
159
+ <tr>
160
+ <td colspan="4"><strong>Salient objects</strong></td>
161
+ </tr>
162
+ <tr>
163
+ <td>DAVIS-S †</td>
164
+ <td style="text-align: right;">0.913</td>
165
+ <td style="text-align: right;"><strong>0.979</strong></td>
166
+ <td style="text-align: right;">+0.066</td>
167
+ </tr>
168
+ <tr>
169
+ <td>HRSOD-TE</td>
170
+ <td style="text-align: right;">0.930</td>
171
+ <td style="text-align: right;"><strong>0.969</strong></td>
172
+ <td style="text-align: right;">+0.039</td>
173
+ </tr>
174
+ <tr>
175
+ <td>UHRSD-TE</td>
176
+ <td style="text-align: right;">0.877</td>
177
+ <td style="text-align: right;"><strong>0.961</strong></td>
178
+ <td style="text-align: right;">+0.084</td>
179
+ </tr>
180
+ <tr>
181
+ <td>DUTS-TE</td>
182
+ <td style="text-align: right;">0.892</td>
183
+ <td style="text-align: right;"><strong>0.954</strong></td>
184
+ <td style="text-align: right;">+0.062</td>
185
+ </tr>
186
+ <tr>
187
+ <td>DUT-OMRON †</td>
188
+ <td style="text-align: right;">0.792</td>
189
+ <td style="text-align: right;"><strong>0.901</strong></td>
190
+ <td style="text-align: right;">+0.109</td>
191
+ </tr>
192
+ <tr>
193
+ <td colspan="4"><strong>Camouflage</strong></td>
194
+ </tr>
195
+ <tr>
196
+ <td>COD10K-TE</td>
197
+ <td style="text-align: right;">0.787</td>
198
+ <td style="text-align: right;"><strong>0.934</strong></td>
199
+ <td style="text-align: right;">+0.148</td>
200
+ </tr>
201
+ <tr>
202
+ <td>CAMO-TE</td>
203
+ <td style="text-align: right;">0.827</td>
204
+ <td style="text-align: right;"><strong>0.914</strong></td>
205
+ <td style="text-align: right;">+0.086</td>
206
+ </tr>
207
+ </tbody>
208
+ </table>
209
+
210
+ † No sibling in the training mix. DAVIS-S and DUT-OMRON are the two fully cross-domain splits here,
211
+ so they are the pair to read for generalization — and MultiMatte's best absolute score lands on
212
+ DAVIS-S at 0.979.
213
+
214
+ **Naming the concept helps, before and after training.** On DIS-VD, a real human-written phrase adds
215
+ 0.150 `S_α` to base SAM 3 for zero gradient steps, and still adds 0.036 to MultiMatte after
216
+ fine-tuning. Prompt supervision made the model better at both pathways rather than making it
217
+ prompt-insensitive.
218
+
219
+ ## Training
220
+ | feature | detail |
221
+ |:--|:--|
222
+ | Base model | [`facebook/sam3`](https://huggingface.co/facebook/sam3), 0.86 B parameters |
223
+ | Method | LoRA, rank 16, merged into the released weights |
224
+ | Trainable | 19.49 M parameters — 2.27 % of the model |
225
+ | Targets | Attention and MLP projections in every tower, including the CLIP text tower |
226
+ | Objective | Focal loss + Dice loss (SAM 3's own semantic segmentation objective) |
227
+ | Steps | 14,000 |
228
+ | Data | 19,953 images: salient objects, camouflage, high-resolution subjects, hair, marine scenes |
229
+ | Prompt supervision | 4,949 images (24.8 %) with human-written per-image concept phrases |
230
+ | Input resolution | 1008 × 1008 |
231
+
232
 
233
  ## Citation
234
+
235
+ ```bibtex
236
+ @note{multimatte2026,
237
+ title = {MultiMatte: Cut Out Anything You Can Name},
238
+ author = {Hichri, Hafedh and Feyn Research},
239
+ year = {2026},
240
+ venue = {Feyn Field Notes}
241
+ }
242
+ ```
243
+
244
+ Please also cite the base model and the adaptation method:
245
+
246
  ```bibtex
247
  @article{sam3,
248
  title={SAM 3: Segment Anything with Concepts},
249
  author={Carion, Nicolas and Gustafson, Laura and Hu, Yuan-Ting and Debnath, Shoubhik and Hu, Ronghang and Suris, Didac and Ryali, Chaitanya and Alwala, Kalyan Vasudev and Khedr, Haitham and Huang, Andrew and Lei, Jie and Ma, Tengyu and Guo, Baishan and Marks, Markus and Greer, Joseph and Wang, Meng and Sun, Peize and R{\"a}dle, Roman and Afouras, Triantafyllos and Mavroudi, Effrosyni and Dollar, Piotr and Ravi, Nikhila and Saenko, Kate and Zhang, Pengchuan and Feichtenhofer, Christoph},
250
+ journal={arXiv preprint arXiv:2511.16719},
251
  year={2025},
252
  url={https://ai.meta.com/research/publications/sam-3-segment-anything-with-concepts/},
253
  }
254
+
255
+ @article{lora,
256
+ title={LoRA: Low-Rank Adaptation of Large Language Models},
257
+ author={Hu, Edward J. and Shen, Yelong and Wallis, Phillip and Allen-Zhu, Zeyuan and Li, Yuanzhi and Wang, Shean and Wang, Lu and Chen, Weizhu},
258
+ journal={arXiv preprint arXiv:2106.09685},
259
+ year={2021},
260
+ }
261
  ```
262
 
263
+ ## Acknowledgements
264
+
265
+ Built on Meta's SAM 3. FlowDIS supplied the human-written DIS5K phrases used for training and
266
+ evaluation. Thinking Machines' LoRA analysis informed the adapter configuration. Thanks to the
267
+ dataset authors whose released work made the training mix and evaluation possible.