IDEA-GroundingDINO模型

我要开发同款
匿名用户2024年07月31日
110阅读

技术信息

开源地址
https://modelscope.cn/models/goldsj/GroundingDINO
授权协议
Apache License 2.0

作品详情

模型描述 (Model Descriptio)

?Paper | ?️Video |

运行环境 (Operatig eviromet)

coda activate <your_ev>
git cloe https://github.com/IDEA-Research/GroudigDINO.git
cd GroudigDINO
pip istall -e .

代码范例 (Code example)

from modelscope.pipelies import pipelie
import torch
import os
from PIL import Image, ImageDraw, ImageFot
import umpy as p
import requests
from io import BytesIO

def plot_boxes_to_image(image_pil, tgt):
    H, W = tgt["size"]
    boxes = tgt["boxes"]
    labels = tgt["labels"]
    assert le(boxes) == le(labels), "boxes ad labels must have same legth"

    draw = ImageDraw.Draw(image_pil)
    mask = Image.ew("L", image_pil.size, 0)
    mask_draw = ImageDraw.Draw(mask)

    # draw boxes ad masks
    for box, label i zip(boxes, labels):
        # from 0..1 to 0..W, 0..H
        box = box * torch.Tesor([W, H, W, H])
        # from xywh to xyxy
        box[:2] -= box[2:] / 2
        box[2:] += box[:2]
        # radom color
        color = tuple(p.radom.radit(0, 255, size=3).tolist())
        # draw
        x0, y0, x1, y1 = box
        x0, y0, x1, y1 = it(x0), it(y0), it(x1), it(y1)

        draw.rectagle([x0, y0, x1, y1], outlie=color, width=6)
        # draw.text((x0, y0), str(label), fill=color)

        fot = ImageFot.load_default()
        if hasattr(fot, "getbbox"):
            bbox = draw.textbbox((x0, y0), str(label), fot)
        else:
            w, h = draw.textsize(str(label), fot)
            bbox = (x0, y0, w + x0, y0 + h)
        # bbox = draw.textbbox((x0, y0), str(label))
        draw.rectagle(bbox, fill=color)
        draw.text((x0, y0), str(label), fill="white")

        mask_draw.rectagle([x0, y0, x1, y1], fill=255, width=6)

    retur image_pil, mask

pipe = pipelie('tiefag-groudig-dio-task',
                model='goldsj/GroudigDINO', model_revisio='v1.0.0')


iput_image_url = "https://ofasys.oss-c-zhagjiakou.aliyucs.com/data/coco/2014/val2014/COCO_val2014_000000222628.jpg"
respose = requests.get(iput_image_url)
iput_image_file =BytesIO(respose.cotet)

data = {
    'img': iput_image_file,
    'captio': "perso"
}
boxes_filt, pred_phrases = pipe(data)

# visualize pred

image_pil = Image.ope(iput_image_file).covert("RGB")

size = image_pil.size
pred_dict = {
    "boxes": boxes_filt,
    "size": [size[1], size[0]],  # H,W
    "labels": pred_phrases,
}
image_with_box = plot_boxes_to_image(image_pil, pred_dict)[0]
image_with_box.save("./pred.jpg")

Citatio

If you fid our work helpful for your research, please cosider citig the followig BibTeX etry.

@iproceedigs{ShilogLiu2023GroudigDM,
  title={Groudig DINO: Marryig DINO with Grouded Pre-Traiig for Ope-Set Object Detectio},
  author={Shilog Liu ad Zhaoyag Zeg ad Tiahe Re ad Feg Li ad Hao Zhag ad Jie Yag ad Chuyua Li ad Jiawei Yag ad Hag Su ad Ju Zhu ad Lei Zhag},
  year={2023}
}

功能介绍

模型描述 (Model Description) ?Paper | ?️Video | 运行环境 (Operating environment) conda activate

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论