🚀 DIT-base-layout-detection
このモデルcmarkea/dit-base-layout-detectionは、文書の画像から異なるレイアウト(テキスト、画像、キャプション、脚注など)を抽出することができます。
これは、DocLayNetデータセットでdit-baseモデルをファインチューニングしたものです。ODQAシステムに取り込むための文書コーパスを処理するのに最適です。
このモデルは、キャプション、脚注、数式、リスト項目、ページフッター、ページヘッダー、画像、セクションヘッダー、表、テキスト、タイトルという11のエンティティを抽出することができます。
✨ 主な機能
性能評価
このセクションでは、セマンティックセグメンテーションと物体検出をそれぞれ考慮して、モデルの性能を評価します。セマンティックセグメンテーションには、何らの後処理も行っていません。物体検出に関しては、OpenCVのfindContours
を適用しただけで、それ以上の後処理は行っていません。
セマンティックセグメンテーションについては、各ピクセルの分類を評価するためにF1スコアを使用します。物体検出については、Generalized Intersection over Union (GIoU)と予測されたバウンディングボックスのクラスの精度に基づいて性能を評価します。評価は、DocLayNetのPDF評価データセットの500ページに対して行われます。
クラス |
f1スコア (x100) |
GIoU (x100) |
精度 (x100) |
背景 |
94.98 |
NA |
NA |
キャプション |
75.54 |
55.61 |
72.62 |
脚注 |
72.29 |
50.08 |
70.97 |
数式 |
82.29 |
49.91 |
94.48 |
リスト項目 |
67.56 |
35.19 |
69 |
ページフッター |
83.93 |
57.99 |
94.06 |
ページヘッダー |
62.33 |
65.25 |
79.39 |
画像 |
78.32 |
58.22 |
92.71 |
セクションヘッダー |
69.55 |
56.64 |
78.29 |
表 |
83.69 |
63.03 |
90.13 |
テキスト |
90.94 |
51.89 |
88.09 |
タイトル |
61.19 |
52.64 |
70 |
ベンチマーク
ここでは、このモデルの性能を他のモデルと比較します。
💻 使用例
基本的な使用法
import torch
from transformers import AutoImageProcessor, BeitForSemanticSegmentation
img_proc = AutoImageProcessor.from_pretrained(
"cmarkea/dit-base-layout-detection"
)
model = BeitForSemanticSegmentation.from_pretrained(
"cmarkea/dit-base-layout-detection"
)
img: PIL.Image
with torch.inference_mode():
input_ids = img_proc(img, return_tensors='pt')
output = model(**input_ids)
segmentation = img_proc.post_process_semantic_segmentation(
output,
target_sizes=[img.size[::-1]]
)
高度な使用法
ここには、セマンティックセグメンテーションからバウンディングボックスを検出する簡単な方法を示します。これは、「性能評価」セクションで説明したように、物体検出におけるモデルの性能を計算するために使用される方法です。この方法は、追加の後処理なしで提供されています。
import cv2
def detect_bboxes(masks: np.ndarray):
r"""
A simple bounding box detection function
"""
detected_blocks = []
contours, _ = cv2.findContours(
masks.astype(np.uint8),
cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE
)
for contour in list(contours):
if len(list(contour)) >= 4:
x, y, width, height = cv2.boundingRect(contour)
bounding_box = [x, y, x + width, y + height]
detected_blocks.append(bounding_box)
return detected_blocks
bbox_pred = []
for segment in segmentation:
boxes, labels = [], []
for ii in range(1, len(model.config.label2id)):
mm = segment == ii
if mm.sum() > 0:
bbx = detect_bboxes(mm.numpy())
boxes.extend(bbx)
labels.extend([ii]*len(bbx))
bbox_pred.append(dict(boxes=boxes, labels=labels))
実行例

📚 詳細ドキュメント
引用
@online{DeDitLay,
AUTHOR = {Cyrile Delestre},
URL = {https://huggingface.co/cmarkea/dit-base-layout-detection},
YEAR = {2024},
KEYWORDS = {Image Processing ; Transformers ; Layout},
}
📄 ライセンス
このプロジェクトは、Apache-2.0ライセンスの下で公開されています。