一、本地部署
1.环境要求和基本配置(也可以使用cpu)
**python>=3.8 **
**pytorch>=1.7 **
torchvision>=0.8
拉取项目:github: https://github.com/IDEA-Research/Grounded-Segment-Anything
安装组件模型:
- I**nstall Segment Anything: **
python -m pip install -e segment_anything
- **Install Grounding DINO: **
python -m pip install -e GroundingDINO
- Install RAM & Tag2Text:
git clone https://github.com/xinyu1205/recognize-anything.git
pip install -r ./recognize-anything/requirements.txt
pip install -e ./recognize-anything/
2.权重下载
- GroundingDINO权重
wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
- SAM系列权重(个人选择版本)
SAM:
vit_h: https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
vit_l: https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth
vit_b: https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
SAM-HQ:
vit_h: https://drive.google.com/file/d/1qobFYrI4eyIANfBSmYcGuWRaSIXfMOQ8/view?usp=sharing
vit_l: https://drive.google.com/file/d/1Uk17tDKX1YAKas5knI4y9ZJCo0lRVL0G/view?usp=sharing
vit_b: https://drive.google.com/file/d/11yExZLOve38kRZPfRx_MRxfIAKmfMY47/view?usp=sharing
- RAM系列权重
RAM++ (14M): https://huggingface.co/xinyu1205/recognize-anything-plus-model/blob/main/ram_plus_swin_large_14m.pth
RAM (14M): https://huggingface.co/spaces/xinyu1205/Recognize_Anything-Tag2Text/blob/main/ram_swin_large_14m.pth
Tag2Text (14M): https://huggingface.co/spaces/xinyu1205/Recognize_Anything-Tag2Text/blob/main/tag2text_swin_14m.pth
注意:
如果无法正常从Hugging Face 上在线下载,可以离线对该模型进行下载并导入。执行如下命令:
from transformers import AutoTokenizer, AutoModel
# 指定本地路径
model_path = "./bert-base-uncased"
# 从本地加载tokenizer和模型
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path)
模型的下载地址:google-bert/bert-base-uncased at main (huggingface.co),主要下载一下几个文件:
3.项目所有文件
以上是本人根据自己电脑部署好在本地的所有文件信息。运行的文件为test1.py,其中图像的导入路径以及结果的保存路径都需要根据自己电脑实际路径情况修改即可。中间如有报错,环境中中缺什么包,那就 pip 安装什么就可以了。
4.运行结果
最终所有运行结果保存在outputs文件夹中,具体效果如下所示:
部分目标截图
Mask结果
参考信息:
1、Grounded-SAM(最强Zero-Shot视觉应用):本地部署及各个模块的全网最详细使用教程!-CSDN博客
2、Installation (huggingface.co)