在数字化办公席卷全球的今天,文档解析技术 已成为企业数字化转型的关键瓶颈。面对海量的合同、报告、论文等文档资料,传统解决方案要么速度缓慢 ,要么错误百出 。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
解析单个文档图片(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-python==4.11.0.86 版本冲突的报错信息:
and opencv-python==4.11.0.86 depends on numpy>=1.26.0, we can conclude that opencv-python==4.11.0.86 depends on numpy>=1.26.0.
And because you require numpy==1.24.4 and opencv-python==4.11.0.86, we can conclude that your requirements are unsatisfiable.解决方案:
修改numpy版本 先修改requirements.txt文件:
把numpy==1.24.4 改为 numpy==1.26.0
ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 16px;margin: 0px;line-height: 26px;color: black;">总结:本文手把手教学,从零开始安装Dolphin项目,使用官方示例代码,测试过程中发现,元素级解析显存占用5G左右,页面级解析显存占用到达17G,这个确实令人惊讶,不过看着效果还可以的,尤其是表格解析,挺不错的,快来一起本地部署使用吧!