DocLayout-YOLO
约 1 分钟阅读
标签:YOLO
- opendatalab/DocLayout-YOLOGitHubopendatalab/DocLayout-YOLOopendatalab/DocLayout-YOLO · AGPLv3, Python, YOLOv10 · https://huggingface.co/spaces/opendatalab/DocLayout-YOLO · classes笔记:DocLayout-YOLO
- AGPLv3, Python, YOLOv10
- HF Space:opendatalab/DocLayout-YOLOHuggingFaceHF Space:opendatalab/DocLayout-YOLOopendatalab/DocLayout-YOLO · AGPLv3, Python, YOLOv10 · https://huggingface.co/spaces/opendatalab/DocLayout-YOLO · classeshuggingface.co · huggingface.co/spaces/opendatalab/DocLayout-YOLO笔记:DocLayout-YOLO
- classes
- title
- plain text
- abandon
- figure
- figure_caption
- table
- table_caption
- table_footnote
- isolate_formula
- formula_caption
#%%
from doclayout_yolo import YOLOv10
from huggingface_hub import hf_hub_download
# model = YOLOv10.from_pretrained("juliozhao/DocLayout-YOLO-DocStructBench")
filepath = hf_hub_download(repo_id="juliozhao/DocLayout-YOLO-DocStructBench",
filename="doclayout_yolo_docstructbench_imgsz1024.pt")
model = YOLOv10(filepath)
#%%
import torch
device = torch.device((
"cuda"
if torch.cuda.is_available()
else "mps"
if torch.backends.mps.is_available()
else "cpu"
))
det_res = model.predict("input/2003-D30-000-0013.jpg", imgsz=1024, device=device)
#%%
import cv2
annotated_frame = det_res[0].plot(pil=True, line_width=5, font_size=20)
cv2.imwrite("result.jpg", annotated_frame)
#%%
result = det_res[0]
table_class_id = None
for id, name in det_res[0].names.items():
if name == "table":
table_class_id = id
break
table_class_id
#%%
table_boxes = []
for i, cls in enumerate(result.boxes.cls):
if int(cls.item()) == table_class_id:
# 获取表格边界框 [x1, y1, x2, y2]
box = result.boxes.xyxy[i].cpu().numpy()
# 获取置信度
conf = result.boxes.conf[i].item()
table_boxes.append({
"xywh": box.tolist(),
"confidence": conf
})
table_boxes
关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
GitHub1 条
- opendatalab/DocLayout-YOLOgithub.com/opendatalab/DocLayout-YOLO
HuggingFace1 条
- HF Space:opendatalab/DocLayout-YOLOhuggingface.co/spaces/opendatalab/DocLayout-YOLO