SAVRN
Search Contact SAVRN

Open-weight model · Image to text

pix2text-mfr

by Breezedeus breezedeus/pix2text-mfr

Mathematical Formula Recognition (MFR) model from Pix2Text (P2T). This MFR model utilizes the TrOCR architecture developed by Microsoft, starting with its initial values and retrained using a dataset of mathematical formula images.

Parameters
Context
Weights117.6 MB
Licensemit
AccessOpen weights
Monthly Downloads19k

Model Card

By Breezedeus, published under mit, revision bea257edb265.

Mathematical Formula Recognition (MFR) model from Pix2Text (P2T). This MFR model utilizes the TrOCR architecture developed by Microsoft, starting with its initial values and retrained using a dataset of mathematical formula images. The resulting MFR model can be used to convert images of mathematical formulas into LaTeX text representation. More detailed can be found: Pix2Text V1.0 New Release: The Best Open-Source Formula Recognition Model | Breezedeus.com. 此 MFR 模型使用了微软的 TrOCR 架构,以其为初始值并利用数学公式图片数据集进行了重新训练。 获得的 MFR 模型可用于把数学公式图片转换为 LaTeX 文本表示。更多细节请见:Pix2Text V1.0 新版发布:最好的开源公式识别模型 | Breezedeus.com。 - 用途:此模型为数学公式识别模型,它可以把输入的数学公式图片转换为 LaTeX 文本表示。 This method doesn't need to install pix2text…

Read Breezedeus's full model card

Model Card: Pix2Text-MFR

Mathematical Formula Recognition (MFR) model from Pix2Text (P2T).

Model Details / 模型细节

This MFR model utilizes the TrOCR architecture developed by Microsoft, starting with its initial values and retrained using a dataset of mathematical formula images. The resulting MFR model can be used to convert images of mathematical formulas into LaTeX text representation. More detailed can be found: Pix2Text V1.0 New Release: The Best Open-Source Formula Recognition Model | Breezedeus.com.

此 MFR 模型使用了微软的 TrOCR 架构,以其为初始值并利用数学公式图片数据集进行了重新训练。 获得的 MFR 模型可用于把数学公式图片转换为 LaTeX 文本表示。更多细节请见:Pix2Text V1.0 新版发布:最好的开源公式识别模型 | Breezedeus.com

Usage and Limitations / 使用和限制

  • Purpose: This model is a mathematical formula recognition model, capable of converting input images of mathematical formulas into LaTeX text representation.
  • Limitation: Since the model is trained on images of mathematical formulas, it may not work when recognizing other types of images.

  • 用途:此模型为数学公式识别模型,它可以把输入的数学公式图片转换为 LaTeX 文本表示。

  • 限制:由于模型是在数学公式图片数据上训练的,它在识别其他类型的图片时可能无法工作。

Documents / 文档

Examples / 示例

Printed Math Formula Images / 印刷体公式图片

Handwritten Math Formula Images / 印刷体公式图片

Model Use / 模型使用

Method 1: Using the model Directly

This method doesn't need to install pix2text, but can only recognize pure formula images.

这种方法无需安装 pix2text,但只能识别纯公式图片。

#! pip install transformers>=4.37.0 pillow optimum[onnxruntime]
from PIL import Image
from transformers import TrOCRProcessor
from optimum.onnxruntime import ORTModelForVision2Seq

processor = TrOCRProcessor.from_pretrained('breezedeus/pix2text-mfr')
model = ORTModelForVision2Seq.from_pretrained('breezedeus/pix2text-mfr', use_cache=False)

