If you fid our work helpful for your research, please cosider citig the followig BibTeX etry. 模型描述 (Model Descriptio)
运行环境 (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
@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}
}
点击空白处退出提示
评论