OCR 通用端到端模型GOT

摘要

在人工智能领域,光学字符识别(OCR)技术已经取得了显著的进展。随着技术的不断进步,我们正迈向OCR 2.0时代。本文将介绍由Vary团队开发的通用端到端模型GOT,这一模型在OCR领域具有革命性的潜力。

论文概览

  • 论文标题:GOT: Towards OCR-2.0
  • 发布平台:arXiv
  • 链接arXiv.org

模型特点

GOT模型是首个迈向OCR 2.0时代的通用端到端模型,它在多个方面展现了其先进性:

  1. 多任务支持:GOT模型支持多种OCR任务,包括场景文本OCR、文档OCR、细粒度OCR以及更通用的OCR任务。
  2. 输出格式多样:除了支持纯文本输出,GOT还能输出格式化文本,如Markdown格式,增强了文本的可读性和可编辑性。
  3. 结构优化 :采用vision encoder + input embedding layer + decoder的架构,其中encoder部分采用带local attention的VITDet架构,有效管理显存使用。

训练方法

GOT模型的训练分为三个阶段:

  1. 第一阶段:高效预训练encoder,使用小型OPT-125M作为decoder,快速引入大量数据。
  2. 第二阶段:联合训练encoder-decoder,使用Qwen团队预训练的Qwen0.5B,适当增大decoder以适应OCR-2.0的知识需求。
  3. 第三阶段 :锁定encoder,加强decoder以适配更多OCR应用场景,如支持坐标或颜色引导的细粒度OCR,动态分辨率OCR技术,多页OCR技术。

数据工程

研究团队在数据工程方面投入巨大,学习并使用了多种数据渲染工具,包括Latex、Mathpix-markdown-it、Matplotlib、Tikz、Verovio、Pyecharts等,以构造多样化的数据。

项目地址

对GOT模型感兴趣的研究者和开发者可以通过以下链接访问项目代码:
GitHub - Ucas-HaoranWei/GOT-OCR2.0

安装

基础环境cuda11.8+torch2.0.1

克隆仓库并导航到GOT文件夹

bash 复制代码
git clone https://github.com/Ucas-HaoranWei/GOT-OCR2.0.git 
cd 'the GOT folder'

安装包

Shell 复制代码
conda create -n got python=3.10 -y
conda activate got
pip install -e .

安装 Flash-Attention

Shell 复制代码
pip install ninja
pip install flash-attn --no-build-isolation

GOT 权重

演示

  1. 普通文本OCR:
Shell 复制代码
python3 GOT/demo/run_ocr_2.0.py  --model-name  /GOT_weights/  --image-file  /an/image/file.png  --type ocr
  1. 格式文本OCR:
Shell 复制代码
python3 GOT/demo/run_ocr_2.0.py  --model-name  /GOT_weights/  --image-file  /an/image/file.png  --type format
  1. 细粒度OCR:
Shell 复制代码
python3 GOT/demo/run_ocr_2.0.py  --model-name  /GOT_weights/  --image-file  /an/image/file.png  --type format/ocr --box [x1,y1,x2,y2]
Shell 复制代码
python3 GOT/demo/run_ocr_2.0.py  --model-name  /GOT_weights/  --image-file  /an/image/file.png  --type format/ocr --color red/green/blue
  1. 多裁剪OCR:
Shell 复制代码
python3 GOT/demo/run_ocr_2.0_crop.py  --model-name  /GOT_weights/ --image-file  /an/image/file.png 
  1. 多页OCR (图像路径包含多个.png文件):
Shell 复制代码
python3 GOT/demo/run_ocr_2.0_crop.py  --model-name  /GOT_weights/ --image-file  /images/path/  --multi-page
  1. 渲染格式化OCR结果:
Shell 复制代码
python3 GOT/demo/run_ocr_2.0.py  --model-name  /GOT_weights/  --image-file  /an/image/file.png  --type format --render

注意 :

渲染结果可以在/results/demo.html中找到。请打开demo.html查看结果。

