源码位置: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
文件夹内文章来源:https://www.toymoban.com/news/detail-504387.html
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
输入:
输出:
文章来源地址https://www.toymoban.com/news/detail-504387.html
到了这里,关于SAM(segment anything model)本地部署复现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!