【计算机视觉 | 目标检测】Grounding DINO 深度学习环境的配置(含案例)

Grounding DINO:Marrying DINO with Grounded Pre-Training for Open-Set Object Detection”的官方 PyTorch 实现:SoTA 开放集对象检测器。

一、Helpful Tutorial

论文地址:

https://arxiv.org/abs/2303.05499

在 YouTube 上观看介绍视频:

https://www.youtube.com/watch?v=wxWDt5UiwY8&feature=youtu.be

在这里插入图片描述
Try the Colab Demo:

https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/zero-shot-object-detection-with-grounding-dino.ipynb

Try Official Huggingface Demo:

https://huggingface.co/spaces/ShilongLiu/Grounding_DINO_demo

二、相关的论文工作

2.1 相关的论文整理

在这里插入图片描述

  • Grounded-SAM: Marrying Grounding DINO with Segment Anything
  • Grounding DINO with Stable Diffusion
  • Grounding DINO with GLIGEN for Controllable Image Editing
  • OpenSeeD: A Simple and Strong Openset Segmentation Model
  • SEEM: Segment Everything Everywhere All at Once
  • X-GPT: Conversational Visual Agent supported by X-Decoder
  • GLIGEN: Open-Set Grounded Text-to-Image Generation
  • LLaVA: Large Language and Vision Assistant

2.2 论文的亮点

本工作的亮点:

  1. Open-Set Detection. Detect everything with language!
  2. High Performancce. COCO zero-shot 52.5 AP (training without COCO data!). COCO fine-tune 63.0 AP.
  3. Flexible. Collaboration with Stable Diffusion for Image Editting.

2.3 论文介绍

在这里插入图片描述

2.4 Marrying Grounding DINO and GLIGEN

在这里插入图片描述

2.5 输入和输出的说明 / 提示

  • Grounding DINO accepts an (image, text) pair as inputs.
  • It outputs 900 (by default) object boxes. Each box has similarity scores across all input words. (as shown in Figures below.)
  • We defaultly choose the boxes whose highest similarities are higher than a box_threshold.
  • We extract the words whose similarities are higher than the text_threshold as predicted labels.
  • If you want to obtain objects of specific phrases, like the dogs in the sentence two dogs with a stick., you can select the boxes with highest text similarities with dogs as final outputs.
  • Note that each word can be split to more than one tokens with differetn tokenlizers. The number of words in a sentence may not equal to the number of text tokens.
  • We suggest separating different category names with . for Grounding DINO.
    在这里插入图片描述
    在这里插入图片描述

三、环境配置过程

3.1 我的环境

系统:最新的ubuntu系统

显卡:3090

CUDA:11.3

如果您有 CUDA 环境,请确保设置了环境变量 CUDA_HOME。 如果没有可用的 CUDA,它将在 CPU-only 模式下编译。

3.2 配置过程

3.2.1 Clone the GroundingDINO repository from GitHub

git clone https://github.com/IDEA-Research/GroundingDINO.git

下载后即可找到对应的文件夹:

在这里插入图片描述

3.2.2 Change the current directory to the GroundingDINO folder

cd GroundingDINO/

3.2.3 Install the required dependencies in the current directory

pip3 install -q -e .

不知道为什么,我这个下载一直报错!换一个新的下载方式:

python setup.py install

在这里插入图片描述

但是也会飘红!

这个时候不要害怕,遇到错误的包,直接使用 pip 下载即可,耐得住性子,最后再运行上面的安装命令,即可顺利成功!

在这里插入图片描述

3.2.4 Create a new directory called “weights” to store the model weights

mkdir weights

Change the current directory to the “weights” folder:

cd weights

Download the model weights file:

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

四、测试

Check your GPU ID (only if you’re using a GPU):

nvidia-smi

在这里插入图片描述

Replace {GPU ID}, image_you_want_to_detect.jpg, and “dir you want to save the output” with appropriate values in the following command:

CUDA_VISIBLE_DEVICES={GPU ID} python demo/inference_on_a_image.py \
-c /GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py \
-p /GroundingDINO/weights/groundingdino_swint_ogc.pth \
-i image_you_want_to_detect.jpg \
-o "dir you want to save the output" \
-t "chair"
 [--cpu-only] # open it for cpu mode

当然了,我们也可以使用 Python 进行测试:

from groundingdino.util.inference import load_model, load_image, predict, annotate
import cv2

model = load_model("./GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py", "./GroundingDINO/weights/groundingdino_swint_ogc.pth")
IMAGE_PATH = "./GroundingDINO/weights/1.png"
TEXT_PROMPT = "person . bike . bottle ."
BOX_TRESHOLD = 0.35
TEXT_TRESHOLD = 0.25

image_source, image = load_image(IMAGE_PATH)

boxes, logits, phrases = predict(
    model=model,
    image=image,
    caption=TEXT_PROMPT,
    box_threshold=BOX_TRESHOLD,
    text_threshold=TEXT_TRESHOLD
)

annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)
cv2.imwrite("./GroundingDINO/weights/annotated_image.jpg", annotated_frame)

我们的测试原图片为:

在这里插入图片描述
测试后的图片为:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

### 关于 GroundingDINO 的使用教程 #### 安装与配置过程 为了开始使用 GroundingDINO,需先克隆该项目仓库至本地环境中。命令如下所示: ```bash git clone https://github.com/IDEA-Research/GroundingDINO.git ``` 进入 GroundingDINO 文件夹并创建名为 `weights` 的新目录用于存储模型权重文件[^3]。 接着,在当前目录下安装所需的依赖项。这一步骤通常通过执行位于项目根目录下的 `requirements.txt` 来完成。可以利用 pip 工具来自动化这一流程: ```bash pip install -r requirements.txt ``` #### 启动文件概述 GroundingDINO 项目的启动主要围绕几个核心组件展开。其中,`demo/` 目录包了演示脚本,比如 `test_ap_on_coco.py` 可供开发者快速上手尝试该框架的功能特性;而 `groundingdino/config/` 下则放置着诸如 `GroundingDINO_SwinT_OGC.py` 这样的配置文件,定义了不同实验设置的具体参数[^1]。 对于想要深入理解或调整算法行为的研究人员来说,熟悉这些配置选项是非常重要的。此外,预训练好的模型权重被保存在 `weights/` 文件夹内,例如 `groundingdino_swint_ogc.pth` 就是一个典型的例子,它承载了经过大量数据集训练后的网络参数信息。 #### 使用指南 一旦完成了上述准备工作之后,就可以着手编写自己的应用逻辑或者直接调用现成的例子来进行功能验证。具体而言,可以通过修改 `demo/test_ap_on_coco.py` 中的内容来自定义输入源以及处理方式,进而实现特定场景下的目标检测任务。 #### 相关研究进展 有关 GroundingDINO 背后的理论基础及其创新之处可以在关联文章中找到详细介绍。这部分内容涵盖了多个方面,包括但不限于如何有效地融合视觉特征与自然语言描述之间的联系等前沿话题[^2]。
评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旅途中的宽~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值