{"id":23458241,"url":"https://github.com/oleehyo/texteller","last_synced_at":"2025-04-04T15:10:48.970Z","repository":{"id":221810582,"uuid":"755423918","full_name":"OleehyO/TexTeller","owner":"OleehyO","description":"TexTeller can convert image to latex formulas (image2latex, latex OCR) with higher accuracy and exhibits superior generalization ability, enabling it to cover most usage scenarios.","archived":false,"fork":false,"pushed_at":"2024-08-07T04:43:15.000Z","size":83552,"stargazers_count":327,"open_issues_count":2,"forks_count":35,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-31T09:14:12.010Z","etag":null,"topics":["image2text","latex-ocr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OleehyO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-10T06:39:02.000Z","updated_at":"2024-10-29T10:34:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"0fe1da45-bba4-478d-8012-6a7f057d1075","html_url":"https://github.com/OleehyO/TexTeller","commit_stats":null,"previous_names":["oleehyo/texteller"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OleehyO%2FTexTeller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OleehyO%2FTexTeller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OleehyO%2FTexTeller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OleehyO%2FTexTeller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OleehyO","download_url":"https://codeload.github.com/OleehyO/TexTeller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image2text","latex-ocr"],"created_at":"2024-12-24T05:18:02.248Z","updated_at":"2025-04-04T15:10:48.949Z","avatar_url":"https://github.com/OleehyO.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"📄 English | \u003ca href=\"./assets/README_zh.md\"\u003e中文\u003c/a\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e\n        \u003cimg src=\"./assets/fire.svg\" width=30, height=30\u003e \n        𝚃𝚎𝚡𝚃𝚎𝚕𝚕𝚎𝚛\n        \u003cimg src=\"./assets/fire.svg\" width=30, height=30\u003e\n    \u003c/h1\u003e\n    \u003c!-- \u003cp align=\"center\"\u003e\n        🤗 \u003ca href=\"https://huggingface.co/OleehyO/TexTeller\"\u003e Hugging Face \u003c/a\u003e\n    \u003c/p\u003e --\u003e\n\n  [![](https://img.shields.io/badge/License-Apache_2.0-blue.svg?logo=github)](https://opensource.org/licenses/Apache-2.0)\n  [![](https://img.shields.io/badge/docker-pull-green.svg?logo=docker)](https://hub.docker.com/r/oleehyo/texteller)\n  [![](https://img.shields.io/badge/Data-Texteller1.0-brightgreen.svg?logo=huggingface)](https://huggingface.co/datasets/OleehyO/latex-formulas)\n  [![](https://img.shields.io/badge/Weights-Texteller3.0-yellow.svg?logo=huggingface)](https://huggingface.co/OleehyO/TexTeller)\n\n\u003c/div\u003e\n\n\u003c!-- \u003cp align=\"center\"\u003e\n\n  \u003ca href=\"https://opensource.org/licenses/Apache-2.0\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-Apache_2.0-blue.svg\" alt=\"License\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/OleehyO/TexTeller/issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" alt=\"Maintenance\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/OleehyO/TexTeller/pulls\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Contributions-welcome-brightgreen.svg?style=flat\" alt=\"Contributions welcome\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://huggingface.co/datasets/OleehyO/latex-formulas\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Data-Texteller1.0-brightgreen.svg\" alt=\"Data\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://huggingface.co/OleehyO/TexTeller\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Weights-Texteller3.0-yellow.svg\" alt=\"Weights\"\u003e\n  \u003c/a\u003e\n\n\u003c/p\u003e --\u003e\n\nhttps://github.com/OleehyO/TexTeller/assets/56267907/532d1471-a72e-4960-9677-ec6c19db289f\n\nTexTeller is an end-to-end formula recognition model based on [TrOCR](https://arxiv.org/abs/2109.10282), capable of converting images into corresponding LaTeX formulas.\n\nTexTeller was trained with **80M image-formula pairs** (previous dataset can be obtained [here](https://huggingface.co/datasets/OleehyO/latex-formulas)), compared to [LaTeX-OCR](https://github.com/lukas-blecher/LaTeX-OCR) which used a 100K dataset, TexTeller has **stronger generalization abilities** and **higher accuracy**, covering most use cases.\n\n\u003e[!NOTE]\n\u003e If you would like to provide feedback or suggestions for this project, feel free to start a discussion in the [Discussions section](https://github.com/OleehyO/TexTeller/discussions).\n\u003e \n\u003e Additionally, if you find this project helpful, please don't forget to give it a star⭐️🙏️\n\n---\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n## 🔖 Table of Contents\n- [Change Log](#-change-log)\n- [Getting Started](#-getting-started)\n- [Web Demo](#-web-demo)\n- [Formula Detection](#-formula-detection)\n- [API Usage](#-api-usage)\n- [Training](#️️-training)\n- [Plans](#-plans)\n- [Stargazers over time](#️-stargazers-over-time)\n- [Contributors](#-contributors)\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cfigure\u003e\n    \u003cimg src=\"assets/cover.png\" width=\"800\"\u003e\n    \u003cfigcaption\u003e\n      \u003cp\u003eImages that can be recognized by TexTeller\u003c/p\u003e\n    \u003c/figcaption\u003e\n  \u003c/figure\u003e\n  \u003cdiv\u003e\n    \u003cp\u003e\n      Thanks to the\n      \u003ci\u003e\n        Super Computing Platform of Beijing University of Posts and Telecommunications\n      \u003c/i\u003e\n        for supporting this work😘\n    \u003c/p\u003e\n    \u003c!-- \u003cimg src=\"assets/scss.png\" width=\"200\"\u003e --\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## 🔄 Change Log\n\n- 📮[2024-06-06] **TexTeller3.0 released!** The training data has been increased to **80M** (**10x more than** TexTeller2.0 and also improved in data diversity). TexTeller3.0's new features:\n\n  - Support scanned image, handwritten formulas, English(Chinese) mixed formulas.\n\n  - OCR abilities in both Chinese and English for printed images.\n\n- 📮[2024-05-02] Support **paragraph recognition**.\n\n- 📮[2024-04-12] **Formula detection model** released!\n\n- 📮[2024-03-25] TexTeller2.0 released! The training data for TexTeller2.0 has been increased to 7.5M (15x more than TexTeller1.0 and also improved in data quality). The trained TexTeller2.0 demonstrated **superior performance** in the test set, especially in recognizing rare symbols, complex multi-line formulas, and matrices.\n\n  \u003e [Here](./assets/test.pdf) are more test images and a horizontal comparison of various recognition models.\n\n## 🚀 Getting Started\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/OleehyO/TexTeller\n   ```\n\n2. Install the project's dependencies:\n\n   ```bash\n   pip install texteller\n   ```\n\n3. Enter the `src/` directory and run the following command in the terminal to start inference:\n\n   ```bash\n   python inference.py -img \"/path/to/image.{jpg,png}\" \n   # use --inference-mode option to enable GPU(cuda or mps) inference\n   #+e.g. python inference.py -img \"img.jpg\" --inference-mode cuda\n   ```\n\n   \u003e The first time you run it, the required checkpoints will be downloaded from Hugging Face.\n\n### Paragraph Recognition\n\nAs demonstrated in the video, TexTeller is also capable of recognizing entire text paragraphs. Although TexTeller has general text OCR capabilities, we still recommend using paragraph recognition for better results:\n\n1. [Download the weights](https://huggingface.co/TonyLee1256/texteller_det/resolve/main/rtdetr_r50vd_6x_coco.onnx?download=true) of the formula detection model to the`src/models/det_model/model/`directory\n\n2. Run `inference.py` in the `src/` directory and add the `-mix` option, the results will be output in markdown format.\n\n   ```bash\n   python inference.py -img \"/path/to/image.{jpg,png}\" -mix\n   ```\n\nTexTeller uses the lightweight [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) model by default for recognizing both Chinese and English text. You can try using a larger model to achieve better recognition results for both Chinese and English:\n\n| Checkpoints | Model Description | Size |\n|-------------|-------------------| ---- |\n| [ch_PP-OCRv4_det.onnx](https://huggingface.co/OleehyO/paddleocrv4.onnx/resolve/main/ch_PP-OCRv4_det.onnx?download=true) | **Default detection model**, supports Chinese-English text detection | 4.70M |\n| [ch_PP-OCRv4_server_det.onnx](https://huggingface.co/OleehyO/paddleocrv4.onnx/resolve/main/ch_PP-OCRv4_server_det.onnx?download=true) | High accuracy model, supports Chinese-English text detection | 115M |\n| [ch_PP-OCRv4_rec.onnx](https://huggingface.co/OleehyO/paddleocrv4.onnx/resolve/main/ch_PP-OCRv4_rec.onnx?download=true) | **Default recoginition model**, supports Chinese-English text recognition | 10.80M |\n| [ch_PP-OCRv4_server_rec.onnx](https://huggingface.co/OleehyO/paddleocrv4.onnx/resolve/main/ch_PP-OCRv4_server_rec.onnx?download=true) | High accuracy model, supports Chinese-English text recognition | 90.60M |\n\nPlace the weights of the recognition/detection model in the `det/` or `rec/` directories within `src/models/third_party/paddleocr/checkpoints/`, and rename them to `default_model.onnx`.\n\n\u003e [!NOTE]\n\u003e Paragraph recognition cannot restore the structure of a document, it can only recognize its content.\n\n## 🌐 Web Demo\n\nGo to the `src/` directory and run the following command:\n\n```bash\n./start_web.sh\n```\n\nEnter `http://localhost:8501` in a browser to view the web demo.\n\n\u003e [!NOTE]\n\u003e 1. For Windows users, please run the `start_web.bat` file.\n\u003e 2. When using onnxruntime + GPU for inference, you need to install onnxruntime-gpu.\n\n## 🔍 Formula Detection\n\nTexTeller’s formula detection model is trained on 3,415 images of Chinese educational materials (with over 130 layouts) and 8,272 images from the [IBEM dataset](https://zenodo.org/records/4757865), and it supports formula detection across entire images.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"./assets/det_rec.png\" width=250\u003e \n\u003c/div\u003e\n\n1. Download the model weights and place them in `src/models/det_model/model/` [[link](https://huggingface.co/TonyLee1256/texteller_det/resolve/main/rtdetr_r50vd_6x_coco.onnx?download=true)].\n\n2. Run the following command in the `src/` directory, and the results will be saved in `src/subimages/`\n\n\u003cdetails\u003e\n\u003csummary\u003eAdvanced: batch formula recognition\u003c/summary\u003e\n\nAfter **formula detection**, run the following command in the `src/` directory:\n\n```shell\npython rec_infer_from_crop_imgs.py\n```\n\nThis will use the results of the previous formula detection to perform batch recognition on all cropped formulas, saving the recognition results as txt files in `src/results/`.\n\n\u003c/details\u003e\n\n## 📡 API Usage\n\nWe use [ray serve](https://github.com/ray-project/ray) to provide an API interface for TexTeller, allowing you to integrate TexTeller into your own projects. To start the server, you first need to enter the `src/` directory and then run the following command:\n\n```bash\npython server.py\n```\n\n| Parameter | Description |\n| --------- | -------- |\n| `-ckpt` | The path to the weights file,*default is TexTeller's pretrained weights*. |\n| `-tknz` | The path to the tokenizer,*default is TexTeller's tokenizer*. |\n| `-port` | The server's service port,*default is 8000*. |\n| `--inference-mode` | Whether to use \"cuda\" or \"mps\" for inference,*default is \"cpu\"*. |\n| `--num_beams` | The number of beams for beam search,*default is 1*. |\n| `--num_replicas` | The number of service replicas to run on the server,*default is 1 replica*. You can use more replicas to achieve greater throughput.|\n| `--ncpu_per_replica` | The number of CPU cores used per service replica,*default is 1*.|\n| `--ngpu_per_replica` | The number of GPUs used per service replica,*default is 1*. You can set this value between 0 and 1 to run multiple service replicas on one GPU to share the GPU, thereby improving GPU utilization. (Note, if --num_replicas is 2, --ngpu_per_replica is 0.7, then 2 GPUs must be available) |\n| `-onnx` | Perform inference using Onnx Runtime, *disabled by default* |\n\n\u003e [!NOTE]\n\u003e A client demo can be found at `src/client/demo.py`, you can refer to `demo.py` to send requests to the server\n\n## 🏋️‍♂️ Training\n\n### Dataset\n\nWe provide an example dataset in the `src/models/ocr_model/train/dataset/` directory, you can place your own images in the `images/` directory and annotate each image with its corresponding formula in `formulas.jsonl`.\n\nAfter preparing your dataset, you need to **change the `DIR_URL` variable to your own dataset's path** in `**/train/dataset/loader.py`\n\n### Retraining the Tokenizer\n\nIf you are using a different dataset, you might need to retrain the tokenizer to obtain a different vocabulary. After configuring your dataset, you can train your own tokenizer with the following command:\n\n1. In `src/models/tokenizer/train.py`, change `new_tokenizer.save_pretrained('./your_dir_name')` to your custom output directory\n\n   \u003e If you want to use a different vocabulary size (default 15K), you need to change the `VOCAB_SIZE` variable in `src/models/globals.py`\n   \u003e\n2. **In the `src/` directory**, run the following command:\n\n   ```bash\n   python -m models.tokenizer.train\n   ```\n\n### Training the Model\n\n1. Modify `num_processes` in `src/train_config.yaml` to match the number of GPUs available for training (default is 1).\n2. In the `src/` directory, run the following command:\n\n   ```bash\n   accelerate launch --config_file ./train_config.yaml -m models.ocr_model.train.train\n   ```\n\nYou can set your own tokenizer and checkpoint paths in `src/models/ocr_model/train/train.py` (refer to `train.py` for more information). If you are using the same architecture and vocabulary as TexTeller, you can also fine-tune TexTeller's default weights with your own dataset.\n\nIn `src/globals.py` and `src/models/ocr_model/train/train_args.py`, you can change the model's architecture and training hyperparameters.\n\n\u003e [!NOTE]\n\u003e Our training scripts use the [Hugging Face Transformers](https://github.com/huggingface/transformers) library, so you can refer to their [documentation](https://huggingface.co/docs/transformers/v4.32.1/main_classes/trainer#transformers.TrainingArguments) for more details and configurations on training parameters.\n\n## 📅 Plans\n\n- [X] ~~Train the model with a larger dataset~~\n- [X] ~~Recognition of scanned images~~\n- [X] ~~Support for English and Chinese scenarios~~\n- [X] ~~Handwritten formulas support~~\n- [ ] PDF document recognition\n- [ ] Inference acceleration\n- [ ] ...\n\n## ⭐️ Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/OleehyO/TexTeller.svg?variant=adaptive)](https://starchart.cc/OleehyO/TexTeller)\n\n\n## 👥 Contributors\n\n\u003ca href=\"https://github.com/OleehyO/TexTeller/graphs/contributors\"\u003e\n   \u003ca href=\"https://github.com/OleehyO/TexTeller/graphs/contributors\"\u003e\n      \u003cimg src=\"https://contrib.rocks/image?repo=OleehyO/TexTeller\" /\u003e\n   \u003c/a\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleehyo%2Ftexteller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleehyo%2Ftexteller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleehyo%2Ftexteller/lists"}