🚀 Florence-2-DocLayNet-Fixed
本項目微調後的模型能夠有效解決類別名稱生成問題,提升了檢測性能,在特定場景下表現出色,同時為相關研究提供了可複用的模型權重。
🚀 快速開始
使用以下代碼即可開始使用該模型:
import requests
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("yifeihu/Florence-2-DocLayNet-Fixed", trust_remote_code=True)
processor = AutoProcessor.from_pretrained("yifeihu/Florence-2-DocLayNet-Fixed", trust_remote_code=True)
prompt = "<OD>"
url = "https://huggingface.co/yifeihu/TF-ID-base/resolve/main/arxiv_2305_10853_5.png?download=true"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=prompt, images=image, return_tensors="pt")
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
do_sample=False,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task="<OD>", image_size=(image.width, image.height))
print(parsed_answer)
若要可視化結果,請參考 此教程筆記本 獲取更多詳情。
✨ 主要特性
- 微調模型:使用 [DocLayNet-v1.1] 數據集對 Florence-2-large-ft [HF] 模型進行微調。
- 類別名稱重映射:為防止模型生成幻覺類別名稱,將所有類別名稱重新映射為單個標記,提升了 mAP50 - 95 分數,並加快了訓練和推理速度。
- 性能表現:在 DocLayNet 測試集上 mAP50 - 95 分數有 7% 的提升;在科學文章子集上,與最佳的 Yolo 模型表現相當;在繪製邊界框方面表現更優,邊界更清晰。
📚 詳細文檔
模型概述
我們使用 [DocLayNet-v1.1] 數據集對 Florence-2-large-ft [HF] 模型進行了微調。為防止模型生成幻覺類別名稱,我們將所有類別名稱重新映射為單個標記:
原始類別名稱 |
新類別名稱 |
Caption |
Cap |
Footnote |
Footnote |
Formula |
Math |
List-item |
List |
Page-footer |
Bottom |
Page-header |
Header |
Picture |
Picture |
Section-header |
Section |
Table |
Table |
Text |
Text |
Title |
Title |
通過這一簡單更改,我們觀察到在 DocLayNet 測試集上 mAP50 - 95 分數提高了 7%。由於類別名稱使用的標記減少,訓練和推理速度也更快。
從 mAP50 - 95 分數來看,該模型在 DocLayNet 測試集上遠未達到 SOTA(70%)。更小的 Yolo 模型(github.com/ppaanngggg/yolo-doclaynet)有更好的基準測試結果(~79%)。在科學文章子集上,該模型在 mAP50 - 95 方面與最佳的 Yolo 模型表現相當(87%)。
然而,經過一些定性分析(論文即將發表),我們發現 Florence - 2 在繪製邊界框時邊界更清晰。Yolo 模型有時會將文本從中間切斷,或者在同一對象上繪製多個邊界框。這些行為在 mAP50 - 95 中未得到嚴重體現,但在實際應用中處理起來很麻煩。在計算 mAP 分數時,我們不得不手動將所有 Florence - 2 輸出的置信度分數設置為 1。
我們發佈微調後的模型權重,供社區進一步研究相關主題。
📄 許可證
本項目採用 Apache - 2.0 許可證。
📖 BibTex和引用信息
@misc{TF-ID,
author = {Yifei Hu},
title = {TF-ID: Table/Figure IDentifier for academic papers},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/ai8hyf/TF-ID}},
}
@article{doclaynet2022,
title = {DocLayNet: A Large Human-Annotated Dataset for Document-Layout Analysis},
doi = {10.1145/3534678.353904},
url = {https://arxiv.org/abs/2206.01062},
author = {Pfitzmann, Birgit and Auer, Christoph and Dolfi, Michele and Nassar, Ahmed S and Staar, Peter W J},
year = {2022}
}