🚀 SlimSAM:0.1%数据让任意分割模型瘦身
SlimSAM是一种新颖的SAM压缩方法,通过高效复用预训练的SAM模型,在无需大量重新训练的情况下,显著减少了模型的参数数量和计算量,同时仅需使用原模型0.1%的训练数据,就能达到接近原模型的性能。
🚀 快速开始
模型使用
以下是本地统一剪枝的SlimSAM - 50模型的快速状态字典加载示例:
model = SamModel.from_pretrained("Zigeng/SlimSAM-uniform-50").to("cuda")
processor = SamProcessor.from_pretrained("Zigeng/SlimSAM-uniform-50")
img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
input_points = [[[450, 600]]]
inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to("cuda")
outputs = model(**inputs)
masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
scores = outputs.iou_scores
✨ 主要特性
高效复用预训练模型
SlimSAM通过统一的剪枝 - 蒸馏框架,高效复用预训练的SAM模型,无需大量重新训练。
交替瘦身策略
采用创新的交替瘦身策略,将压缩过程划分为渐进式步骤,交替修剪和蒸馏解耦的模型结构,与以往的修剪技术不同。
无标签剪枝准则
提出了一种新颖的无标签剪枝准则,使剪枝目标与优化目标一致,提高剪枝后的蒸馏效果。
显著的性能提升
与原始的SAM - H相比,SlimSAM在将参数数量减少到0.9%(570万)、MACs减少到0.8%(21G),且仅需0.1%(1万)的训练数据的情况下,仍能达到接近的性能。与其他SAM压缩方法相比,在使用少10倍以上训练数据的情况下,实现了显著更优的性能。
📚 详细文档
简介
SlimSAM是一种新颖的SAM压缩方法,它通过统一的剪枝 - 蒸馏框架,高效复用预训练的SAM模型,无需大量重新训练。为了增强从原始SAM继承的知识,我们采用了一种创新的交替瘦身策略,将压缩过程划分为渐进式步骤。与以往的剪枝技术不同,我们交替修剪和蒸馏解耦的模型结构。此外,还提出了一种新颖的无标签剪枝准则,使剪枝目标与优化目标一致,从而提高剪枝后的蒸馏效果。
SlimSAM在将参数数量减少到0.9%(570万)、MACs减少到0.8%(21G),且仅需0.1%(1万)的训练数据的情况下,仍能达到接近原始SAM - H的性能。大量实验表明,与其他SAM压缩方法相比,我们的方法在使用少10倍以上训练数据的情况下,实现了显著更优的性能。
📄 许可证
本项目采用Apache - 2.0许可证。
📚 BibTex引用
如果您在研究中使用了SlimSAM,请使用以下BibTeX条目。感谢您的支持!
@misc{chen202301,
title={0.1% Data Makes Segment Anything Slim},
author={Zigeng Chen and Gongfan Fang and Xinyin Ma and Xinchao Wang},
year={2023},
eprint={2312.05284},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
致谢
SAM (Segment Anything) [bib]
@article{kirillov2023segany,
title={Segment Anything},
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},
journal={arXiv:2304.02643},
year={2023}
}
Torch Pruning (DepGraph: Towards Any Structural Pruning) [bib]
@inproceedings{fang2023depgraph,
title={Depgraph: Towards any structural pruning},
author={Fang, Gongfan and Ma, Xinyin and Song, Mingli and Mi, Michael Bi and Wang, Xinchao},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={16091--16101},
year={2023}
}