字節開源Dolphin文檔解析模型-部署指南+實戰測試
在數字化辦公席卷全球的今天,文檔解析技術已成為企業數字化轉型的關鍵瓶頸。面對海量的合同、報告、論文等文檔資料,傳統解決方案要么速度緩慢,要么錯誤百出。5月22日,字節跳動開源的全新文檔解析模型Dolphin橫空出世,憑借僅322M參數的輕量級架構,在性能上實現了對GPT-4.1、Claude3.5等重量級模型的全面超越!
github: https://github.com/bytedance/Dolphin
在線Demo: http://115.190.42.15:8888/dolphin
下面開始部署指南:
一、安裝依賴環境
# 下載代碼
git clone https://github.com/ByteDance/Dolphin.git
cd Dolphin
# 創建虛擬環境
conda create -n Dolphin python=3.11
# 激活虛擬環境
conda activate Dolphin
# 安裝uv
pip install uv -i https://pypi.tuna.tsinghua.edu.cn/simple/
# 修改numpy版本
先修改requirements.txt文件,否則會報錯,報錯信息放在了文末:
把numpy==1.24.4 改為 numpy==1.26.0
# 安裝requirements.txt依賴包
uv pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
二、下載模型權重
選項A:原始模型格式(基于配置)
從百度云或谷歌驅動器下載,并將它們放在。/checkpoint文件夾中。
百度網盤:??https://pan.baidu.com/share/init?surl=5zcARoX0CTOHKbW8bFZovQ&pwd=9rpx??
谷歌云盤:??https://drive.google.com/drive/folders/1PQJ3UutepXvunizZEw-uGaQ0BCzf-mie??
選項B:Huggingface模型格式
huggingface模型地址:??https://huggingface.co/ByteDance/Dolphin??
魔搭的模型地址:??https://www.modelscope.cn/models/ByteDance/Dolphin??
#從Hugging Face Hub下載模型
Git LFS安裝
git clone https://huggingface.co/ByteDance/Dolphin ./hf_model
本文采用選項A:原始模型格式,百度網盤下載模型權重,放入checkpoints 目錄中;
三、實戰測試效果
模型推理的配置文件:
1、頁面級解析(Page-level Parsing)
解析單個文檔圖片(page_1.jpeg)
python demo_page.py --config ./config/Dolphin.yaml --input_path ./demo/page_imgs/page_1.jpeg --save_dir ./results
輸出結果:
顯存占用量高達15g多;
處理一個目錄中的所有文檔圖像
json和md文件都會生成一份;
python demo_page.py --config ./config/Dolphin.yaml --input_path ./demo/page_imgs --save_dir ./results
運行日志截圖:
顯存截圖:顯存占用量最高達到17g;
2、元素級解析(Element-level Parsing)
Using Original Framework (config-based)
# Process a single table image
python demo_element.py --config ./config/Dolphin.yaml --input_path ./demo/element_imgs/table_1.jpeg --element_type table
# Process a single formula image
python demo_element.py --config ./config/Dolphin.yaml --input_path ./demo/element_imgs/line_formula.jpeg --element_type formula
# Process a single text paragraph image
python demo_element.py --config ./config/Dolphin.yaml --input_path ./demo/element_imgs/para_1.jpg --element_type text
# Process a single table image 顯存截圖
# Process a single formula image 顯存截圖
1、單個段落處理
結果:
2、單個表格處理
結果:
把md文件,在線解析一下看看,表格還原程度如何:
模型解析的md結果:
原始圖片的:
結果竟然是正確的,效果很厲害!
3、單行公式處理
結果:
部署中常見的錯誤:
numpy==1.24.4 與opencv-pythnotallow==4.11.0.86 版本沖突的報錯信息:
and opencv-pythnotallow==4.11.0.86 depends on numpy>=1.26.0, we can conclude that opencv-pythnotallow==4.11.0.86 depends on numpy>=1.26.0.
And because you require numpy==1.24.4 and opencv-pythnotallow==4.11.0.86, we can conclude that your requirements are unsatisfiable.
解決方案:
修改numpy版本
先修改requirements.txt文件:
把numpy==1.24.4 改為 numpy==1.26.0
總結:本文手把手教學,從零開始安裝Dolphin項目,使用官方示例代碼,測試過程中發現,元素級解析顯存占用5G左右,頁面級解析顯存占用到達17G,這個確實令人驚訝,不過看著效果還可以的,尤其是表格解析,挺不錯的,快來一起本地部署使用吧!
本文轉載自??????AI小新??????,作者:AI小新
