跳转到主要内容

快速分割任何东西

项目描述

快速分割任何东西

image

[📕论文] [🤗HuggingFace演示] [Colab演示] [Replicate演示 & API] [模型库] [BibTeX]

FastSAM Speed

Fast Segment Anything Model(FastSAM) 是一个仅使用SAM作者发布的SA-1B数据集的2%训练的CNN分割任何东西模型。FastSAM在比SAM方法快50倍的时间内达到可比较的性能。

FastSAM design

🍇 更新

安装

在本地克隆存储库

pip install segment-anything-fast

入门

首先下载一个 模型检查点

然后,您可以运行脚本尝试所有模式以及三种提示模式。

# Everything mode
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg
# Text prompt
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg  --text_prompt "the yellow dog"
# Box prompt (xywh)
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --box_prompt "[[570,200,230,400]]"
# Points prompt
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg  --point_prompt "[[520,360],[620,300]]" --point_label "[1,0]"

您可以使用以下代码生成所有掩码,根据提示进行掩码选择,并可视化结果。

from fastsam import FastSAM, FastSAMPrompt

model = FastSAM('./weights/FastSAM.pt')
IMAGE_PATH = './images/dogs.jpg'
DEVICE = 'cpu'
everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9,)
prompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)

# everything prompt
ann = prompt_process.everything_prompt()

# bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]
ann = prompt_process.box_prompt(bbox=[[200, 200, 300, 300]])

# text prompt
ann = prompt_process.text_prompt(text='a photo of a dog')

# point prompt
# points default [[0,0]] [[x1,y1],[x2,y2]]
# point_label default [0] [1,0] 0:background, 1:foreground
ann = prompt_process.point_prompt(points=[[620, 360]], pointlabel=[1])

prompt_process.plot(annotations=ann,output_path='./output/dog.jpg',)

也欢迎您尝试我们的 Colab 演示: FastSAM_example.ipynb

不同的推理选项

我们为不同的目的提供了各种选项,详细信息请参阅 MORE_USAGES.md

网络演示

Gradio 演示

  • 我们还提供了一个使用 gradio 构建的测试我们方法的 UI。您可以上传自定义图像,选择模式并设置参数,点击分割按钮,并获得满意的分割结果。目前,该 UI 支持与 '所有模式' 和 '点模式' 交互。我们计划在将来添加对其他模式的支持。在终端运行以下命令将启动演示
# Download the pre-trained model in "./weights/FastSAM.pt"
python app_gradio.py

HF_Everyhting HF_Points

复制演示

  • Replicate 演示 已支持所有模式,您可以体验点/框/文本模式。

Replicate-1 Replicate-2 Replicate-3

模型检查点

该模型有两种不同大小的版本。点击以下链接下载对应模型类型的检查点。

结果

所有结果均在单个 NVIDIA GeForce RTX 3090 上测试。

1. 推理时间

不同点提示数量下的运行速度(毫秒)。

方法 参数 1 10 100 E(16x16) E(32x32*) E(64x64)
SAM-H 0.6G 446 464 627 852 2099 6972
SAM-B 136M 110 125 230 432 1383 5417
FastSAM 68M 40 40 40 40 40 40

2. 内存使用

数据集 方法 GPU 内存(MB)
COCO 2017 FastSAM 2608
COCO 2017 SAM-H 7060
COCO 2017 SAM-B 4670

3. 零样本迁移实验

边缘检测

在 BSDB500 数据集上进行测试。

方法 年份 ODS OIS AP R50
HED 2015 .788 .808 .840 .923
SAM 2023 .768 .786 .794 .928
FastSAM 2023 .750 .790 .793 .903

对象提议

COCO
方法 AR10 AR100 AR1000 AUC
SAM-H E64 15.5 45.6 67.7 32.1
SAM-H E32 18.5 49.5 62.5 33.7
SAM-B E32 11.4 39.6 59.1 27.3
FastSAM 15.7 47.3 63.7 32.2
LVIS

bbox AR@1000

方法 所有 小型 中型 大型
ViTDet-H 65.0 53.2 83.3 91.2
零样本迁移方法
SAM-H E64 52.1 36.6 75.1 88.2
SAM-H E32 50.3 33.1 76.2 89.8
SAM-B E32 45.0 29.3 68.7 80.6
FastSAM 57.1 44.3 77.1 85.3

在 COCO 2017 上的实例分割

方法 AP APS APM APL
ViTDet-H .510 .320 .543 .689
SAM .465 .308 .510 .617
FastSAM .379 .239 .434 .500

4. 性能可视化

几个分割结果

自然图像

Natural Images

文本到掩码

Text to Mask

5. 下游任务

展示了几个下游任务的结果以展示其有效性。

异常检测

Anomaly Detection

显著物体检测

Salient Object Detection

建筑提取

Building Detection

许可证

该模型采用 Apache 2.0 许可证 许可。

致谢

贡献者

没有这些杰出人士的贡献,我们的项目不可能实现!感谢大家使这个项目变得更好。

引用 FastSAM

如果您认为这个项目对您的研究有用,请考虑引用以下 BibTeX 条目。

@misc{zhao2023fast,
      title={Fast Segment Anything},
      author={Xu Zhao and Wenchao Ding and Yongqi An and Yinglong Du and Tao Yu and Min Li and Ming Tang and Jinqiao Wang},
      year={2023},
      eprint={2306.12156},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

Star History Chart

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

segment-anything-fast-0.1.2.tar.gz (23.0 kB 查看哈希值)

上传时间

构建分布

segment_anything_fast-0.1.2-py3-none-any.whl (20.5 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面