Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL authored Sep 13, 2023
1 parent f1fc6e4 commit cf3860d
Showing 1 changed file with 68 additions and 66 deletions.
134 changes: 68 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,77 @@
- [ ] Integrate other better models
- [ ] Add support for OpenVINO

### Use
1. Installation
1. pip install `rapid_latext_ocr` library. Because packaging the model into the whl package exceeds the pypi limit (100M), the model needs to be downloaded separately.
```bash
pip install rapid_latex_ocr
```
2. Download the model ([Google Drive](https://drive.google.com/drive/folders/1e8BgLk1cPQDSZjgoLgloFYMAQWLTaroQ?usp=sharing) | [Baidu NetDisk](https://pan.baidu.com/s/1rnYmmKp2HhOkYVFehUiMNg?pwd=dh72)), when initializing, just specify the model path, see the next part for details.

|model name|size|
|---:|:---:|
|`image_resizer.onnx`|37.1M|
|`encoder.onnx`|84.8M|
|`decoder.onnx`|48.5M|

2. Use
- Used by python script:
```python
from rapid_latex_ocr import LatexOCR
image_resizer_path = 'models/image_resizer.onnx'
encoder_path = 'models/encoder.onnx'
decoder_path = 'models/decoder.onnx'
tokenizer_json = 'models/tokenizer.json'
model = LatexOCR(image_resizer_path=image_resizer_path,
encoder_path=encoder_path,
decoder_path=decoder_path,
tokenizer_json=tokenizer_json)
img_path = "tests/test_files/6.png"
with open(img_path, "rb") as f:
data = f. read()
result, elapse = model(data)
print(result)
# {\frac{x^{2}}{a^{2}}}-{\frac{y^{2}}{b^{2}}}=1
print(elapse)
# 0.4131628000000003
```
- Used by command line.
```bash
$ rapid_latex_ocr -h
usage: rapid_latex_ocr [-h] [-img_resizer IMAGE_RESIZER_PATH]
[-encdoer ENCODER_PATH] [-decoder DECODER_PATH]
[-tokenizer TOKENIZER_JSON]
img_path
positional arguments:
img_path Only img path of the formula.
optional arguments:
-h, --help show this help message and exit
-img_resizer IMAGE_RESIZER_PATH, --image_resizer_path IMAGE_RESIZER_PATH
-encdoer ENCODER_PATH, --encoder_path ENCODER_PATH
-decoder DECODER_PATH, --decoder_path DECODER_PATH
-tokenizer TOKENIZER_JSON, --tokenizer_json TOKENIZER_JSON
$ rapid_latex_ocr tests/test_files/6.png \
-img_resizer models/image_resizer.onnx \
-encoder models/encoder.onnx \
-dedocer models/decoder.onnx \
-tokenizer models/tokenizer.json
# ('{\\frac{x^{2}}{a^{2}}}-{\\frac{y^{2}}{b^{2}}}=1', 0.47902780000000034)
```
### Installation
1. pip install `rapid_latext_ocr` library. Because packaging the model into the whl package exceeds the pypi limit (100M), the model needs to be downloaded separately.
```bash
pip install rapid_latex_ocr
```
2. Download the model ([Google Drive](https://drive.google.com/drive/folders/1e8BgLk1cPQDSZjgoLgloFYMAQWLTaroQ?usp=sharing) | [Baidu NetDisk](https://pan.baidu.com/s/1rnYmmKp2HhOkYVFehUiMNg?pwd=dh72)), when initializing, just specify the model path, see the next part for details.

|model name|size|
|---:|:---:|
|`image_resizer.onnx`|37.1M|
|`encoder.onnx`|84.8M|
|`decoder.onnx`|48.5M|


### Usage
- Used by python script:
```python
from rapid_latex_ocr import LatexOCR
image_resizer_path = 'models/image_resizer.onnx'
encoder_path = 'models/encoder.onnx'
decoder_path = 'models/decoder.onnx'
tokenizer_json = 'models/tokenizer.json'
model = LatexOCR(image_resizer_path=image_resizer_path,
encoder_path=encoder_path,
decoder_path=decoder_path,
tokenizer_json=tokenizer_json)
img_path = "tests/test_files/6.png"
with open(img_path, "rb") as f:
data = f. read()
result, elapse = model(data)
print(result)
# {\frac{x^{2}}{a^{2}}}-{\frac{y^{2}}{b^{2}}}=1
print(elapse)
# 0.4131628000000003
```
- Used by command line.
```bash
$ rapid_latex_ocr -h
usage: rapid_latex_ocr [-h] [-img_resizer IMAGE_RESIZER_PATH]
[-encdoer ENCODER_PATH] [-decoder DECODER_PATH]
[-tokenizer TOKENIZER_JSON]
img_path
positional arguments:
img_path Only img path of the formula.
optional arguments:
-h, --help show this help message and exit
-img_resizer IMAGE_RESIZER_PATH, --image_resizer_path IMAGE_RESIZER_PATH
-encdoer ENCODER_PATH, --encoder_path ENCODER_PATH
-decoder DECODER_PATH, --decoder_path DECODER_PATH
-tokenizer TOKENIZER_JSON, --tokenizer_json TOKENIZER_JSON
$ rapid_latex_ocr tests/test_files/6.png \
-img_resizer models/image_resizer.onnx \
-encoder models/encoder.onnx \
-dedocer models/decoder.onnx \
-tokenizer models/tokenizer.json
# ('{\\frac{x^{2}}{a^{2}}}-{\\frac{y^{2}}{b^{2}}}=1', 0.47902780000000034)
```

### 👫 Community
We regard [RapidLatexOCR Discussions](https://github.com/RapidAI/RapidLatexOCR/discussions) as our community platform. All ideas and questions can be discussed here in English.

### ChangLog
- 2023-09-13 v0.0.4 update:
- Merge [pr #5](https://github.com/RapidAI/RapidLatexOCR/pull/5)
- 2023-07-15 v0.0.1 update:
- First release
- First release

0 comments on commit cf3860d

Please sign in to comment.