"vscode:/vscode.git/clone" did not exist on "f0bc00c980012badea8db011f84a0e9ef33ba6c1"
Commit bffed0fe authored by dengjb's avatar dengjb
Browse files

update

parents
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2024 OpenDataLab
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
## Install dependency and download model weight.
```bash
conda create -n mfd python=3.10
conda activate mfd
pip install ultralytics
# download with modelscope
cd MFD/
wget -c https://www.modelscope.cn/models/wanderkid/PDF-Extract-Kit/resolve/master/models/MFD/weights.pt
# you can also download with huggingface
# https://huggingface.co/wanderkid/PDF-Extract-Kit/blob/main/models/MFD/weights.pt
```
## Run the demo
```bash
python demo.py
```
from ultralytics import YOLO
if __name__ == "__main__":
weight = "./weights.pt"
model = YOLO(weight)
# 'path to your image'
img_path = './asset/demo_1_textbook.png'
det_res = model.predict(img_path , imgsz=1280, conf=0.25, iou=0.45)[0]
# print bbox info
print(det_res.boxes)
# visualize the bbox
det_res.save(filename=img_path.replace('.png', '_res.png'))
\ No newline at end of file
<div align="center">
[English](./README.md) | [简体中文](./README-zh_CN.md) | 日本語
<h1>UniMERNet: 実世界の数式認識のためのユニバーサルネットワーク</h1>
[[ 論文 ]](https://arxiv.org/abs/2404.15254) [[ ウェブサイト ]](https://github.com/opendatalab/UniMERNet/tree/main) [[ データセット (OpenDataLab)]](https://opendatalab.com/OpenDataLab/UniMER-Dataset) [[ データセット (Hugging Face) ]](https://huggingface.co/datasets/wanderkid/UniMER_Dataset)
[[モデル 🤗(Hugging Face)]](https://huggingface.co/wanderkid/unimernet_base)
[[モデル <img src="./asset/images/modelscope_logo.png" width="20px">(ModelScope)]](https://www.modelscope.cn/models/wanderkid/unimernet_base)
🔥🔥 [CDM: 公平で正確な数式認識評価のための信頼できる指標](https://github.com/opendatalab/UniMERNet/tree/main/cdm)
</div>
UniMERNetの公式リポジトリへようこそ。これは、数式の画像をLaTeXに変換するソリューションであり、さまざまな実世界のシナリオに適しています。
## ニュース 🚀🚀🚀
**2025.03.25** 🎉🎉 <font color="red">新しい数式認識指標[CDM](https://arxiv.org/abs/2409.03643)に関する論文がCVPR 2025に採択されました。ぜひご利用ください。</font>
**2024.09.06** 🎉🎉 UniMERNetの更新: 新バージョンはモデルが小さくなり、推論が高速化されました。トレーニングコードがオープンソース化されました。詳細は最新の論文[UniMERNet](https://arxiv.org/abs/2404.15254)をご覧ください。
**2024.09.06** 🎉🎉 数式認識の新しい指標を導入: [CDM](https://github.com/opendatalab/UniMERNet/tree/main/cdm)。BLEU/EditDistanceと比較して、CDMはより直感的で正確な評価スコアを提供し、数式表現の多様性に影響されずに異なるモデルの公平な比較を可能にします。
**2024.07.21** 🎉🎉 [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) MFDモデルに基づく数式検出(MFD)チュートリアルを追加しました。
**2024.06.06** 🎉🎉 UniMERデータセットの評価コードをオープンソース化しました。
**2024.05.06** 🎉🎉 UniMERデータセットをオープンソース化しました。これには、モデルトレーニング用のUniMER-1MとMER評価用のUniMER-Testが含まれます。
**2024.05.06** 🎉🎉 Streamlit数式認識デモを追加し、ローカルデプロイメントアプリを提供しました。
**2024.04.24** 🎉🎉 論文が[ArXiv](https://arxiv.org/abs/2404.15254)で公開されました。
**2024.04.24** 🎉🎉 推論コードとチェックポイントがリリースされました。
## デモビデオ
https://github.com/opendatalab/UniMERNet/assets/69186975/ac54c6b9-442c-48b0-95f9-a4a3fce8780b
https://github.com/opendatalab/UniMERNet/assets/69186975/09b71c55-c58a-4792-afc1-d5774880ccf8
## クイックスタート
### リポジトリをクローンし、モデルをダウンロード
```bash
git clone https://github.com/opendatalab/UniMERNet.git
```
```bash
cd UniMERNet/models
# モデルとトークナイザーを個別にダウンロードするか、git-lfsを使用
git lfs install
git clone https://huggingface.co/wanderkid/unimernet_base # 1.3GB
git clone https://huggingface.co/wanderkid/unimernet_small # 773MB
git clone https://huggingface.co/wanderkid/unimernet_tiny # 441MB
# モデルをModelScopeからもダウンロードできます
git clone https://www.modelscope.cn/wanderkid/unimernet_base.git
git clone https://www.modelscope.cn/wanderkid/unimernet_small.git
git clone https://www.modelscope.cn/wanderkid/unimernet_tiny.git
```
### インストール
> クリーンなConda環境を作成
``` bash
conda create -n unimernet python=3.10
conda activate unimernet
```
> インストール方法1:pip installで直接インストール(一般ユーザー向け)
```bash
pip install --upgrade unimernet
pip install "unimernet[full]"
```
> インストール方法2:ローカルインストール(開発者向け)
```bash
pip install -e ."[full]"
```
### UniMERNetの実行
1. **Streamlitアプリケーション**:インタラクティブでユーザーフレンドリーな体験のために、StreamlitベースのGUIを使用します。このアプリケーションでは、リアルタイムの数式認識とレンダリングが可能です。
```bash
unimernet_gui
```
最新バージョンのUniMERNetをインストールしていることを確認してください(`pip install --upgrade unimernet & pip install "unimernet[full]"`)Streamlit GUIアプリケーションを使用するために。
2. **コマンドラインデモ**:画像からLaTeXコードを予測します。
```bash
python demo.py
```
3. **Jupyter Notebookデモ**:画像から数式を認識してレンダリングします。
```bash
jupyter-lab ./demo.ipynb
```
## SOTAメソッドとのパフォーマンス比較(BLEU)。
> UniMERNetは、実世界の数式認識において主流のモデルを大幅に上回り、BLEUスコア評価によって示されるように、シンプルな印刷表現(SPE)、複雑な印刷表現(CPE)、スクリーンキャプチャ表現(SCE)、手書き表現(HWE)において優れた性能を示しています。
![BLEU](./asset/papers/fig1_bleu.jpg)
## SOTAメソッドとのパフォーマンス比較(CDM)。
> 数式の表現には多様性があるため、異なるモデルの比較にBLEU指標を使用することは公平ではありません。そのため、数式認識専用に設計されたCDMで評価を行いました。我々の方法はオープンソースモデルを大幅に上回り、商用ソフトウェアMathpixと同等の効果を示しました。CDM@ExpRateは完全に予測が正しい数式の割合を指し、詳細は[CDM](https://arxiv.org/pdf/2409.03643)論文を参照してください。
![CDM](./asset/papers/fig2_cdm.jpg)
## 異なるメソッドによる可視化結果。
> UniMERNetは、他のメソッドを上回る挑戦的なサンプルの視覚的認識において優れています。
![Visualization](https://github.com/opendatalab/VIGC/assets/69186975/6edcac69-5082-43a2-8095-5681b7a707b9)
## UniMERデータセット
### イントロダクション
UniMERデータセットは、数式認識(MER)分野を進展させるために特別に収集されたコレクションです。これには、100万以上のインスタンスを含む包括的なUniMER-1Mトレーニングセットと、実世界のシナリオに対するMERモデルのベンチマークテスト用に精巧に設計されたUniMERテストセットが含まれます。データセットの詳細は以下の通りです:
**UniMER-1Mトレーニングセット:**
- 総サンプル数:1,061,791のLaTeX-画像ペア
- 構成:簡潔で複雑な拡張数式表現のバランスの取れた混合
- 目的:堅牢で高精度なMERモデルをトレーニングし、認識精度と一般化能力を向上させる
**UniMERテストセット:**
- 総サンプル数:23,757、4種類の表現に分類:
- シンプルな印刷表現(SPE):6,762サンプル
- 複雑な印刷表現(CPE):5,921サンプル
- スクリーンキャプチャ表現(SCE):4,742サンプル
- 手書き表現(HWE):6,332サンプル
- 目的:さまざまな実世界の条件下でMERモデルを徹底的に評価する
### データセットのダウンロード
データセットは[OpenDataLab](https://opendatalab.com/OpenDataLab/UniMER-Dataset)(中国ユーザー向け推奨)または[HuggingFace](https://huggingface.co/datasets/wanderkid/UniMER_Dataset)からダウンロードできます。
### UniMER-Testデータセットのダウンロード
UniMER-1Mデータセットをダウンロードし、以下のディレクトリに解凍します:
```bash
./data/UniMER-1M
```
UniMER-Testデータセットをダウンロードし、以下のディレクトリに解凍します:
```bash
./data/UniMER-Test
```
## トレーニング
UniMERNetモデルをトレーニングするには、以下の手順に従ってください:
1. **トレーニングデータセットパスの指定**`configs/train`フォルダを開き、トレーニングデータセットのパスを設定します。
2. **トレーニングスクリプトの実行**:以下のコマンドを実行してトレーニングプロセスを開始します。
```bash
bash script/train.sh
```
### 注意:
- `configs/train`フォルダに指定されたデータセットパスが正しくアクセス可能であることを確認してください。
- トレーニングプロセス中のエラーや問題を監視してください。
## テスト
UniMERNetモデルをテストするには、以下の手順に従ってください:
1. **テストデータセットパスの指定**`configs/val`フォルダを開き、テストデータセットのパスを設定します。
2. **テストスクリプトの実行**:以下のコマンドを実行してテストプロセスを開始します。
```bash
bash script/test.sh
```
### 注意:
- `configs/val`フォルダに指定されたデータセットパスが正しくアクセス可能であることを確認してください。
- `test.py`スクリプトは指定されたテストデータセットを使用して評価を行います。test.pyのテストセットパスを実際のパスに変更することを忘れないでください。
- テスト結果を確認して、パフォーマンス指標や潜在的な問題を確認してください。
## 数式検出チュートリアル
数式認識の前提条件は、PDFやウェブページのスクリーンショット内の数式が存在する領域を検出することです。[PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit)には、数式を検出するための強力なモデルが含まれています。数式の検出と認識の両方を自分で行いたい場合は、数式検出モデルのデプロイと使用に関するガイドラインについて[数式検出チュートリアル](./MFD/README.md)を参照してください。
## TODO
[✅] UniMERNetの推論コードとモデルをリリース。
[✅] UniMER-1MとUniMER-Testをリリース。
[✅] Streamlit数式認識GUIアプリケーションをオープンソース化。
[✅] UniMERNetのトレーニングコードをリリース。
## 引用
私たちのモデル/コード/論文が研究に役立つ場合は、スターを付けていただき、私たちの仕事を引用してください。ありがとうございます。
```bibtex
@misc{wang2024unimernetuniversalnetworkrealworld,
title={UniMERNet: A Universal Network for Real-World Mathematical Expression Recognition},
author={Bin Wang and Zhuangcheng Gu and Guang Liang and Chao Xu and Bo Zhang and Botian Shi and Conghui He},
year={2024},
eprint={2404.15254},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2404.15254},
}
@misc{wang2024cdmreliablemetricfair,
title={CDM: A Reliable Metric for Fair and Accurate Formula Recognition Evaluation},
author={Bin Wang and Fan Wu and Linke Ouyang and Zhuangcheng Gu and Rui Zhang and Renqiu Xia and Bo Zhang and Conghui He},
year={2024},
eprint={2409.03643},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2409.03643},
}
```
## 謝辞
- [VIGC](https://github.com/opendatalab/VIGC)。モデルフレームワークはVIGCに依存しています。
- [Texify](https://github.com/VikParuchuri/texify)。主流のMERアルゴリズムであり、UniMERNetのデータ処理はTexifyを参考にしています。
- [Latex-OCR](https://github.com/lukas-blecher/LaTeX-OCR)。もう一つの主流のMERアルゴリズムです。
- [Donut](https://huggingface.co/naver-clova-ix/donut-base)。UniMERNetのTransformerエンコーダー-デコーダーはDonutを参考にしています。
- [Nougat](https://github.com/facebookresearch/nougat)。トークナイザーはNougatを使用しています。
## お問い合わせ
質問、コメント、提案がある場合は、wangbin@pjlab.org.cnまでお気軽にお問い合わせください。
## ライセンス
[Apache License 2.0](LICENSE)
<div align="center">
[English](./README.md) | 简体中文 | [日本語](./README-ja.md)
<h1>UniMERNet: 一个用于真实世界数学表达式识别的通用网络</h1>
[[ 论文 ]](https://arxiv.org/abs/2404.15254) [[ 网站 ]](https://github.com/opendatalab/UniMERNet/tree/main) [[ 数据集 (OpenDataLab)]](https://opendatalab.com/OpenDataLab/UniMER-Dataset) [[ 数据集 (Hugging Face) ]](https://huggingface.co/datasets/wanderkid/UniMER_Dataset)
[[模型 🤗(Hugging Face)]](https://huggingface.co/wanderkid/unimernet_base)
[[模型 <img src="./asset/images/modelscope_logo.png" width="20px">(ModelScope)]](https://www.modelscope.cn/models/wanderkid/unimernet_base)
🔥🔥🔥 [CDM: 一种公平、准确的可信公式识别评测指标](https://github.com/opendatalab/UniMERNet/tree/main/cdm)
</div>
欢迎来到 UniMERNet 的官方仓库,这是一个将数学表达式图像转换为 LaTeX 的解决方案,适用于各种真实世界场景。
## 新闻 🚀🚀🚀
**2025.09.28** 🎉🎉 CDM 支持并优化了中文公式的渲染。
**2025.03.25** 🎉🎉 <font color="red">公式识别新指标[CDM](https://arxiv.org/abs/2409.03643) 论文已被CVPR 2025接收,欢迎大家使用。</font>
**2024.09.06** 🎉🎉 UniMERNet 版本更新,训练代码开源,新版本模型更小,速度更快。具体见最新版本论文[UniMERNet](https://arxiv.org/abs/2404.15254)
**2024.09.06** 🎉🎉 提出公式识别新指标[CDM](https://github.com/opendatalab/UniMERNet/tree/main/cdm),相比于BLEU/EditDistance,CDM评测得分更加直观,准确,可以公平对比不同模型性能,不受公式多样性表达影响。
**2024.07.21** 🎉🎉 基于 [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) MFD 模型,添加了数学公式检测 (MFD) 教程。
**2024.06.06** 🎉🎉 开源了 UniMER 数据集的评估代码。
**2024.05.06** 🎉🎉 开源了 UniMER 数据集,包括用于模型训练的 UniMER-1M 和用于 MER 评估的 UniMER-Test。
**2024.05.06** 🎉🎉 添加了 Streamlit 公式识别演示,并提供了本地部署应用程序。
**2024.04.24** 🎉🎉 论文现在可以在 [ArXiv](https://arxiv.org/abs/2404.15254) 上查看。
**2024.04.24** 🎉🎉 发布了推理代码和检查点。
## 演示视频
https://github.com/opendatalab/UniMERNet/assets/69186975/ac54c6b9-442c-48b0-95f9-a4a3fce8780b
https://github.com/opendatalab/UniMERNet/assets/69186975/09b71c55-c58a-4792-afc1-d5774880ccf8
## 快速开始
### 克隆仓库并下载模型
```bash
git clone https://github.com/opendatalab/UniMERNet.git
```
```bash
cd UniMERNet/models
# 单独下载模型和分词器或使用 git-lfs
git lfs install
git clone https://huggingface.co/wanderkid/unimernet_base # 1.3GB
git clone https://huggingface.co/wanderkid/unimernet_small # 773MB
git clone https://huggingface.co/wanderkid/unimernet_tiny # 441MB
# 你也可以从 ModelScope 下载模型
git clone https://www.modelscope.cn/wanderkid/unimernet_base.git
git clone https://www.modelscope.cn/wanderkid/unimernet_small.git
git clone https://www.modelscope.cn/wanderkid/unimernet_tiny.git
```
### 安装
> 新建一个干净的conda环境
``` bash
conda create -n unimernet python=3.10
conda activate unimernet
```
> 安装方式1:直接 pip install安装,适合一般用户
```bash
pip install --upgrade unimernet
pip install "unimernet[full]"
```
> 安装方式2:本地安装,适合开发者
```bash
pip install -e ."[full]"
```
### 运行 UniMERNet
1. **Streamlit 应用程序**:使用我们的基于 Streamlit 的 GUI 进行交互和用户友好的体验。此应用程序允许实时公式识别和渲染。
```bash
unimernet_gui
```
确保你已安装最新版本的 UniMERNet (`pip install --upgrade unimernet & pip install "unimernet[full]"`) 以使用 Streamlit GUI 应用程序。
2. **命令行演示**:从图像中预测 LaTeX 代码。
```bash
python demo.py
```
3. **Jupyter Notebook 演示**:从图像中识别和渲染公式。
```bash
jupyter-lab ./demo.ipynb
```
## 与 SOTA 方法的性能比较(BLEU)。
> UniMERNet 在识别真实世界数学表达式方面显著优于主流模型,在简单打印表达式(SPE)、复杂打印表达式(CPE)、屏幕截图表达式(SCE)和手写表达式(HWE)方面表现出色,如 BLEU 分数评估所示。
![BLEU](./asset/papers/fig1_bleu.jpg)
## 与 SOTA 方法的性能比较(CDM)。
> 由于公式存在表达的多样性,使用BLEU指标对于不同模型对比不具备公平性,为此我们在专门针对公式识别设计的CDM上进行评估,我们的方法远超开源模型,与商业软件Mathpix效果相当,CDM@ExpRate是指完全预测正确公式占比,具体参考[CDM](https://arxiv.org/pdf/2409.03643)论文。
![CDM](./asset/papers/fig2_cdm.jpg)
## 不同方法的可视化结果。
> UniMERNet 在挑战性样本的视觉识别方面表现出色,优于其他方法。
![Visualization](https://github.com/opendatalab/VIGC/assets/69186975/6edcac69-5082-43a2-8095-5681b7a707b9)
## UniMER 数据集
### 介绍
UniMER 数据集是一个专门收集的集合,旨在推进数学表达式识别(MER)领域。它包括全面的 UniMER-1M 训练集,包含超过一百万个实例,代表了多样且复杂的数学表达式,以及精心设计的 UniMER 测试集,用于基准测试 MER 模型在真实世界场景中的表现。数据集详情如下:
**UniMER-1M 训练集:**
- 总样本数:1,061,791 对 LaTeX-图像对
- 组成:简洁和复杂的扩展公式表达的平衡混合
- 目的:训练鲁棒、高精度的 MER 模型,提高识别精度和泛化能力
**UniMER 测试集:**
- 总样本数:23,757 个,分为四种表达式类型:
- 简单打印表达式(SPE):6,762 个样本
- 复杂打印表达式(CPE):5,921 个样本
- 屏幕截图表达式(SCE):4,742 个样本
- 手写表达式(HWE):6,332 个样本
- 目的:在各种真实世界条件下对 MER 模型进行全面评估
### 数据集下载
你可以从 [OpenDataLab](https://opendatalab.com/OpenDataLab/UniMER-Dataset)(推荐中国用户)或 [HuggingFace](https://huggingface.co/datasets/wanderkid/UniMER_Dataset) 下载数据集。
### 下载 UniMER-Test 数据集
下载 UniMER-1M 数据集并将其解压到以下目录:
```bash
./data/UniMER-1M
```
下载 UniMER-Test 数据集并将其解压到以下目录:
```bash
./data/UniMER-Test
```
## 训练
要训练 UniMERNet 模型,请按照以下步骤操作:
1. **指定训练数据集路径**:打开 `configs/train` 文件夹并设置你的训练数据集路径。
2. **运行训练脚本**:执行以下命令以开始训练过程。
```bash
bash script/train.sh
```
### 注意:
- 确保 `configs/train` 文件夹中指定的数据集路径是正确且可访问的。
- 监控训练过程中的任何错误或问题。
## 测试
要测试 UniMERNet 模型,请按照以下步骤操作:
1. **指定测试数据集路径**:打开 `configs/val` 文件夹并设置你的测试数据集路径。
2. **运行测试脚本**:执行以下命令以开始测试过程。
```bash
bash script/test.sh
```
### 注意:
- 确保 `configs/val` 文件夹中指定的数据集路径是正确且可访问的。
- `test.py` 脚本将使用指定的测试数据集进行评估。记得将 `test.py` 中的测试集路径更改为你的实际路径。
- 查看测试结果以获取性能指标和潜在问题。
## 数学公式检测教程
公式识别的前提是检测 PDF 或网页截图中公式所在的区域。[PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) 包含了一个强大的公式检测模型。如果你希望自行进行公式检测和识别,可以参考 [公式检测教程](./MFD/README.md) 以获取有关部署和使用公式检测模型的指南。
## 待办事项
[✅] 发布 UniMERNet 的推理代码和模型。
[✅] 发布 UniMER-1M 和 UniMER-Test。
[✅] 开源 Streamlit 公式识别 GUI 应用程序。
[✅] 发布 UniMERNet 的训练代码。
## 引用
如果你在研究中发现我们的模型/代码/论文有用,欢迎给我们项目点个 ⭐ 并引用我们的工作 📝,谢谢 :)
```bibtex
@misc{wang2024unimernetuniversalnetworkrealworld,
title={UniMERNet: A Universal Network for Real-World Mathematical Expression Recognition},
author={Bin Wang and Zhuangcheng Gu and Guang Liang and Chao Xu and Bo Zhang and Botian Shi and Conghui He},
year={2024},
eprint={2404.15254},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2404.15254},
}
@misc{wang2024cdmreliablemetricfair,
title={CDM: A Reliable Metric for Fair and Accurate Formula Recognition Evaluation},
author={Bin Wang and Fan Wu and Linke Ouyang and Zhuangcheng Gu and Rui Zhang and Renqiu Xia and Bo Zhang and Conghui He},
year={2024},
eprint={2409.03643},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2409.03643},
}
```
## 致谢
- [VIGC](https://github.com/opendatalab/VIGC)。模型框架依赖于 VIGC。
- [Texify](https://github.com/VikParuchuri/texify)。一个主流的 MER 算法,UniMERNet 的数据处理参考了 Texify。
- [Latex-OCR](https://github.com/lukas-blecher/LaTeX-OCR)。另一个主流的 MER 算法。
- [Donut](https://huggingface.co/naver-clova-ix/donut-base)。UniMERNet 的 Transformer 编码器-解码器参考了 Donut。
- [Nougat](https://github.com/facebookresearch/nougat)。分词器使用了 Nougat。
## 联系我们
如果你有任何问题、意见或建议,请随时通过 wangbin@pjlab.org.cn 联系我们。
## 许可证
[Apache 许可证 2.0](LICENSE)
# MiniMax-M2
## 论文
[UniMERNet](https://arxiv.org/abs/2404.15254)
## 模型简介
UniMERNet 是一个深度学习模型,专注于数学公式的识别。它可以从手写或打印的数学公式图像中提取出精确的数学表达式,并将其转换为 LaTeX 代码。LaTeX 是广泛应用于数学、科学和技术领域的排版系统,因此,能够将数学公式转换为 LaTeX 代码对于公式的展示和编辑至关重要。
**主要特点:**
**高精度识别:** 支持手写和打印数学公式的高精度识别。
**实时渲染:** 通过 Streamlit 和 LaTeX 渲染,您可以实时查看公式识别结果。
**多平台支持:** UniMERNet 可以在 Windows、Linux 和 macOS 等操作系统上运行。
## 环境依赖
| 软件 | 版本 |
| :------: | :------: |
| DTK | 25.04.2 |
| python | 3.10.12 |
| transformers | 4.57.1 |
| vllm | 0.11.0+das.opt1.alpha.8e22ded.dtk25042 |
| torch | 2.5.1+das.opt1.dtk25042 |
| triton | 3.1+das.opt1.3c5d12d.dtk25041 |
| flash_attn | 2.6.1+das.opt1.dtk2504 |
| flash_mla | 1.0.0+das.opt1.dtk25042 |
当前仅支持镜像:
- 挂载地址`-v`根据实际模型情况修改
```bash
docker run -it --shm-size 60g --network=host --name minimax_m2 --privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mkfd --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /opt/hyhal/:/opt/hyhal/:ro -v /path/your_code_path/:/path/your_code_path/ image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.5.1-ubuntu22.04-dtk25.04.2-py3.10 bash
```
更多镜像可前往[光源](https://sourcefind.cn/#/service-list)下载使用。
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
## 数据集
### 介绍
UniMER 数据集是一个专门收集的集合,旨在推进数学表达式识别(MER)领域。它包括全面的 UniMER-1M 训练集,包含超过一百万个实例,代表了多样且复杂的数学表达式,以及精心设计的 UniMER 测试集,用于基准测试 MER 模型在真实世界场景中的表现。数据集详情如下:
**UniMER-1M 训练集:**
- 总样本数:1,061,791 对 LaTeX-图像对
- 组成:简洁和复杂的扩展公式表达的平衡混合
- 目的:训练鲁棒、高精度的 MER 模型,提高识别精度和泛化能力
**UniMER 测试集:**
- 总样本数:23,757 个,分为四种表达式类型:
- 简单打印表达式(SPE):6,762 个样本
- 复杂打印表达式(CPE):5,921 个样本
- 屏幕截图表达式(SCE):4,742 个样本
- 手写表达式(HWE):6,332 个样本
- 目的:在各种真实世界条件下对 MER 模型进行全面评估
### 数据集下载
你可以从 [OpenDataLab](https://opendatalab.com/OpenDataLab/UniMER-Dataset)(推荐中国用户)或 [HuggingFace](https://huggingface.co/datasets/wanderkid/UniMER_Dataset) 下载数据集。
## 训练
要训练 UniMERNet 模型,请按照以下步骤操作:
1. **指定训练数据集路径**:打开 `configs/train` 文件夹并设置你的训练数据集路径。
2. **运行训练脚本**:执行以下命令以开始训练过程。
```bash
bash script/train.sh
```
### 注意:
- 确保 `configs/train` 文件夹中指定的数据集路径是正确且可访问的。
- 监控训练过程中的任何错误或问题。
## 推理
模型权重
```bash
git clone https://github.com/opendatalab/UniMERNet.git
```
```bash
cd UniMERNet/models
# 单独下载模型和分词器或使用 git-lfs
git lfs install
git clone https://huggingface.co/wanderkid/unimernet_base # 1.3GB
git clone https://huggingface.co/wanderkid/unimernet_small # 773MB
git clone https://huggingface.co/wanderkid/unimernet_tiny # 441MB
# 你也可以从 ModelScope 下载模型
git clone https://www.modelscope.cn/wanderkid/unimernet_base.git
git clone https://www.modelscope.cn/wanderkid/unimernet_small.git
git clone https://www.modelscope.cn/wanderkid/unimernet_tiny.git
```
. **Streamlit 应用程序**:使用我们的基于 Streamlit 的 GUI 进行交互和用户友好的体验。此应用程序允许实时公式识别和渲染。
```bash
unimernet_gui
```
确保你已安装最新版本的 UniMERNet (`pip install --upgrade unimernet & pip install "unimernet[full]"`) 以使用 Streamlit GUI 应用程序。
2. **命令行演示**:从图像中预测 LaTeX 代码。
```bash
python demo.py
```
3. **Jupyter Notebook 演示**:从图像中识别和渲染公式。
```bash
jupyter-lab ./demo.ipynb
```
## 效果展示
暂无
### 精度
DCU与GPU精度一致,推理框架:vllm。
## 预训练权重
| 模型名称 | 权重大小 | DCU型号 | 最低卡数需求 |下载地址|
|:-----:|:----------:|:----------:|:---------------------:|:----------:|
| unimernet_base | 1.3GB | K100AI | 1 | [下载地址](https://huggingface.co/wanderkid/unimernet_base) |
| unimernet_small | 1.3GB | K100AI | 1 | [下载地址](https://huggingface.co/wanderkid/unimernet_small) |
| unimernet_tiny | 1.3GB | K100AI | 1 | [下载地址](https://huggingface.co/wanderkid/unimernet_tiny ) |
## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/unimernet_transformers
## 参考资料
- https://github.com/opendatalab/UniMERNet
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment