Indra OCR v1.1.0
Browse files- .gitattributes +2 -0
- README.md +136 -43
- assets/examples/{chinese_essay.png → handwriting_letter.png} +2 -2
- assets/examples/{multi_column.png → korean_letter.png} +2 -2
- assets/speed_score.png +2 -2
- assets/throughput.png +2 -2
- config.json +8 -3
- det.onnx +1 -1
- lm.npz +3 -0
- lm_cjk.npz +3 -0
- lm_world.npz +3 -0
- meta.json +0 -0
- model.safetensors +2 -2
- order.onnx +1 -1
- orient.onnx +2 -2
- rec.onnx +2 -2
- rec_cjk.onnx +2 -2
- assets/examples/rotated_letter.png → rec_rtl.onnx +2 -2
- assets/examples/table_pmc.png → rec_world.onnx +2 -2
- script.onnx +2 -2
.gitattributes
CHANGED
|
@@ -46,3 +46,5 @@ assets/examples/chinese_essay.png filter=lfs diff=lfs merge=lfs -text
|
|
| 46 |
assets/examples/multi_column.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
assets/examples/rotated_letter.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
assets/examples/table_pmc.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 46 |
assets/examples/multi_column.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
assets/examples/rotated_letter.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
assets/examples/table_pmc.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
assets/examples/handwriting_letter.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
assets/examples/korean_letter.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -12,12 +12,55 @@ language:
|
|
| 12 |
- pt
|
| 13 |
- nl
|
| 14 |
- pl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
- ru
|
| 16 |
- uk
|
|
|
|
|
|
|
| 17 |
- el
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
- hi
|
|
|
|
|
|
|
| 19 |
- bn
|
| 20 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
tags:
|
| 22 |
- ocr
|
| 23 |
- onnx
|
|
@@ -26,6 +69,8 @@ tags:
|
|
| 26 |
- markdown
|
| 27 |
- layout
|
| 28 |
- document-parsing
|
|
|
|
|
|
|
| 29 |
---
|
| 30 |
|
| 31 |
<p align="center">
|
|
@@ -51,16 +96,16 @@ tags:
|
|
| 51 |
|
| 52 |
# Indra OCR
|
| 53 |
|
| 54 |
-
Indra OCR is a 1M-parameter OCR model that
|
| 55 |
-
|
| 56 |
-
- Throughput - 49 pages/s, 11-17x faster than Tesseract and PaddleOCR on the same machine and pages ([table](#throughput))
|
| 57 |
-
- Latency - ~230 ms per page on 4 x86 vCPUs, 12-24x faster than Tesseract and PaddleOCR
|
| 58 |
-
- Accuracy - scores 41.3 on [OmniParseBench](https://github.com/datalab-to/omni_parse_bench) text, ahead of PaddleOCR's PP-OCR text models (35.8) and Tesseract (19.3). Its headline score (62.1) beats PaddleOCR's full PP-StructureV3 pipeline (58.4).
|
| 59 |
-
- Layout and boxes - a bounding box for every line and every layout block, with block labels (headings, lists, tables, captions, footnotes, page headers) and reading order
|
| 60 |
-
- Digital PDFs - reads the PDF's own text layer in any script, and OCRs only what is missing
|
| 61 |
-
- Small - about 18 MB of models on ONNX Runtime, no PyTorch
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
Indra OCR is named for [Indra](https://en.wikipedia.org/wiki/Indra).
|
| 66 |
|
|
@@ -72,7 +117,7 @@ Indra OCR is built for speed on CPUs. When you need the highest accuracy, on han
|
|
| 72 |
|
| 73 |
If you have high volume workloads, we offer a batch processing service that can handle 1B+ pages a day.
|
| 74 |
|
| 75 |
-
Get started with **$5 in free credits** - [sign up](https://www.datalab.to/?utm_source=
|
| 76 |
|
| 77 |
## Quickstart
|
| 78 |
|
|
@@ -86,7 +131,7 @@ indra-ocr scan.png --format json # lines, boxes, layout blocks, confidence
|
|
| 86 |
indra-ocr-viewer # local web viewer on http://localhost:8765
|
| 87 |
```
|
| 88 |
|
| 89 |
-
The first run downloads the models (about
|
| 90 |
|
| 91 |
## Examples
|
| 92 |
|
|
@@ -94,8 +139,8 @@ Real Indra OCR outputs on OmniParseBench pages. Colored boxes are layout blocks
|
|
| 94 |
|
| 95 |
<table>
|
| 96 |
<tr>
|
| 97 |
-
<td width="50%"><img src="assets/examples/
|
| 98 |
-
<td width="50%"><img src="assets/examples/
|
| 99 |
</tr>
|
| 100 |
</table>
|
| 101 |
|
|
@@ -108,7 +153,7 @@ The code is [Apache 2.0](https://github.com/datalab-to/indra/blob/main/LICENSE).
|
|
| 108 |
|
| 109 |
# Commercial usage
|
| 110 |
|
| 111 |
-
This code is Apache 2.0, and our model weights use a modified OpenRAIL-M license (free for research, personal use, and startups under $20M funding/revenue, cannot be used competitively with our API). To remove the OpenRAIL license requirements, or for broader commercial licensing, visit our pricing page [here](https://www.datalab.to/pricing?utm_source=
|
| 112 |
|
| 113 |
# Installation
|
| 114 |
|
|
@@ -116,7 +161,11 @@ This code is Apache 2.0, and our model weights use a modified OpenRAIL-M license
|
|
| 116 |
pip install indra-ocr
|
| 117 |
```
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Usage
|
| 122 |
|
|
@@ -137,7 +186,6 @@ indra-ocr paper.pdf --math # write math as LaTeX (off by default;
|
|
| 137 |
- `--out DIR`: write one file per input (`.md`, `.txt` or `.jsonl`)
|
| 138 |
- `--format [md|text|json]`: output format (default: md)
|
| 139 |
- `--mode [auto|ocr|text]`: `auto` reads the text layer where it passes the checks and OCRs elsewhere (default). `ocr` never reads the text layer. `text` uses the text layer even when the checks fail
|
| 140 |
-
- `--model-order`: order text-layer lines with the order model, not the PDF content order
|
| 141 |
- `--no-image-ocr`: on text-layer pages, do not OCR text inside images
|
| 142 |
- `--cores N`: cores to use, one worker process each (default: all usable cores)
|
| 143 |
- `--dpi`: render resolution for PDFs (default: 200)
|
|
@@ -163,6 +211,23 @@ for i, page in conv.convert("paper.pdf"):
|
|
| 163 |
page.lines # [Line(box, text, conf)] in reading order
|
| 164 |
```
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
For many pages or files, `convert_many` runs one single-threaded worker process per core, one page per task, and returns results in input order:
|
| 167 |
|
| 168 |
```python
|
|
@@ -178,7 +243,7 @@ if __name__ == "__main__": # worker processes re-import this file
|
|
| 178 |
|
| 179 |
Without the `if __name__ == "__main__":` guard (needed on macOS and Windows), `convert_many` warns and reads everything in one process.
|
| 180 |
|
| 181 |
-
`indra_ocr.load` takes `path` (model folder), `threads`, `dpi`, `mode`, `
|
| 182 |
|
| 183 |
## Viewer
|
| 184 |
|
|
@@ -198,6 +263,7 @@ Every page is a `Page` with:
|
|
| 198 |
- `blocks`: layout blocks in reading order, `{"label", "bbox", "text"}`
|
| 199 |
- `source`: `text` (PDF text layer), `ocr`, `hybrid` (text layer + OCR of text inside images) or `error`
|
| 200 |
- `rotation`, `skew`: the quarter or half turn applied (degrees), and the small tilt straightened
|
|
|
|
| 201 |
- `timings`: per-step milliseconds, with `total_ms`
|
| 202 |
- `note`: why the page took its path
|
| 203 |
|
|
@@ -205,7 +271,33 @@ Block labels: `Text`, `Section-Header`, `Page-Header`, `Page-Footer`, `List-Grou
|
|
| 205 |
|
| 206 |
# Languages
|
| 207 |
|
| 208 |
-
**OCR (scans and images):**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
**Text layer (digital PDFs): any script.** We checked text mode on 1,125 pages from 75 language families. On pages whose layer passes the checks, Indra OCR keeps at least 98% of the layer's characters in every family, including Arabic, Hebrew, Persian, Urdu, Thai, Khmer, Lao, Myanmar, Georgian, Armenian, Ethiopic, the Indic scripts, Chinese, Japanese and Korean. Right-to-left lines keep their right-to-left order.
|
| 211 |
|
|
@@ -214,18 +306,18 @@ Block labels: `Text`, `Section-Header`, `Page-Header`, `Page-Footer`, `List-Grou
|
|
| 214 |
Indra OCR is built for speed on clean print. It is not the right tool for:
|
| 215 |
|
| 216 |
- **Complex tables.** Tables with merged or spanning cells, cell text that wraps over several lines, nested headers, or no ruling lines can come out with cells in the wrong rows or columns. Simple grid tables read well.
|
| 217 |
-
- **Handwriting.** Handwritten
|
| 218 |
-
- **Scripts outside the OCR list.**
|
| 219 |
-
- **
|
|
|
|
| 220 |
|
| 221 |
Also:
|
| 222 |
|
| 223 |
- Math comes out as plain text unless `--math` is on (see [Math](#math)).
|
| 224 |
-
-
|
| 225 |
- Very wide, banner-shaped pages read poorly.
|
| 226 |
- Labels inside engineering drawings often come out as small tables.
|
| 227 |
- Pages above 100 megapixels at 200 dpi render at a lower dpi, so small text on them can be lost.
|
| 228 |
-
- The orientation model turns about half of the upright Arabic and Hebrew pages that go to OCR by mistake. Do not rely on it for those scripts.
|
| 229 |
|
| 230 |
For these documents, [Chandra on Datalab](https://www.datalab.to/?utm_source=hf-indra-ocr) is the accurate option.
|
| 231 |
|
|
@@ -237,15 +329,13 @@ On OmniParseBench (all 2,937 pages, default settings otherwise):
|
|
| 237 |
|
| 238 |
| | headline | text | tables | layout | math tests |
|
| 239 |
|---|---|---|---|---|---|
|
| 240 |
-
| Indra OCR |
|
| 241 |
-
| Indra OCR `--math` | **
|
| 242 |
| PaddleOCR PP-StructureV3 | 58.4 | 55.6 | 47.8 | 71.7 | – |
|
| 243 |
|
| 244 |
- With `--math`, Indra OCR is ahead of PaddleOCR's PP-StructureV3 on the headline, text, tables and layout. Without it, PP-StructureV3 leads on text.
|
| 245 |
- Tables lose 1.5 points: numbers in some table cells are read as math.
|
| 246 |
-
- `--math` is slower. On x86
|
| 247 |
-
- The cost falls on the pages where the math path runs. In auto mode, pages read through a digital PDF's text layer slow down most: their median time per page goes from 130 ms to 345 ms in the throughput run (one single-threaded worker per core).
|
| 248 |
-
- Old scanned math gains little (22.2 to 23.1).
|
| 249 |
|
| 250 |
The math models download only when `--math` is on.
|
| 251 |
|
|
@@ -259,20 +349,21 @@ The math models download only when `--math` is on.
|
|
| 259 |
|
| 260 |
| engine | headline | text | tables | layout | median ms / page |
|
| 261 |
|---|---|---|---|---|---|
|
| 262 |
-
| Indra OCR (auto: text layer + OCR) |
|
| 263 |
-
| Indra OCR (OCR only) |
|
| 264 |
-
| Indra OCR `--math` (auto) | **
|
| 265 |
| PaddleOCR PP-OCRv6 small, text models only (RapidOCR) | – | 35.8 | 0.0 | – | 2,685 |
|
| 266 |
| PaddleOCR PP-StructureV3 (2,918 pages\*) | 58.4 | 55.6 | 47.8 | 71.7 | 40,958 |
|
| 267 |
| Tesseract 5 (our run, Latin model) | – | 19.3 | 0.0 | – | 5,496 |
|
| 268 |
|
|
|
|
| 269 |
- The PP-OCR text models and Tesseract output lines, not tables or layout blocks, so their table scores are 0 and their layout family is not scored.
|
| 270 |
-
- PP-StructureV3 is PaddleOCR's full document pipeline (layout, tables, formulas). Without `--math`, it reads text better than Indra OCR (55.6 vs
|
| 271 |
-
- Faster settings exist, but we did not score their accuracy. Tesseract with the `eng` model and 1 thread takes 3.4 s a page (6.1 s as run). PP-StructureV3 without formula, seal and chart recognition, unwarping and orientation, and with its mobile OCR models, takes 10.5 s a page. Indra OCR is still
|
| 272 |
- The OmniParseBench leaderboard's own Tesseract run scores 17.6 on text.
|
| 273 |
-
- Median latency varies by about 15% between runs of the same code
|
| 274 |
|
| 275 |
-
**Chinese** (136 OmniParseBench Chinese tests): Indra OCR 64.
|
| 276 |
|
| 277 |
## olmOCR-bench
|
| 278 |
|
|
@@ -290,28 +381,30 @@ Born-digital splits and old scans, our harness, 200 dpi:
|
|
| 290 |
|
| 291 |
The CLI and `convert_many` run one single-threaded worker process per usable core, one page per task, so a single long PDF also uses every core. `--cores` limits it.
|
| 292 |
|
| 293 |
-
Pages per second
|
| 294 |
|
| 295 |
| engine | 4 cores | 8 cores | 16 cores | 32 cores |
|
| 296 |
|---|---|---|---|---|
|
| 297 |
-
| Indra OCR | **
|
| 298 |
-
| Indra OCR `--math`† | ~5 | – | – | ~30 |
|
| 299 |
| PaddleOCR PP-OCRv6 small, text models only (RapidOCR) | 0.65 | 1.24 | 2.42 | 4.28 |
|
| 300 |
| Tesseract 5 | 0.78 | 1.37 | 2.27 | 2.92 |
|
| 301 |
| PaddleOCR PP-StructureV3\* | ≤ 0.022 | ≤ 0.044 | ≤ 0.089 | ≤ 0.18 |
|
| 302 |
|
| 303 |
-
At 32 cores, Indra OCR is
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
Model loading and one warm-up page per worker are not timed.
|
| 306 |
|
| 307 |
## Reproducing
|
| 308 |
|
| 309 |
```shell
|
| 310 |
-
|
|
|
|
| 311 |
python bench/opb_indra.py --out runs/opb_auto --mode auto --procs 8
|
| 312 |
```
|
| 313 |
|
| 314 |
-
Each page runs in a single-threaded worker process, page headers and footers kept. `--mode ocr` gives the OCR-only row, `--limit N` scores the first N pages, and `--models` points at a local model folder. The run writes `summary.json` (the benchmark's own summary, plus median and p90 ms per page) and `pages.jsonl` (per page: time, source, tests passed).
|
| 315 |
|
| 316 |
# Credits
|
| 317 |
|
|
|
|
| 12 |
- pt
|
| 13 |
- nl
|
| 14 |
- pl
|
| 15 |
+
- cs
|
| 16 |
+
- sk
|
| 17 |
+
- ro
|
| 18 |
+
- hu
|
| 19 |
+
- sv
|
| 20 |
+
- da
|
| 21 |
+
- no
|
| 22 |
+
- fi
|
| 23 |
+
- tr
|
| 24 |
+
- az
|
| 25 |
+
- uz
|
| 26 |
+
- vi
|
| 27 |
+
- id
|
| 28 |
+
- ms
|
| 29 |
+
- sw
|
| 30 |
+
- ha
|
| 31 |
+
- yo
|
| 32 |
- ru
|
| 33 |
- uk
|
| 34 |
+
- bg
|
| 35 |
+
- sr
|
| 36 |
- el
|
| 37 |
+
- zh
|
| 38 |
+
- ja
|
| 39 |
+
- ko
|
| 40 |
+
- ar
|
| 41 |
+
- fa
|
| 42 |
+
- ur
|
| 43 |
+
- ps
|
| 44 |
+
- he
|
| 45 |
- hi
|
| 46 |
+
- mr
|
| 47 |
+
- ne
|
| 48 |
- bn
|
| 49 |
+
- ta
|
| 50 |
+
- te
|
| 51 |
+
- kn
|
| 52 |
+
- ml
|
| 53 |
+
- gu
|
| 54 |
+
- pa
|
| 55 |
+
- or
|
| 56 |
+
- th
|
| 57 |
+
- lo
|
| 58 |
+
- km
|
| 59 |
+
- my
|
| 60 |
+
- si
|
| 61 |
+
- ka
|
| 62 |
+
- hy
|
| 63 |
+
- am
|
| 64 |
tags:
|
| 65 |
- ocr
|
| 66 |
- onnx
|
|
|
|
| 69 |
- markdown
|
| 70 |
- layout
|
| 71 |
- document-parsing
|
| 72 |
+
- handwriting
|
| 73 |
+
- multilingual
|
| 74 |
---
|
| 75 |
|
| 76 |
<p align="center">
|
|
|
|
| 96 |
|
| 97 |
# Indra OCR
|
| 98 |
|
| 99 |
+
Indra OCR is a 1M-parameter OCR model that runs on CPU. It turns PDFs and images into markdown, text, or JSON with boxes, and it reads handwriting, 80+ languages, and pages at any angle.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
- **Accurate** - 66.7 on [OmniParseBench](https://github.com/datalab-to/omni_parse_bench) (71.4 with `--math`), ahead of PaddleOCR's full PP-StructureV3 pipeline (58.4). Its text score (46.7) is ahead of PaddleOCR's PP-OCR text models (35.8) and Tesseract (19.3).
|
| 102 |
+
- **Fast** - about 44 pages/s on 32 CPU cores, 15x Tesseract and 10x PaddleOCR's PP-OCR text models on the same machine type and pages, and about 210 ms per page on 4 cores ([benchmarks](#benchmarks))
|
| 103 |
+
- **80+ languages** - Latin-script languages, Russian and the Cyrillic languages, Greek, Chinese, Japanese, Korean, Arabic, Persian, Urdu, Hebrew, Hindi and the Indic languages, Thai, Khmer and more ([languages](#languages))
|
| 104 |
+
- **Handwriting** - handwritten pages and forms (25.2% on the OmniParseBench handwriting tests, see [limitations](#limitations))
|
| 105 |
+
- **Real-world scans** - sideways, upside down, tilted up to 45 degrees, light text on dark ground
|
| 106 |
+
- **Layout** - a box, a label and a reading order for every line and block (headings, lists, tables, captions, footnotes, page headers)
|
| 107 |
+
- **Digital PDFs** - reads the text layer in any script, and OCRs only what is missing
|
| 108 |
+
- **Small** - ONNX Runtime, no PyTorch, no GPU
|
| 109 |
|
| 110 |
Indra OCR is named for [Indra](https://en.wikipedia.org/wiki/Indra).
|
| 111 |
|
|
|
|
| 117 |
|
| 118 |
If you have high volume workloads, we offer a batch processing service that can handle 1B+ pages a day.
|
| 119 |
|
| 120 |
+
Get started with **$5 in free credits** - [sign up](https://www.datalab.to/?utm_source=hf-indra-ocr) - or try Chandra in our [public playground](https://www.datalab.to/playground?utm_source=hf-indra-ocr).
|
| 121 |
|
| 122 |
## Quickstart
|
| 123 |
|
|
|
|
| 131 |
indra-ocr-viewer # local web viewer on http://localhost:8765
|
| 132 |
```
|
| 133 |
|
| 134 |
+
The first run downloads the models (about 76 MB) from [Hugging Face](https://huggingface.co/datalab-to/indra-ocr).
|
| 135 |
|
| 136 |
## Examples
|
| 137 |
|
|
|
|
| 139 |
|
| 140 |
<table>
|
| 141 |
<tr>
|
| 142 |
+
<td width="50%"><img src="assets/examples/handwriting_letter.png"/><br/><sub>A handwritten letter in cursive: Indra OCR finds every line and reads the body of the letter.</sub></td>
|
| 143 |
+
<td width="50%"><img src="assets/examples/korean_letter.png"/><br/><sub>A scanned Korean letter: each line goes to the recognizer for its script.</sub></td>
|
| 144 |
</tr>
|
| 145 |
</table>
|
| 146 |
|
|
|
|
| 153 |
|
| 154 |
# Commercial usage
|
| 155 |
|
| 156 |
+
This code is Apache 2.0, and our model weights use a modified OpenRAIL-M license (free for research, personal use, and startups under $20M funding/revenue, cannot be used competitively with our API). To remove the OpenRAIL license requirements, or for broader commercial licensing, visit our pricing page [here](https://www.datalab.to/pricing?utm_source=hf-indra-ocr).
|
| 157 |
|
| 158 |
# Installation
|
| 159 |
|
|
|
|
| 161 |
pip install indra-ocr
|
| 162 |
```
|
| 163 |
|
| 164 |
+
The default models are about 76 MB: 30 MB of networks and 46 MB of language models for unsure lines. The main recognizer, `rec.onnx` (Latin script), has about 1.25M parameters, and all default models together have 7.3M (the optional math models are extra).
|
| 165 |
+
|
| 166 |
+
For the latest code from GitHub instead: `pip install git+https://github.com/datalab-to/indra.git`. To let the viewer compare with Tesseract, install `pip install "indra-ocr[tesseract]"` and a Tesseract binary.
|
| 167 |
+
|
| 168 |
+
Python 3.10 or newer, tested on Linux (x86_64 and aarch64, Python 3.10 to 3.13) and macOS (Apple silicon). It installs ONNX Runtime, OpenCV and pypdfium2, and no PyTorch. The models download from Hugging Face on the first run and are cached. To use a local copy, set `INDRA_OCR_MODEL_DIR` or pass `--model-dir`.
|
| 169 |
|
| 170 |
# Usage
|
| 171 |
|
|
|
|
| 186 |
- `--out DIR`: write one file per input (`.md`, `.txt` or `.jsonl`)
|
| 187 |
- `--format [md|text|json]`: output format (default: md)
|
| 188 |
- `--mode [auto|ocr|text]`: `auto` reads the text layer where it passes the checks and OCRs elsewhere (default). `ocr` never reads the text layer. `text` uses the text layer even when the checks fail
|
|
|
|
| 189 |
- `--no-image-ocr`: on text-layer pages, do not OCR text inside images
|
| 190 |
- `--cores N`: cores to use, one worker process each (default: all usable cores)
|
| 191 |
- `--dpi`: render resolution for PDFs (default: 200)
|
|
|
|
| 211 |
page.lines # [Line(box, text, conf)] in reading order
|
| 212 |
```
|
| 213 |
|
| 214 |
+
An image file works the same way as a PDF (PNG, JPEG, TIFF, BMP, WebP; one page per TIFF frame). For an image already in memory, pass a grayscale `uint8` numpy array to `conv.ocr`:
|
| 215 |
+
|
| 216 |
+
```python
|
| 217 |
+
import cv2
|
| 218 |
+
import indra_ocr
|
| 219 |
+
|
| 220 |
+
conv = indra_ocr.load(threads=4)
|
| 221 |
+
for i, page in conv.convert("scan.png"): # an image file
|
| 222 |
+
print(page.text)
|
| 223 |
+
|
| 224 |
+
gray = cv2.cvtColor(cv2.imread("photo.jpg"), cv2.COLOR_BGR2GRAY)
|
| 225 |
+
page = conv.ocr(gray) # an image in memory
|
| 226 |
+
print(page.markdown)
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
Runnable examples: [`examples/ocr_image.py`](https://github.com/datalab-to/indra/blob/main/examples/ocr_image.py) (one image to markdown, text or JSON with boxes) and [`examples/quickstart.ipynb`](https://github.com/datalab-to/indra/blob/main/examples/quickstart.ipynb).
|
| 230 |
+
|
| 231 |
For many pages or files, `convert_many` runs one single-threaded worker process per core, one page per task, and returns results in input order:
|
| 232 |
|
| 233 |
```python
|
|
|
|
| 243 |
|
| 244 |
Without the `if __name__ == "__main__":` guard (needed on macOS and Windows), `convert_many` warns and reads everything in one process.
|
| 245 |
|
| 246 |
+
`indra_ocr.load` takes `path` (model folder), `threads`, `dpi`, `mode`, `image_ocr`, `furniture` and `math`. `conv.convert` takes `max_pages` and `password`.
|
| 247 |
|
| 248 |
## Viewer
|
| 249 |
|
|
|
|
| 263 |
- `blocks`: layout blocks in reading order, `{"label", "bbox", "text"}`
|
| 264 |
- `source`: `text` (PDF text layer), `ocr`, `hybrid` (text layer + OCR of text inside images) or `error`
|
| 265 |
- `rotation`, `skew`: the quarter or half turn applied (degrees), and the small tilt straightened
|
| 266 |
+
- `vertical`: the page is set in vertical columns (Chinese, Japanese): it was read turned a quarter turn, and its boxes are on the page as it is
|
| 267 |
- `timings`: per-step milliseconds, with `total_ms`
|
| 268 |
- `note`: why the page took its path
|
| 269 |
|
|
|
|
| 271 |
|
| 272 |
# Languages
|
| 273 |
|
| 274 |
+
**OCR (scans and images):** we measured 95 languages on held-out printed pages: 83 read at character F1 0.90 or higher, and 67 at 0.95 or higher. Four recognizers, and a line classifier that sends each line to one of them:
|
| 275 |
+
|
| 276 |
+
- `rec.onnx`: Latin (about 50 languages, with the letters of Hausa, Fula, Akan, Azerbaijani and Uzbek and the tone marks of Vietnamese and Yoruba), Cyrillic, Greek, and handwriting in Latin script.
|
| 277 |
+
- `rec_cjk.onnx`: Chinese (simplified and traditional), Japanese (kana and kanji), Korean.
|
| 278 |
+
- `rec_rtl.onnx`: Arabic, Persian, Urdu, Pashto, Kurdish, Hebrew. Lines come out in logical order, and a right-to-left page reads its right column first.
|
| 279 |
+
- `rec_world.onnx`: Devanagari (Hindi, Marathi, Nepali), Bengali, Tamil, Telugu, Kannada, Malayalam, Gujarati, Gurmukhi, Odia, Thai, Lao, Khmer, Myanmar, Sinhala, Georgian, Armenian, Ethiopic.
|
| 280 |
+
|
| 281 |
+
When the classifier is not sure of a line, the main recognizer reads it too, and the more confident reading wins.
|
| 282 |
+
|
| 283 |
+
OmniParseBench, per script (tests in parentheses):
|
| 284 |
+
|
| 285 |
+
| Script | Score | Script | Score |
|
| 286 |
+
|---|---|---|---|
|
| 287 |
+
| Latin (9,406) | 61.6 | Thai (39) | 87.2 |
|
| 288 |
+
| Chinese (136) | 64.0 | Lao (52) | 96.2 |
|
| 289 |
+
| Korean (24) | 79.2 | Khmer (34) | 70.6 |
|
| 290 |
+
| Japanese kana (19) | 57.9 | Tamil (25) | 84.0 |
|
| 291 |
+
| Devanagari (23) | 69.6 | Telugu (33) | 87.9 |
|
| 292 |
+
| Bengali (40) | 77.5 | Kannada (48) | 93.8 |
|
| 293 |
+
| Arabic (13) | 69.2 | Malayalam (40) | 65.0 |
|
| 294 |
+
| Hebrew (30) | 80.0 | Gujarati (15) | 80.0 |
|
| 295 |
+
| Georgian (14) | 100 | Gurmukhi (31) | 64.5 |
|
| 296 |
+
| Armenian (60) | 100 | Ethiopic (43) | 100 |
|
| 297 |
+
|
| 298 |
+
Most scripts have few tests, so one test moves a score by 2 to 8 points. On [OmniDocBench](https://github.com/opendatalab/OmniDocBench) v1.5 (OCR only, 1,651 pages, our run without the formula metric), the text edit distance is 0.114 on English pages and 0.237 on simplified Chinese pages (lower is better), and table TEDS is 0.47.
|
| 299 |
+
|
| 300 |
+
**Vertical text.** Chinese and Japanese pages set in vertical columns are read turned a quarter turn, so each column is a line for the CJK recognizer. Scans are found by the orientation model, digital PDFs by their text layer. `page.vertical` is set, and boxes are on the page as it is.
|
| 301 |
|
| 302 |
**Text layer (digital PDFs): any script.** We checked text mode on 1,125 pages from 75 language families. On pages whose layer passes the checks, Indra OCR keeps at least 98% of the layer's characters in every family, including Arabic, Hebrew, Persian, Urdu, Thai, Khmer, Lao, Myanmar, Georgian, Armenian, Ethiopic, the Indic scripts, Chinese, Japanese and Korean. Right-to-left lines keep their right-to-left order.
|
| 303 |
|
|
|
|
| 306 |
Indra OCR is built for speed on clean print. It is not the right tool for:
|
| 307 |
|
| 308 |
- **Complex tables.** Tables with merged or spanning cells, cell text that wraps over several lines, nested headers, or no ruling lines can come out with cells in the wrong rows or columns. Simple grid tables read well.
|
| 309 |
+
- **Handwriting.** Handwritten pages read, but not well: 25.2% on the OmniParseBench handwriting tests, and about a third of the words on held-out handwritten pages. Cursive and faint pencil read worst.
|
| 310 |
+
- **Scripts outside the OCR list.** Syriac, Tibetan, Mongolian, Santali, Meitei and other scripts not listed under [Languages](#languages) work only through a digital PDF's text layer. Khmer and Malayalam OCR are fair (65 to 71 on OmniParseBench). Written Cantonese characters (嘅 咗 冇) are not in the Chinese recognizer.
|
| 311 |
+
- **Latin languages with many diacritics.** Some of them (Kurmanji, Czech, Lithuanian, Icelandic, Turkish, Slovak) read less well: the recognizer sometimes writes a close diacritic instead of the right one (ñ for ň, ú for ů, é for ė). English, French, German and Spanish are not affected.
|
| 312 |
+
- **Degraded scans.** Old, faded or low-resolution scans read poorly (29.5% on the OmniParseBench degraded-scan tests).
|
| 313 |
|
| 314 |
Also:
|
| 315 |
|
| 316 |
- Math comes out as plain text unless `--math` is on (see [Math](#math)).
|
| 317 |
+
- Vertical pages read their columns right to left and their tiers top to bottom; a newspaper whose articles wind across tiers can come out in the wrong article order. Vertical scans read less well than horizontal ones.
|
| 318 |
- Very wide, banner-shaped pages read poorly.
|
| 319 |
- Labels inside engineering drawings often come out as small tables.
|
| 320 |
- Pages above 100 megapixels at 200 dpi render at a lower dpi, so small text on them can be lost.
|
|
|
|
| 321 |
|
| 322 |
For these documents, [Chandra on Datalab](https://www.datalab.to/?utm_source=hf-indra-ocr) is the accurate option.
|
| 323 |
|
|
|
|
| 329 |
|
| 330 |
| | headline | text | tables | layout | math tests |
|
| 331 |
|---|---|---|---|---|---|
|
| 332 |
+
| Indra OCR | 66.7 | 46.7 | 61.1 | 92.2 | 14.0 |
|
| 333 |
+
| Indra OCR `--math` | **71.4** | **62.7** | 59.6 | 92.0 | **55.8** |
|
| 334 |
| PaddleOCR PP-StructureV3 | 58.4 | 55.6 | 47.8 | 71.7 | – |
|
| 335 |
|
| 336 |
- With `--math`, Indra OCR is ahead of PaddleOCR's PP-StructureV3 on the headline, text, tables and layout. Without it, PP-StructureV3 leads on text.
|
| 337 |
- Tables lose 1.5 points: numbers in some table cells are read as math.
|
| 338 |
+
- `--math` is slower. On x86, one page at a time on 4 vCPUs in auto mode, the median page takes 357 ms with `--math` and 212 ms without. With one single-threaded worker per core, throughput is about 30% lower on 4 cores and 38% lower on 32 (measured in one container on 300 OmniParseBench pages).
|
|
|
|
|
|
|
| 339 |
|
| 340 |
The math models download only when `--math` is on.
|
| 341 |
|
|
|
|
| 349 |
|
| 350 |
| engine | headline | text | tables | layout | median ms / page |
|
| 351 |
|---|---|---|---|---|---|
|
| 352 |
+
| Indra OCR (auto: text layer + OCR) | 66.7 | 46.7 | **61.1** | **92.2** | **212** |
|
| 353 |
+
| Indra OCR (OCR only)‡ | 61.2 | 40.7 | 52.7 | 90.3 | 344 |
|
| 354 |
+
| Indra OCR `--math` (auto) | **71.4** | **62.7** | 59.6 | 92.0 | 357 |
|
| 355 |
| PaddleOCR PP-OCRv6 small, text models only (RapidOCR) | – | 35.8 | 0.0 | – | 2,685 |
|
| 356 |
| PaddleOCR PP-StructureV3 (2,918 pages\*) | 58.4 | 55.6 | 47.8 | 71.7 | 40,958 |
|
| 357 |
| Tesseract 5 (our run, Latin model) | – | 19.3 | 0.0 | – | 5,496 |
|
| 358 |
|
| 359 |
+
- Indra OCR's accuracy comes from the benchmark's own Indra OCR adapter and scorer (omni-parse-bench 1.0.0rc1, dataset revision 961c0f89), as on the OmniParseBench leaderboard. ‡The OCR-only row and the other engines come from our runs of the same pages and scorer. The median ms column comes from the x86 run below.
|
| 360 |
- The PP-OCR text models and Tesseract output lines, not tables or layout blocks, so their table scores are 0 and their layout family is not scored.
|
| 361 |
+
- PP-StructureV3 is PaddleOCR's full document pipeline (layout, tables, formulas). Without `--math`, it reads text better than Indra OCR (55.6 vs 46.7). With `--math`, Indra OCR is ahead on text too (62.7). It takes about 190 times as long per page as Indra OCR's default mode. \*One of its 150 shards stalled for 6 hours on its first page, so its row leaves out 19 pages.
|
| 362 |
+
- Faster settings exist, but we did not score their accuracy. Tesseract with the `eng` model and 1 thread takes 3.4 s a page (6.1 s as run). PP-StructureV3 without formula, seal and chart recognition, unwarping and orientation, and with its mobile OCR models, takes 10.5 s a page. Indra OCR is still 16-50x faster per page.
|
| 363 |
- The OmniParseBench leaderboard's own Tesseract run scores 17.6 on text.
|
| 364 |
+
- Median latency varies by about 15% between runs of the same code, so compare engines within one run. The Indra OCR rows come from one run. The other engines ran earlier, on the same container type and pages.
|
| 365 |
|
| 366 |
+
**Chinese** (136 OmniParseBench Chinese tests): Indra OCR 64.0, PaddleOCR PP-OCRv5 mobile Chinese text models 65.4, PP-StructureV3 68.4.
|
| 367 |
|
| 368 |
## olmOCR-bench
|
| 369 |
|
|
|
|
| 381 |
|
| 382 |
The CLI and `convert_many` run one single-threaded worker process per usable core, one page per task, so a single long PDF also uses every core. `--cores` limits it.
|
| 383 |
|
| 384 |
+
Pages per second on x86 (AMD EPYC 9004 Genoa, 34 cores, no GPU), on the same 300 OmniParseBench pages, with one single-threaded worker per core, OCR mode and default settings. The other engines ran once on the same machine type and pages.
|
| 385 |
|
| 386 |
| engine | 4 cores | 8 cores | 16 cores | 32 cores |
|
| 387 |
|---|---|---|---|---|
|
| 388 |
+
| Indra OCR | **6.2** | **11.9** | **23.7** | **43.9** |
|
|
|
|
| 389 |
| PaddleOCR PP-OCRv6 small, text models only (RapidOCR) | 0.65 | 1.24 | 2.42 | 4.28 |
|
| 390 |
| Tesseract 5 | 0.78 | 1.37 | 2.27 | 2.92 |
|
| 391 |
| PaddleOCR PP-StructureV3\* | ≤ 0.022 | ≤ 0.044 | ≤ 0.089 | ≤ 0.18 |
|
| 392 |
|
| 393 |
+
At 32 cores, Indra OCR is 10x PaddleOCR's PP-OCR text models and 15x Tesseract. \*PP-StructureV3 ran a time-capped subset of other OmniParseBench pages in an earlier run, so its numbers are upper bounds.
|
| 394 |
+
|
| 395 |
+
Throughput depends on the CPU: on other x86 container types we measured 25 to 51 pages per second at 32 cores.
|
| 396 |
|
| 397 |
+
Model loading and one warm-up page per worker are not timed.
|
| 398 |
|
| 399 |
## Reproducing
|
| 400 |
|
| 401 |
```shell
|
| 402 |
+
git clone https://github.com/datalab-to/indra.git && cd indra
|
| 403 |
+
pip install indra-ocr 'omni-parse-bench[benchmark]'
|
| 404 |
python bench/opb_indra.py --out runs/opb_auto --mode auto --procs 8
|
| 405 |
```
|
| 406 |
|
| 407 |
+
Each page runs in a single-threaded worker process, page headers and footers kept. `--mode ocr` gives the OCR-only row, `--math` the `--math` row, `--suites` scores only the listed suites, `--limit N` scores the first N pages, and `--models` points at a local model folder. The run writes `summary.json` (the benchmark's own summary, plus median and p90 ms per page) and `pages.jsonl` (per page: time, source, tests passed). The tables above come from our x86 harness, which gives each page 4 threads. This script gives each page one thread, so its times differ, and its scores can differ by a few tenths of a point.
|
| 408 |
|
| 409 |
# Credits
|
| 410 |
|
assets/examples/{chinese_essay.png → handwriting_letter.png}
RENAMED
|
File without changes
|
assets/examples/{multi_column.png → korean_letter.png}
RENAMED
|
File without changes
|
assets/speed_score.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
assets/throughput.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
config.json
CHANGED
|
@@ -5,16 +5,21 @@
|
|
| 5 |
"framework": "onnxruntime",
|
| 6 |
"files": [
|
| 7 |
"det.onnx",
|
|
|
|
|
|
|
|
|
|
| 8 |
"math_dec_init.onnx",
|
| 9 |
"math_dec_step.onnx",
|
| 10 |
"math_enc.onnx",
|
| 11 |
"mathcls.onnx",
|
|
|
|
| 12 |
"order.onnx",
|
| 13 |
"orient.onnx",
|
| 14 |
"rec.onnx",
|
| 15 |
"rec_cjk.onnx",
|
| 16 |
-
"
|
| 17 |
-
"
|
|
|
|
| 18 |
],
|
| 19 |
-
"note": "Indra OCR runs the .onnx files with onnxruntime (pip install indra-ocr). model.safetensors holds the float weights of rec.onnx, the Latin-script
|
| 20 |
}
|
|
|
|
| 5 |
"framework": "onnxruntime",
|
| 6 |
"files": [
|
| 7 |
"det.onnx",
|
| 8 |
+
"lm.npz",
|
| 9 |
+
"lm_cjk.npz",
|
| 10 |
+
"lm_world.npz",
|
| 11 |
"math_dec_init.onnx",
|
| 12 |
"math_dec_step.onnx",
|
| 13 |
"math_enc.onnx",
|
| 14 |
"mathcls.onnx",
|
| 15 |
+
"meta.json",
|
| 16 |
"order.onnx",
|
| 17 |
"orient.onnx",
|
| 18 |
"rec.onnx",
|
| 19 |
"rec_cjk.onnx",
|
| 20 |
+
"rec_rtl.onnx",
|
| 21 |
+
"rec_world.onnx",
|
| 22 |
+
"script.onnx"
|
| 23 |
],
|
| 24 |
+
"note": "Indra OCR runs the .onnx files with onnxruntime (pip install indra-ocr). The .npz files are n-gram language models for unsure lines. model.safetensors holds the float weights of rec.onnx, the Latin-script recognizer, for the Hub parameter count; the package does not use it."
|
| 25 |
}
|
det.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 389948
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2bd4cba23e9c328cf7ec824634e423e191a2c6aacbbf35c62bd79dd70f62f59
|
| 3 |
size 389948
|
lm.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c0fb618a363a0acdd05d4f5b0edd9e8146d2d990541b87f6130bbfe17cea58d
|
| 3 |
+
size 15695957
|
lm_cjk.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d64f13f4f90f4e529bd63340c6df76238d007feaef2abb903d8cd28d92bc2f3
|
| 3 |
+
size 18955160
|
lm_world.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34df5e74a2fcbb9cf5e7f360a559375ffa2e04d2d2943a42308c177bcb444d5d
|
| 3 |
+
size 11641215
|
meta.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e9b0b74c12176516548664a46429758ac7c1088dd43524534fc7272e221a6762
|
| 3 |
+
size 5013304
|
order.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2973138
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a42db2e8b536ad3d84045a4b7f9b0a72667cf8be4aa02d63f7b38004719fb180
|
| 3 |
size 2973138
|
orient.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:20eaf670f55a7cf9facfe1bdd6c7b8e40be75bbf4d48a3df43f66aa3bbd874fd
|
| 3 |
+
size 371802
|
rec.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:475972a2710be4a3cbfeb2bc7f3624ffd563de07de42476fc7a290d4e1ece484
|
| 3 |
+
size 5042161
|
rec_cjk.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a035516a17e62cdf33a4fe2d88077654cb8841cff024685cdef4e351694ef50
|
| 3 |
+
size 10176018
|
assets/examples/rotated_letter.png → rec_rtl.onnx
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:468796bd684486a8388c30c8b4ed2a26e3eeb1f8ff02831c24c2e12c79a2a834
|
| 3 |
+
size 4812710
|
assets/examples/table_pmc.png → rec_world.onnx
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8d1e59f21b04966f179d2d2d8e22b230d22110b3f89855bbbf2624a58c40043
|
| 3 |
+
size 5627990
|
script.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6ce4e926e19c243faaf37bd46880398bf2cb4ae56a29e1177a3b017c1280e36
|
| 3 |
+
size 191630
|