Tools,

MiniCPM-OCR 1.0 on a Mac, tested on a book scan

1,954

of 1,955 words, 10 pages in 16 s

Get the script

Whole pages: top score, fastest run

Four ways to run it on the same 10 scanned book pages, on a Mac with an M5 Max.

Words found of 1,955, and time
Way Words Time
Whole pages, DSpark on 1,954 16 s
Whole pages, DSpark off 1,954 22 s
SDK on the PDF 1,954 64 s
SDK on the page JPEGs 1,953 84 s

The model ran on the Mac GPU in llama.cpp. The SDK adds a layout model that runs on the CPU.

Every run missed the same word: course--" lost its closing quote mark.

Step 1: start llama-server

curl -LO https://github.com/ggml-org/llama.cpp/releases/download/b11901/llama-b11901-bin-macos-arm64.tar.gz
tar xzf llama-b11901-bin-macos-arm64.tar.gz
H=https://huggingface.co/openbmb
curl -LO $H/MiniCPM-OCR-1.0-gguf/resolve/main/MiniCPM-OCR-1_0-Q8_0.gguf
curl -LO $H/MiniCPM-OCR-1.0-gguf/resolve/main/mmproj-model-f16-4x.gguf
curl -LO $H/MiniCPM-OCR-1.0-DSpark-gguf/resolve/main/dspark-MiniCPM-OCR-1_0-Q8_0.gguf
llama-b11901/llama-server \
  --model MiniCPM-OCR-1_0-Q8_0.gguf \
  --mmproj mmproj-model-f16-4x.gguf \
  --model-draft dspark-MiniCPM-OCR-1_0-Q8_0.gguf \
  --spec-type draft-dspark --spec-draft-n-max 15 --gpu-layers-draft 99 \
  --n-gpu-layers 99 --flash-attn on --ctx-size 8192 --parallel 1 \
  --threads 2 --host 127.0.0.1 --port 18499 \
  --alias minicpm-ocr --jinja --reasoning off

The draft model and the three flags after it turn on DSpark. Drop those four to run without it.

Step 2: send each page

Standard library only. It sends each page with the prompt the SDK uses for text blocks. Or download ocr_page.py.

"""MiniCPM-OCR 1.0 on whole pages via llama-server: python3 ocr_page.py *.jpg > book.txt"""

import base64
import json
import sys
import urllib.request

URL = "http://127.0.0.1:18499/v1/chat/completions"


def ask(path):
    with open(path, "rb") as f:
        b64 = base64.b64encode(f.read()).decode()
    body = {
        "model": "minicpm-ocr",
        "temperature": 0,
        "top_k": 1,
        "max_tokens": 4096,
        "messages": [
            {
                "role": "user",
                "content": [
                    {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}},
                    {"type": "text", "text": "Text Recognition:"},
                ],
            }
        ],
    }
    req = urllib.request.Request(URL, json.dumps(body).encode(), {"Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=600) as r:
        return json.load(r)


if __name__ == "__main__":
    for p in sys.argv[1:]:
        print(ask(p)["choices"][0]["message"]["content"])
python3 ocr_page.py page-*.jpg > book.txt

DSpark: same words, 22 s to 16 s

Whole pages, 10 pages
DSpark Writing speed Time
Off 210 tokens/s 22 s
On 461 tokens/s 16 s

The text was the same byte for byte. DSpark speeds up writing the text, not reading the page image, so each page gains less than writing does.

The SDK: layout first, then the model

pip install "minicpm-ocr[all]==1.0.5" paddlepaddle==3.3.1
export PADDLE_PDX_CPU_NUM_THREADS=2
minicpmvocr parse scan.pdf --backend llamacpp \
  --server-url http://127.0.0.1:18499 --model minicpm-ocr \
  --device cpu --workers 1 --set engine.max_model_len=8192 \
  --set pipeline.queue_mode=serial \
  --set pipeline.overlap_layout=false \
  --output book.md --json

It finds the blocks on each page with PP-DocLayoutV3, cuts them out, and sends each block to the same llama-server.

Where the time went, our PDF
Step Time
Layout model, CPU, 2 threads 37 s
MiniCPM-OCR on 59 blocks 20 s
Whole run 64 s

What each way gives you

Output Whole pages SDK
Running heads Kept as plain lines 5 dropped, 5 became ## headings
Page breaks None <!-- page-break --> lines
Boxes and labels None JSON with --json

The JSON gives each block a label, a box and its text. Our pages had four labels: text, header, number and paragraph_title.

Four things that tripped us

Fastest top score on our scan

Same 10 pages, words found of 1,955
Tool Words Time
MiniCPM-OCR 1.0, whole pages 1,954 16 s
olmOCR-2 7B 1,954 77 s
LightOnOCR-2 1B 1,954 72 s
GLM-OCR in MLX 1,953 39 s
PaddleOCR-VL 1.6 4-bit in MLX 1,942 20 s
Our Actor's code 1,879 38 s
Tesseract 5.5.4 1,878 34 s

The other models ran on earlier days, with other jobs on the Mac, so their times are rough. Tesseract and the Actor ran today.

The scan is 10 proofread pages from two public domain books on Wikisource: 1,955 words. The score is true words found in order.

How we ran it
  • A Mac with Apple M5 Max. llama.cpp b11901, the version the MiniCPM-OCR llama.cpp guide names, with Metal.
  • Files: Q8_0 model 812 MB, vision file 901 MB, DSpark draft 327 MB.
  • One warm-up request on a smaller copy of page 1 before each timed run. A repeat of the DSpark run took 16.3 s, same text.
  • SDK: minicpm-ocr 1.0.5, paddlex 3.7.2, paddlepaddle 3.3.1 (CPU wheel), Python 3.12.12. Its OMP, Paddle and OpenCV threads set to 2.
  • Every run at low priority, one at a time, while other jobs ran.
  • The JPEG run also lost a dash: Court-- became Court-.
  • Licenses: the model, GGUF and DSpark cards, the MiniCPM-OCR repo and the minicpm-ocr package say Apache-2.0, as does PP-DocLayoutV3. llama.cpp is MIT. We only ran them.

Scanned pages to text, no install

Run it yourself. Our Apify Actor turns a scanned PDF into Markdown or text. $0.006 a scanned page. Its code found 1,879 of these 1,955 words.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free

Questions people ask

What is MiniCPM-OCR 1.0?

A 1.3B OCR model from OpenBMB, the team behind MiniCPM-V. The card lists text, tables, formulas, charts and seals. We tested book text.

Does MiniCPM-OCR run on a Mac?

Yes. The GGUF files ran on the Mac GPU in llama.cpp b11901. Our 10 book pages took 16 s.

Do I need the SDK?

Not for plain text. Whole pages found the same 1,954 words, 4 times faster. The SDK adds layout labels, boxes and Markdown.

What is DSpark?

A small draft model that guesses the next tokens for the main model to check. Our text did not change, and decoding ran 2.2 times faster.

Can I use it in a business?

The model card says the weights, code and documentation are under the Apache License 2.0. We found no other terms on the cards.