训练

  1. 训练样本可以在此链接找到。注意,在'conversations'-'human'-'value'中的'<image>'是必要的!
  2. 此代码库仅支持在我们GOT权重上的后训练(第二/第三阶段)。
  3. 如果你想从我们论文中描述的第一阶段训练,你需要这个仓库
Shell 复制代码
deepspeed   /GOT-OCR-2.0-master/GOT/train/train_GOT.py \
 --deepspeed /GOT-OCR-2.0-master/zero_config/zero2.json    --model_name_or_path /GOT_weights/ \
 --use_im_start_end True   \
 --bf16 True   \
 --gradient_accumulation_steps 2    \
 --evaluation_strategy "no"   \
 --save_strategy "steps"  \
 --save_steps 200   \
 --save_total_limit 1   \
 --weight_decay 0.    \
 --warmup_ratio 0.001     \
 --lr_scheduler_type "cosine"    \
 --logging_steps 1    \
 --tf32 True     \
 --model_max_length 8192    \
 --gradient_checkpointing True   \
 --dataloader_num_workers 8    \
 --report_to none  \
 --per_device_train_batch_size 2    \
 --num_train_epochs 1 \
 --learning_rate 2e-5   \
 --datasets pdf-ocr+scence \
 --output_dir /your/output.path

注意:

  1. 更改constant.py中相应的数据信息。
  2. 更改conversation_dataset_qwen.py中第37行为你的数据名称。

评估

  1. 使用FoxOneChart基准,其他基准可以在权重下载链接中找到。
  2. 评估代码可以在GOT/eval中找到。
  3. 你可以使用evaluate_GOT.py运行评估。如果你有8个GPU,--num-chunks可以设置为8。
Shell 复制代码
python3 GOT/eval/evaluate_GOT.py --model-name /GOT_weights/ --gtfile_path xxxx.json --image_path  /image/path/ --out_path /data/eval_results/GOT_mathpix_test/ --num-chunks 8 --datatype OCR
相关推荐
AI人工智能+12 分钟前
一种融合大模型微调与高精度OCR的智能文档抽取系统,实现对合同文本中关键要素的高精度语义理解与结构化抽取
人工智能·语言模型·ocr·文档抽取
余俊晖1 小时前
多模态文档解析新思路:MinerU-Diffusion通过扩散解码进行文档OCR
人工智能·ocr·多模态
带娃的IT创业者2 小时前
文档扫描工具开发:高拍仪硬件集成与图像处理流水线
jvm·图像处理·人工智能·ocr·文档扫描·glm-4.6v·高拍仪
熊猫钓鱼>_>1 天前
MinerU的正确使用方式:如何解析PDF成标准化向量数据,以供AI大模型等场景应用
人工智能·阿里云·架构·pdf·ocr·skill·mineru
开开心心就好2 天前
免费自媒体多功能工具箱,图片音视频处理
人工智能·pdf·ocr·excel·音视频·语音识别·媒体
AI人工智能+2 天前
银行回单识别技术:融合计算机视觉与自然语言处理,实现对多版式回单的高精度解析
深度学习·计算机视觉·ocr·银行回单识别
Predestination王瀞潞3 天前
1.3.1 AI->Tesseract OCR Engine标准(HP、Google):Tesseract OCR Engine
人工智能·ocr
OpenCSG3 天前
百度千帆开源 Qianfan-OCR:端到端文档智能模型的架构革命
百度·架构·ocr
feasibility.4 天前
让OpenCode/OpenClaw的AI/Agent准确识别图表文字:PaddleOCR-VL-1.5 封装为全局 OCR skills
人工智能·aigc·ocr·ai编程
AI人工智能+4 天前
融合计算机视觉与自然语言处理的道路运输经营许可证识别技术,实现从图像预处理、关键信息定位、字符识别到语义结构化输出的端到端闭环
计算机视觉·自然语言处理·ocr·道路运输经营许可证识别