Update README.md
Browse files
README.md
CHANGED
@@ -2,7 +2,64 @@
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
``` python
|
8 |
model = SamModel.from_pretrained("Zigeng/SlimSAM-uniform-77").to("cuda")
|
@@ -15,4 +72,53 @@ inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to
|
|
15 |
outputs = model(**inputs)
|
16 |
masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
|
17 |
scores = outputs.iou_scores
|
18 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
5 |
+
# SlimSAM: 0.1% Data Makes Segment Anything Slim
|
6 |
+
<div align="center">
|
7 |
+
<img src="images/paper/intro.PNG" width="66%">
|
8 |
+
<img src="images/paper/everything.PNG" width="100%">
|
9 |
+
</div>
|
10 |
+
|
11 |
+
> **0.1% Data Makes Segment Anything Slim**
|
12 |
+
> [Zigeng Chen](https://github.com/czg1225), [Gongfan Fang](https://fangggf.github.io/), [Xinyin Ma](https://horseee.github.io/), [Xinchao Wang](https://sites.google.com/site/sitexinchaowang/)
|
13 |
+
> [Learning and Vision Lab](http://lv-nus.org/), National University of Singapore
|
14 |
+
> Paper: [[Arxiv]](https://arxiv.org/abs/2312.05284)
|
15 |
+
|
16 |
+
## Introduction
|
17 |
+
|
18 |
+
<div align="center">
|
19 |
+
<img src="images/paper/process.PNG" width="100%">
|
20 |
+
</div>
|
21 |
+
|
22 |
+
**SlimSAM** is a novel SAM compression method, which efficiently reuses pre-trained SAMs without the necessity for extensive retraining. This is achieved by the efficient reuse of pre-trained SAMs through a unified pruning-distillation framework. To enhance knowledge inheritance from the original SAM, we employ an innovative alternate slimming strategy that partitions the compression process into a progressive procedure. Diverging from prior pruning techniques, we meticulously prune and distill decoupled model structures in an alternating fashion. Furthermore, a novel label-free pruning criterion is also proposed to align the pruning objective with the optimization target, thereby boosting the post-distillation after pruning.
|
23 |
+
|
24 |
+

|
25 |
+
|
26 |
+
SlimSAM achieves approaching performance while reducing the parameter counts to **0.9\% (5.7M)**, MACs to **0.8\% (21G)**, and requiring mere **0.1\% (10k)** of the training data when compared to the original SAM-H. Extensive experiments demonstrate that our method realize significant superior performance while utilizing over **10 times** less training data when compared to other SAM compression methods.
|
27 |
+
|
28 |
+
## Visualization Results
|
29 |
+
|
30 |
+
Qualitative comparison of results obtained using point prompts, box prompts, and segment everything prompts are shown in the following section.
|
31 |
+
|
32 |
+
### Segment Everything Prompts
|
33 |
+
<div align="center">
|
34 |
+
<img src="images/paper/everything2.PNG" width="100%">
|
35 |
+
</div>
|
36 |
+
|
37 |
+
### Box Prompts and Point Prompts
|
38 |
+
<div align="center">
|
39 |
+
<img src="images/paper/prompt.PNG" width="100%">
|
40 |
+
</div>
|
41 |
+
|
42 |
+
|
43 |
+
## Quantitative Results
|
44 |
+
|
45 |
+
We conducted a comprehensive comparison encompassing performance, efficiency, and training costs with other SAM compression methods and structural pruning methods.
|
46 |
+
|
47 |
+
### Comparing with other SAM compression methods.
|
48 |
+
<div align="center">
|
49 |
+
<img src="images/paper/compare_tab1.PNG" width="100%">
|
50 |
+
</div>
|
51 |
+
|
52 |
+
### Comparing with other structural pruning methods.
|
53 |
+
<div align="center">
|
54 |
+
<img src="images/paper/compare_tab2.PNG" width="50%">
|
55 |
+
</div>
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
## <a name="Models"></a>Model Using
|
61 |
+
|
62 |
+
Fast state_dict loading for local uniform pruning SlimSAM-50 model:
|
63 |
|
64 |
``` python
|
65 |
model = SamModel.from_pretrained("Zigeng/SlimSAM-uniform-77").to("cuda")
|
|
|
72 |
outputs = model(**inputs)
|
73 |
masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
|
74 |
scores = outputs.iou_scores
|
75 |
+
```
|
76 |
+
|
77 |
+
## BibTex of our SlimSAM
|
78 |
+
If you use SlimSAM in your research, please use the following BibTeX entry. Thank you!
|
79 |
+
|
80 |
+
```bibtex
|
81 |
+
@misc{chen202301,
|
82 |
+
title={0.1% Data Makes Segment Anything Slim},
|
83 |
+
author={Zigeng Chen and Gongfan Fang and Xinyin Ma and Xinchao Wang},
|
84 |
+
year={2023},
|
85 |
+
eprint={2312.05284},
|
86 |
+
archivePrefix={arXiv},
|
87 |
+
primaryClass={cs.CV}
|
88 |
+
}
|
89 |
+
```
|
90 |
+
|
91 |
+
## Acknowledgement
|
92 |
+
|
93 |
+
<details>
|
94 |
+
<summary>
|
95 |
+
<a href="https://github.com/facebookresearch/segment-anything">SAM</a> (Segment Anything) [<b>bib</b>]
|
96 |
+
</summary>
|
97 |
+
|
98 |
+
```bibtex
|
99 |
+
@article{kirillov2023segany,
|
100 |
+
title={Segment Anything},
|
101 |
+
author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{\'a}r, Piotr and Girshick, Ross},
|
102 |
+
journal={arXiv:2304.02643},
|
103 |
+
year={2023}
|
104 |
+
}
|
105 |
+
```
|
106 |
+
</details>
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
<details>
|
111 |
+
<summary>
|
112 |
+
<a href="https://github.com/VainF/Torch-Pruning">Torch Pruning</a> (DepGraph: Towards Any Structural Pruning) [<b>bib</b>]
|
113 |
+
</summary>
|
114 |
+
|
115 |
+
```bibtex
|
116 |
+
@inproceedings{fang2023depgraph,
|
117 |
+
title={Depgraph: Towards any structural pruning},
|
118 |
+
author={Fang, Gongfan and Ma, Xinyin and Song, Mingli and Mi, Michael Bi and Wang, Xinchao},
|
119 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
120 |
+
pages={16091--16101},
|
121 |
+
year={2023}
|
122 |
+
}
|
123 |
+
```
|
124 |
+
</details>
|