TexTellerv2 release

This commit is contained in:
三洋三洋
2024-03-25 11:23:54 +00:00
parent 86443d0cf7
commit 63b8e04dab
5 changed files with 24 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
📄 English | <a href="./assets/README_zh.md">中文</a>
<div align="center"> <div align="center">
<h1> <h1>
<img src="./assets/fire.svg" width=30, height=30> <img src="./assets/fire.svg" width=30, height=30>
@@ -5,7 +7,7 @@
<img src="./assets/fire.svg" width=30, height=30> <img src="./assets/fire.svg" width=30, height=30>
</h1> </h1>
<p align="center"> <p align="center">
English | <a href="./assets/README_zh.md">中文</a> 🤗 <a href="https://huggingface.co/OleehyO/TexTeller"> Hugging Face</a>
</p> </p>
<!-- <p align="center"> <!-- <p align="center">
<img src="./assets/web_demo.gif" alt="TexTeller_demo" width=800> <img src="./assets/web_demo.gif" alt="TexTeller_demo" width=800>
@@ -22,14 +24,14 @@ TexTeller was trained with ~~550K~~7.5M image-formula pairs (dataset available [
## 🔄 Change Log ## 🔄 Change Log
* 📮[2024-03-24] TexTeller 2.0 released! The training data for TexTeller 2.0 has been increased to 7.5M (about **15 times more** than TexTeller 1.0 and also improved in data quality). The trained TexTeller 2.0 demonstrated **superior performance** in the test set, especially in recognizing rare symbols, complex multi-line formulas, and matrices. * 📮[2024-03-25] TexTeller 2.0 released! The training data for TexTeller 2.0 has been increased to 7.5M (about **15 times more** than TexTeller 1.0 and also improved in data quality). The trained TexTeller 2.0 demonstrated **superior performance** in the test set, especially in recognizing rare symbols, complex multi-line formulas, and matrices.
> [There](./assets/test.pdf) are more test images here and a horizontal comparison of recognition models from different companies. > [There](./assets/test.pdf) are more test images here and a horizontal comparison of recognition models from different companies.
## 🔑 Prerequisites ## 🔑 Prerequisites
python=3.10 python=3.10
pytorch [pytorch](https://pytorch.org/get-started/locally/)
> [!WARNING] > [!WARNING]
> Only CUDA versions >= 12.0 have been fully tested, so it is recommended to use CUDA version >= 12.0 > Only CUDA versions >= 12.0 have been fully tested, so it is recommended to use CUDA version >= 12.0
@@ -71,19 +73,21 @@ pytorch
## 🌐 Web Demo ## 🌐 Web Demo
To start the web demo, you need to first enter the `TexTeller/src` directory, then run the following command First, **ensure that [poppler](https://poppler.freedesktop.org/) is correctly installed and added to the `PATH`** (so that the `pdftoppm` command can be directly used in the terminal).
Then, go to the `TexTeller/src` directory and run the following command:
```bash ```bash
./start_web.sh ./start_web.sh
``` ```
Then, enter `http://localhost:8501` in your browser to see the web demo Enter `http://localhost:8501` in a browser to view the web demo.
> [!TIP] > [!TIP]
> You can change the default configuration of `start_web.sh`, for example, to use GPU for inference (e.g. `USE_CUDA=True`) or to increase the number of beams (e.g. `NUM_BEAM=3`) to achieve higher accuracy > You can change the default configuration of `start_web.sh`, for example, to use GPU for inference (e.g. `USE_CUDA=True`) or to increase the number of beams (e.g. `NUM_BEAM=3`) to achieve higher accuracy
> [!IMPORTANT] > [!IMPORTANT]
> If you want to directly render the prediction results as images on the web (for example, to check if the prediction is correct), you need to ensure [xelatex is correctly installed](https://github.com/OleehyO/TexTeller?tab=readme-ov-file#Rendering-Predicted-Results) > If you want to directly render the prediction results as images on the web (for example, to check if the prediction is correct), you need to ensure [xelatex is correctly installed](https://github.com/OleehyO/TexTeller?tab=readme-ov-file#-about-rendering-latex-as-images)
## 📡 API Usage ## 📡 API Usage

View File

@@ -1,3 +1,5 @@
📄 <a href="../README.md">English</a> | 中文
<div align="center"> <div align="center">
<h1> <h1>
<img src="./fire.svg" width=30, height=30> <img src="./fire.svg" width=30, height=30>
@@ -5,7 +7,7 @@
<img src="./fire.svg" width=30, height=30> <img src="./fire.svg" width=30, height=30>
</h1> </h1>
<p align="center"> <p align="center">
<a href="../README.md">English</a> | 中文 🤗 <a href="https://huggingface.co/OleehyO/TexTeller">Hugging Face</a>
</p> </p>
<!-- <p align="center"> <!-- <p align="center">
<img src="./web_demo.gif" alt="TexTeller_demo" width=800> <img src="./web_demo.gif" alt="TexTeller_demo" width=800>
@@ -22,14 +24,14 @@ TexTeller用了~~550K~~7.5M的图片-公式对进行训练(数据集可以在[
## 🔄 变更信息 ## 🔄 变更信息
* 📮[2024-03-24] TexTeller2.0发布TexTeller2.0的训练数据增大到了7.5M(相较于TexTeller1.0**增加了~15倍**并且数据质量也有所改善)。训练后的TexTeller2.0在测试集中展现出了**更加优越的性能**,尤其在生僻符号、复杂多行、矩阵的识别场景中。 * 📮[2024-03-25] TexTeller2.0发布TexTeller2.0的训练数据增大到了7.5M(相较于TexTeller1.0**增加了~15倍**并且数据质量也有所改善)。训练后的TexTeller2.0在测试集中展现出了**更加优越的性能**,尤其在生僻符号、复杂多行、矩阵的识别场景中。
> 在[这里](./test.pdf)有更多的测试图片以及各家识别模型的横向对比。 > 在[这里](./test.pdf)有更多的测试图片以及各家识别模型的横向对比。
## 🔑 前置条件 ## 🔑 前置条件
python=3.10 python=3.10
pytorch [pytorch](https://pytorch.org/get-started/locally/)
> [!WARNING] > [!WARNING]
> 只有CUDA版本>= 12.0被完全测试过,所以最好使用>= 12.0的CUDA版本 > 只有CUDA版本>= 12.0被完全测试过,所以最好使用>= 12.0的CUDA版本
@@ -99,19 +101,21 @@ pytorch
## 🌐 网页演示 ## 🌐 网页演示
要想启动web demo你需要先进入 `TexTeller/src` 目录,然后运行以下命令 首先**确保[poppler](https://poppler.freedesktop.org/)被正确安装,并添加到`PATH`路径中**(终端可以直接使用`pdftoppm`命令)。
然后进入 `TexTeller/src` 目录,运行以下命令
```bash ```bash
./start_web.sh ./start_web.sh
``` ```
然后在浏览器里输入`http://localhost:8501`就可以看到web demo 在浏览器里输入`http://localhost:8501`就可以看到web demo
> [!TIP] > [!TIP]
> 你可以改变`start_web.sh`的默认配置, 例如使用GPU进行推理(e.g. `USE_CUDA=True`) 或者增加beams的数量(e.g. `NUM_BEAM=3`)来获得更高的精确度 > 你可以改变`start_web.sh`的默认配置, 例如使用GPU进行推理(e.g. `USE_CUDA=True`) 或者增加beams的数量(e.g. `NUM_BEAM=3`)来获得更高的精确度
> [!IMPORTANT] > [!IMPORTANT]
> 如果你想直接把预测结果在网页上渲染成图片(比如为了检查预测结果是否正确)你需要确保[xelatex被正确安装](https://github.com/OleehyO/TexTeller?tab=readme-ov-file#Rendering-Predicted-Results) > 如果你想直接把预测结果在网页上渲染成图片(比如为了检查预测结果是否正确)你需要确保[xelatex被正确安装](https://github.com/OleehyO/TexTeller?tab=readme-ov-file#-关于把latex渲染成图片)
## 📡 API调用 ## 📡 API调用
@@ -150,8 +154,7 @@ python server.py # default settings
如果你使用了不一样的数据集你可能需要重新训练tokenizer来得到一个不一样的字典。配置好数据集后可以通过以下命令来训练自己的tokenizer 如果你使用了不一样的数据集你可能需要重新训练tokenizer来得到一个不一样的字典。配置好数据集后可以通过以下命令来训练自己的tokenizer
1. 在`TexTeller/src/models/tokenizer/train.py`中,修改`new_tokenizer.save_pretrained('./your_dir_name')`为你自定义的输出目录 1. 在`TexTeller/src/models/tokenizer/train.py`中,修改`new_tokenizer.save_pretrained('./your_dir_name')`为你自定义的输出目录
> [!IMPORTANT] > 注意:如果要用一个不一样大小的字典(默认1W个token),你需要在 `TexTeller/src/models/globals.py`中修改`VOCAB_SIZE`变量
> 如果要用一个不一样大小的字典(默认1W个token),你需要在 `TexTeller/src/models/globals.py`中修改`VOCAB_SIZE`变量
2. **在 `TexTeller/src` 目录下**运行以下命令: 2. **在 `TexTeller/src` 目录下**运行以下命令:

View File

@@ -17,7 +17,7 @@ from transformers import (
class TexTeller(VisionEncoderDecoderModel): class TexTeller(VisionEncoderDecoderModel):
REPO_NAME = '/home/lhy/code/TexTeller/src/models/ocr_model/train/train_result/TexTellerv2/checkpoint-588000' REPO_NAME = 'OleehyO/TexTeller'
def __init__(self, decoder_path=None, tokenizer_path=None): def __init__(self, decoder_path=None, tokenizer_path=None):
encoder = ViTModel(ViTConfig( encoder = ViTModel(ViTConfig(
image_size=FIXED_IMG_SIZE, image_size=FIXED_IMG_SIZE,

View File

@@ -3,8 +3,7 @@ set -exu
export CHECKPOINT_DIR="default" export CHECKPOINT_DIR="default"
export TOKENIZER_DIR="default" export TOKENIZER_DIR="default"
# export USE_CUDA=False # True or False (case-sensitive) export USE_CUDA=False # True or False (case-sensitive)
export USE_CUDA=True # True or False (case-sensitive) export NUM_BEAM=1
export NUM_BEAM=10
streamlit run web.py streamlit run web.py

View File

@@ -65,7 +65,6 @@ tex = r'''
def get_model(): def get_model():
return TexTeller.from_pretrained(os.environ['CHECKPOINT_DIR']) return TexTeller.from_pretrained(os.environ['CHECKPOINT_DIR'])
@st.cache_resource @st.cache_resource
def get_tokenizer(): def get_tokenizer():
return TexTeller.get_tokenizer(os.environ['TOKENIZER_DIR']) return TexTeller.get_tokenizer(os.environ['TOKENIZER_DIR'])