image_fps = [
    'examples/example.jpg',
    'examples/42.png',
    'examples/0000186.png',
]
images = [Image.open(fp).convert('RGB') for fp in image_fps]
pixel_values = processor(images=images, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
print(f'generated_ids: {generated_ids}, \ngenerated text: {generated_text}')

Method 2: Using Pix2Text

This method requires the installation of pix2text, utilizing the Mathematical Formula Detection model (MFD) within Pix2Text. It is capable of recognizing not only pure formula images but also mixed images containing text.

这种方法需要安装 pix2text,借助 Pix2Text 中的数学公式检测模型(MFD),它不仅可以识别纯公式图片,还可以识别包含文本的混合图片。

$ pip install pix2text>=1.1
#! pip install pix2text>=1.1

from pix2text import Pix2Text, merge_line_texts

image_fps = [
    'examples/example.jpg',
    'examples/42.png',
    'examples/0000186.png',
]
p2t = Pix2Text.from_config()
outs = p2t.recognize_formula(image_fps)  # recognize pure formula images

outs2 = p2t.recognize('examples/mixed.jpg', file_type='text_formula', return_text=True, save_analysis_res='mixed-out.jpg')  # recognize mixed images
print(outs2)

Method 3: Notebook

Just try Pix2Text with this notebook: https://github.com/breezedeus/Pix2Text/blob/main/pix2text_v1_1.ipynb.

Performance / 性能

The original images for the test data are derived from real data uploaded by users on the Pix2Text Online Service. Initially, real user data from a specific period is selected, and then the Mathematical Formula Detection model (MFD) within Pix2Text is used to detect the mathematical formulas in these images and crop the corresponding parts. A subset of these formula images is then randomly chosen for manual annotation to create the test dataset. The following image shows some sample pictures from the test dataset. It is evident that the images in the test dataset are quite diverse, including mathematical formulas of various lengths and complexities, from single letters to formula groups and even matrices. This test dataset includes 485 images.

测试数据对应的原始图片来源于 Pix2Text 网页版 用户上传的真实数据。首先选取一段时间内用户的真实数据,然后利用 Pix2Text 中数学公式检测模型(MFD)检测出这些图片中的数学公式并截取出对应的部分,再从中随机选取部分公式图片进行人工标注。就获得了用于测试的测试数据集了。下图是测试数据集中的部分样例图片。从中可以看出测试数据集中的图片比较多样,包括了各种不同长度和复杂度的数学公式,有单个字母的图片,也有公式组甚至矩阵图片。本测试数据集包括了 485 张图片。

Below are the Character Error Rates (CER, the lower, the better) of various models on this test dataset. For the true annotated results, as well as the output of each model, normalization was first performed to ensure that irrelevant factors such as spaces do not affect the test outcomes. For the recognition results of Texify, the leading and trailing symbols $ or $$ of the formula are removed first.

以下是各个模型在此测试数据集上的 CER(字错误率,越小越好)。其中对真实标注结果,以及每个模型的输出都首先进行了标准化,以保证不会因为空格等无关因素影响测试结果。对 Texify 的识别结果会首先去掉公式的首尾符号$或$$。

As can be seen from the figure above, the Pix2Text V1.0 MFR open-source free version model has significantly outperformed the previous versions of the paid model. Moreover, compared to the V1.0 MFR open-source free model, the precision of the Pix2Text V1.0 MFR paid model has been further improved.

由上图可见,Pix2Text V1.0 MFR 开源免费版模型已经大大优于之前版本的付费模型。而相比 V1.0 MFR 开源免费模型,Pix2Text V1.0 MFR 付费模型精度得到了进一步的提升。

Texify is more suited for recognizing images with standard formatting. It performs poorly in recognizing images containing single letters. This is the main reason why Texify's performance on this test dataset is inferior to that of Latex-OCR.

Texify 更适用于识别标准排版的图片,它对包含单字母的图片识别较差。这也是 Texify 在此测试数据集上效果比 Latex-OCR 还差的主要原因。

Feedback / 反馈

Where to send questions or comments about the model.

Welcome to contact the author Breezedeus.

欢迎联系作者 Breezedeus

Configuration

Architecture
VisionEncoderDecoderModel
Model type
vision-encoder-decoder

Identity and Version

Repository
breezedeus/pix2text-mfr
Publisher
Breezedeus
Task
Image to text
Modality
Image and text
Library
transformers
Parameters
Not stated by the source
Languages
mfr
Revision
bea257edb2653f2ae413b084f2ac0e8299d08df0
First published
2024-02-11
Last updated
2024-05-05

Files and Weights

10 files, 117.7 MB in total. The weights are 2 files totalling 117.6 MB in onnx.

Weights2 files · 117.6 MB
Configuration4 files · 6.2 KB
Tokenizer2 files · 40.3 KB
Documentation1 file · 9.3 KB
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
decoder_model.onnxWeights30.1 MB fd0f92d7a012
encoder_model.onnxWeights87.5 MB bd8d5c322792
config.jsonConfiguration4.6 KB
generation_config.jsonConfiguration210 B
preprocessor_config.jsonConfiguration450 B
special_tokens_map.jsonConfiguration964 B
README.mdDocumentation9.3 KB
.gitattributesRepository1.5 KB
tokenizer.jsonTokenizer39.2 KB
tokenizer_config.jsonTokenizer1.2 KB

License and Download

License
mit
Access
Open weights, no gate
Download size
117.6 MB
Download from Breezedeus

Released by Breezedeus through its official repository on Hugging Face. Read the license.

Memory Requirements

PrecisionWeights in memory
As published117.6 MB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About pix2text-mfr

Can I use pix2text-mfr commercially?

Yes. pix2text-mfr is released under MIT License. The MIT License is a short permissive license. It permits commercial use, modification and redistribution, provided the copyright notice and permission notice are included.

Similar Models

captioning pretrained on COCO dataset - base architecture (with ViT base backbone). Authors from the paper write in the abstract: Vision-Language Pre-training (VLP) has advanced the performance for many vision-language tasks. However, most existing pre-trained models only excel in either understanding-based tasks or generation-based tasks. Furthermore, performance improvement has been largely achieved by scaling up the dataset with noisy image-text pairs collected from the web, which is a suboptimal source of supervision. In this paper, we propose BLIP, a new VLP framework which transfers flexibly to both vision-language understanding and generation tasks. BLIP effectively utilizes the…

Open weights bsd-3-clause 512 tokens transformers

Model · Image to text

manga-ocr-base

Maciej Budyś

Optical character recognition for Japanese text, with the main focus being Japanese manga. It uses Vision Encoder Decoder framework. Manga OCR can be used as a general purpose printed Japanese OCR, but its main goal was to provide a high quality text recognition, robust against various scenarios specific to manga: - both vertical and horizontal text - text with furigana - text overlaid on images - wide variety of fonts and font styles - low quality images Code is available here.

Open weights apache-2.0 transformers

Model · Image to text

PP-OCRv5_server_det

PaddlePaddle

PP-OCRv5serverdet is one of the PP-OCRv5det series, the latest generation of text detection models developed by the PaddleOCR team. Designed for high-performance applications, it supports the detection of text in diverse scenarios—including handwriting, vertical, rotated, and curved text—across multiple languages such as Simplified Chinese, Traditional Chinese, English, and Japanese. Key features include robust handling of complex layouts, varying text sizes, and challenging backgrounds, making it suitable for practical applications like document analysis, license plate recognition, and scene text detection. The key accuracy metrics are as follow: Please refer to the following commands to…

Open weights apache-2.0 PaddleOCR

Model · Image to text

UVDoc

PaddlePaddle

The main purpose of text image correction is to carry out geometric transformation on the image to correct the document distortion, inclination, perspective deformation and other problems in the image, so that the subsequent text recognition can be more accurate. Please refer to the following commands to install PaddlePaddle using pip: For details about PaddlePaddle installation, please refer to the PaddlePaddle official website. Install the latest version of the PaddleOCR inference package from PyPI: You can quickly experience the functionality with a single command: You can also integrate the model inference of the TextImageUnwarping module into your project. Before running the following…

Open weights apache-2.0 PaddleOCR

Model · Image to text

en_PP-OCRv5_mobile_rec

PaddlePaddle

enPP-OCRv5mobilerec is one of the PP-OCRv5rec that are the latest generation text line recognition models developed by PaddleOCR team. It aims to efficiently and accurately support the recognition of English. The key accuracy metrics are as follow: Note: If any character (including punctuation) in a line was incorrect, the entire line was marked as wrong. This ensures higher accuracy in practical applications. Please refer to the following commands to install PaddlePaddle using pip: For details about PaddlePaddle installation, please refer to the PaddlePaddle official website. Install the latest version of the PaddleOCR inference package from PyPI: You can quickly experience the…

Open weights apache-2.0 PaddleOCR

Model · Image to text

PP-LCNet_x1_0_doc_ori

PaddlePaddle

The Document Image Orientation Classification Module is primarily designed to distinguish the orientation of document images and correct them through post-processing. During processes such as document scanning or ID photo capturing, the device might be rotated to achieve clearer images, resulting in images with various orientations. Standard OCR pipelines may not handle these images effectively. By leveraging image classification techniques, the orientation of documents or IDs containing text regions can be pre-determined and adjusted, thereby improving the accuracy of OCR processing. The key accuracy metrics are as follow: Please refer to the following commands to install PaddlePaddle…

Open weights apache-2.0 PaddleOCR