SAM(segment anything model)本地部署复现

源码位置:https://github.com/facebookresearch/segment-anything

一、下载

pip install git+https://github.com/facebookresearch/segment-anything.git

或者 直接下载,解压到当前文件夹,并把解压出的文件夹名字改成segment-anything

二、安装

1、进入segment-anything文件夹

cd segment-anything

2、安装

pip install -e .

3、安装其他依赖

pip install opencv-python pycocotools matplotlib onnxruntime onnx

4、下载模型文件到segment-anything文件夹内

default or vit_h:

https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth

vit_l:

https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth

vit_b:

https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth

5、下载数据集

https://ai.facebook.com/datasets/segment-anything-downloads/

或者用自己的图片数据集

三、运行

整体文件结构

python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type> --input <image_or_folder> --output <path/to/output>

例如:在D:\PythonProject\segment-anything\test\input文件夹下放入图片,使用vit_b模型sam_vit_b_01ec64.pth,输出到D:\PythonProject\segment-anything\test\output文件夹内

python scripts/amg.py --checkpoint sam_vit_b_01ec64.pth --model-type vit_b --input D:\PythonProject\segment-anything\test\input --output D:\PythonProject\segment-anything\test\output

输入:

输出:

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年7月15日
下一篇 2023年7月15日

相关推荐