【图像分割】Grounded Segment Anything根据文字自动画框或分割环境配置和使用教程

摘要:1 环境配置  要求:python>=3.8, pytorch>=1.7, torchvision>=0.8官方地址最简单

1 环境配置

要求:python>=3.8, pytorch>=1.7, torchvision>=0.8

官方地址

image.png

最简单的方法是直接Git,Git环境配好的直接Clone就好了,如果没有,请按照下面的流程。

下面 1.1 和 1.2 部分的下载好的文件,下载解压后可以跳过1.1和1.2:

注意:官方Github库每天都在更新,建议下载下面的压缩包以防报错。

链接:https://pan.baidu.com/s/1u-qZK03wcn0dye\_q\_pL5zA 提取码:6666

下载Grounded Segment Anything库

image.png

下载后解压。

下载引用的库

image.png

image.png

分别手动下载这两个引用的库,并保存在Grounded-Segment-Anything文件夹中所对应的位置

使用pip进行安装

安装segment_anything:

python -m pip install -e segment_anything

安装GroundingDINO:

在第1部分中下载好的目录下运行

注意:如果pip安装GroundingDIN失败,大概率电脑的C++有问题或者版本过低。

python -m pip install -e GroundingDINO

安装diffusers:

pip install --upgrade diffusers[torch]

安装grounded-sam-osx:

注意:需要下载好Bash

cd grounded-sam-osx
bash install.sh

安装其他依赖:

pip install opencv-python pycocotools matplotlib onnxruntime onnx ipykernel

下载权重文件

将下列下载好的权重文件放在Grounded-Segment-Anything目录下。

image.png

权重文件1:

https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth

权重文件2:

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

如果下载速度慢:

链接:百度网盘 请输入提取码 提取码:6666 链接:https://pan.baidu.com/s/1UJ8GjXHQhOD\_ZMnzUkSSwg 提取码:6666

根据文字自动画框

在解压好的目录下运行:

python grounding_dino_demo.py --config GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py --grounded_checkpoint groundingdino_swint_ogc.pth --input_image assets/xs_7.jpg --output_dir "outputs" --box_threshold 0.3 --text_threshold 0.25 --text_prompt "tomato" --device "cuda"

我指定画框的是tomato(番茄),效果展示:

image.png

根据文字自动画框并分割

在目录下运行:

python grounded_sam_demo.py --config GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py --grounded_checkpoint groundingdino_swint_ogc.pth --sam_checkpoint sam_vit_h_4b8939.pth --input_image assets/xs_7.jpg --output_dir "outputs" --box_threshold 0.3 --text_threshold 0.25 --text_prompt "tomato" --device "cuda"

效果展示:

生成三个文件(包含一个Json文件):

image.png

image.png

image.png

APP运行

python gradio_app.py

博客原文:CloseAi论坛 - 专业人工智能技术社区

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值