LaTeX OCR - 数学公式识别系统

文章目录


一、关于 LaTeX OCR

1、项目概览

基于 Seq2Seq + Attention + Beam Search 架构的数学公式识别系统,可将数学公式图片转换为 LaTeX 代码。


架构图


2、相关链接资源


3、功能特性

1、多平台支持

  • 支持 Linux/Mac/Windows 系统
  • 提供一键安装脚本

2、可视化训练

  • 集成 TensorBoard 训练过程可视化
  • 支持注意力机制可视化

3、评估指标

  • 支持 perplexity/EditDistance/BLEU-4/ExactMatchScore 四种评估指标

二、安装配置

基础环境要求

  1. Python 3.5 + TensorFlow 1.12.2
  2. LaTeX (latex 转 pdf)
  3. Ghostscript (图片处理)
  4. ImageMagick (pdf 转 png)

Linux 安装

一键安装

shell 复制代码
make install-linux

或分步安装

bash 复制代码
# 创建环境 
virtualenv env35 --python=python3.5
source env35/bin/activate
pip install -r requirements.txt

# 安装 latex (latex 转 pdf)
sudo apt-get install texlive-latex-base texlive-latex-extra

# 安装 ghostscript
sudo apt-get update && sudo apt-get install ghostscript libgs-dev

# 安装 magick (pdf 转 png)
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar -xvf ImageMagick.tar.gz
cd ImageMagick-7.*
./configure --with-gslib=yes
make
sudo make install
sudo ldconfig /usr/local/lib
rm ImageMagick.tar.gz
rm -r ImageMagick-7.*

Mac 安装

一键安装

shell 复制代码
make install-mac

分步安装

bash 复制代码
sudo pip install -r requirements.txt
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar -xvf ImageMagick.tar.gz
cd ImageMagick-7.*
./configure --with-gslib=yes
make
sudo make install
rm ImageMagick.tar.gz
rm -r ImageMagick-7.*

三、使用指南

1、快速训练(小数据集)

一键训练(约2分钟)

shell 复制代码
make small

分步执行

bash 复制代码
python build.py --data=configs/data_small.json --vocab=configs/vocab_small.json
python train.py --data=configs/data_small.json --vocab=configs/vocab_small.json --training=configs/training_small.json --model=configs/model.json --output=results/small/
python evaluate_txt.py --results=results/small/
python evaluate_img.py --results=results/small/

2、完整训练(大数据集)

一键训练(2-3小时)

shell 复制代码
make full

分步执行

bash 复制代码
python build.py --data=configs/data.json --vocab=configs/vocab.json
python train.py --data=configs/data.json --vocab=configs/vocab.json --training=configs/training.json --model=configs/model.json --output=results/full/
python evaluate_txt.py --results=results/full/
python evaluate_img.py --results=results/full/

四、可视化功能

训练过程可视化

bash 复制代码
# 小数据集
cd results/small
tensorboard --logdir ./

# 大数据集
cd results/full
tensorboard --logdir ./

预测过程可视化

bash 复制代码
python visualize_attention.py --image=data/images_test/6.png --vocab=configs/vocab.json --model=configs/model.json --output=results/full/

五、模型评估

指标 训练分数 测试分数
perplexity 1.39 1.44
EditDistance 81.68 80.45
BLEU-4 78.21 75.42
ExactMatchScore 13.93 12.44

六、技术细节

数据处理流程

  1. 获取 LaTeX 公式数据
  2. 公式规范化处理
  3. 生成图片数据集
  4. 构建字典和映射文件

模型架构

  • Encoder: CNN
  • Decoder: LSTM/GRU
  • 注意力机制层
  • Beam Search/Greedy 输出策略

伊织 xAI 2025-05-18(日)

相关推荐
昔时扬尘处几秒前
【Files Content Replace】文件夹文件内容批量替换自动化测试脚本
c语言·python·pytest·adi
杨浦老苏14 分钟前
隐私优先的图片遮蔽工具AutoRedact
docker·ai·工具·群晖·图片
xian_wwq15 分钟前
【学习笔记】打造可复现、可评测、可迭代的AI技术体系
笔记·学习·ai
咖啡の猫17 分钟前
Python字典的查询操作
数据库·python·c#
smile_Iris1 小时前
Day 38 GPU训练及类的call方法
开发语言·python
嗷嗷哦润橘_1 小时前
AI Agent学习:MetaGPT项目之RAG
人工智能·python·学习·算法·deepseek
Smart-Space1 小时前
tkinter绘制组件(47)——导航边栏
python·tkinter·tinui
ULTRA??1 小时前
KD-Tree的查询原理
python·算法
电饭叔2 小时前
TypeError:unsupported operand type(s) for -: ‘method‘ and ‘int‘
开发语言·笔记·python
老歌老听老掉牙2 小时前
使用贝叶斯因子量化假设验证所需数据量
python·贝叶斯因子·假设