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(日)

相关推荐
站大爷IP14 分钟前
Python 办公实战:用 python-docx 自动生成 Word 文档
python
master-dragon23 分钟前
spring-ai 工作流
人工智能·spring·ai
MO2T40 分钟前
使用 Flask 构建基于 Dify 的企业资金投向与客户分类评估系统
后端·python·语言模型·flask
慢热型网友.43 分钟前
用 Docker 构建你的第一个 Python Flask 程序
python·docker·flask
Naiva43 分钟前
【小技巧】Python + PyCharm 小智AI配置MCP接入点使用说明(内测)( PyInstaller打包成 .exe 可执行文件)
开发语言·python·pycharm
云动雨颤1 小时前
Python 自动化办公神器|一键转换所有文档为 PDF
运维·python
梅孔立1 小时前
yum update 报错 Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64 等解决办法
linux·python·centos
前端付豪1 小时前
13、你还在 print 调试🧾?教你写出自己的日志系统
后端·python
这里有鱼汤1 小时前
hvPlot:用你熟悉的 Pandas,画出你没见过的炫图
后端·python
源码站~2 小时前
基于Flask+Vue的豆瓣音乐分析与推荐系统
vue.js·python·flask·毕业设计·毕设·校园·豆瓣音乐