#18195·PaddleOCR

PP-OCRv5: use_textline_orientation=True corrupts bold/large text lines on GPU (CPU unaffected, resolution-dependent)

Author: marcosmarf27Created Jun 22, 2026Updated Sep 22, 2026
Labelsstale

Description

With use_textline_orientation=True on GPU, PP-OCRv5 corrupts bold / large printed text lines: the line is recognized as a few scattered characters with low confidence, while every other (regular-weight) line on the same page is fine.

The exact same image, model and settings on CPU (device="cpu") reads the same lines correctly. Setting use_textline_orientation=False on GPU also fixes it.

The failure is resolution dependent and non‑monotonic: rasterizing the same A4 page at different DPIs flips between broken and correct on GPU.

This is easy to miss because only a few lines per page are affected, so the page's mean confidence stays high.

Example

A bold, perfectly legible line (here shown with placeholder text — real content redacted) such as 1) ALPHA BRAVO CHARLIE DELTA ECHO FOXTROT JUNIOR is returned as:

device use_textline_orientation output confidence
GPU (L4) True R TO I O I O (scattered garbage) ~0.34
GPU (L4) False 1) ALPHA BRAVO CHARLIE DELTA ECHO FOXTROT JUNIOR ~0.98
CPU True or False 1) ALPHA BRAVO CHARLIE DELTA ECHO FOXTROT JUNIOR ~0.98

Resolution dependence (GPU, use_textline_orientation=True)

Same A4 page rasterized at different DPIs and fed to predict() on GPU — fraction of the bold lines recognized correctly:

render DPI 150 170 180 200 220 240 250 270 300
GPU ok? ❌ ✅ ✅ ✅ ⚠️ ❌ ✅ ✅ ❌
CPU ok? ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅

CPU is robust at every DPI; GPU is erratic. This points to the textline‑orientation classifier mis‑classifying bold/large lines as rotated (and flipping them before recognition) on the GPU code path.

Reproduction

reproduce_textline_orientation_gpu.py (attached below) generates a synthetic A4 page with a few bold uppercase lines and runs predict() with the classifier on and off:

bash
python reproduce_textline_orientation_gpu.py gpu   # bold lines garbled when on
python reproduce_textline_orientation_gpu.py cpu   # always correct

Note: crisp synthetic text may not always trigger it; it reproduces reliably on rasterized scanned document pages (the table above is from real scanned A4 pages rendered at the listed DPIs). I can share a redacted sample image if helpful.

Environment

  • PaddleOCR 3.6.0 (also reproduced on 3.4.1)
  • paddlepaddle‑gpu 3.x, CUDA, NVIDIA L4 (24 GB)
  • Models: PP-OCRv5_server_det + latin_PP-OCRv5_mobile_rec
  • use_doc_orientation_classify=False, use_doc_unwarping=False
  • Linux, Python 3.11

Expected vs actual

  • Expected: GPU recognizes bold/large lines the same as CPU.
  • Actual: with use_textline_orientation=True, GPU returns low‑confidence garbage for bold/large lines, varying with render DPI.

Workaround

use_textline_orientation=False eliminates the problem on GPU with no observed downside for upright document scans.

reproduce_textline_orientation_gpu.py
python
#!/usr/bin/env python3
"""
Minimal reproduction: `use_textline_orientation=True` corrupts BOLD/large printed
text lines on GPU (PP-OCRv5), while the SAME image/model reads correctly on CPU.

Run twice (GPU then CPU), or once on a GPU machine:
    python reproduce_textline_orientation_gpu.py gpu
    python reproduce_textline_orientation_gpu.py cpu

On our NVIDIA L4 (paddleocr 3.6.0, paddlepaddle-gpu 3.x):
  - device=gpu, use_textline_orientation=True  -> bold lines come out as garbage,
    low confidence (e.g. a name line -> "R TO  I O I O", conf ~0.34)
  - device=gpu, use_textline_orientation=False -> correct
  - device=cpu, EITHER setting                 -> correct

The effect is also render-resolution dependent (non-monotonic): the same page
rasterized at different DPIs flips between broken and correct on GPU.
"""
import sys
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from paddleocr import PaddleOCR

DEVICE = sys.argv[1] if len(sys.argv) > 1 else "gpu"

# A serif bold font (Times-like) reproduces best; fall back to default if missing.
BOLD_CANDIDATES = [
    "/usr/share/fonts/truetype/liberation/LiberationSerif-Bold.ttf",
    "/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf",
]
REG_CANDIDATES = [
    "/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf",
    "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf",
]


def _font(paths, size):
    for p in paths:
        try:
            return ImageFont.truetype(p, size)
        except OSError:
            continue
    return ImageFont.load_default()


def make_page():
    """A4 @ ~150 DPI page: regular body + a few BOLD uppercase lines (the trigger)."""
    W, H = 1240, 1754
    im = Image.new("RGB", (W, H), "white")
    d = ImageDraw.Draw(im)
    body = _font(REG_CANDIDATES, 26)
    bold = _font(BOLD_CANDIDATES, 30)
    y = 120
    for ln in [
        "This is regular-weight body text that is recognized correctly in all cases.",
        "The bold uppercase lines further down are the trigger for the GPU issue.",
    ]:
        d.text((110, y), ln, fill="black", font=body); y += 42
    y += 360
    d.text((110, y), "LIST OF WITNESSES:", fill="black", font=bold); y += 80
    for ln in [
        "1) ALPHA BRAVO CHARLIE DELTA ECHO FOXTROT JUNIOR (XX)",
        "2) GOLF HOTEL INDIA JULIET KILO LIMA (XX)",
        "3) MIKE NOVEMBER OSCAR PAPA QUEBEC (XX)",
    ]:
        d.text((150, y), ln, fill="black", font=bold); y += 50
    return im


def run(orientation: bool):
    ocr = PaddleOCR(
        text_detection_model_name="PP-OCRv5_server_det",
        text_recognition_model_name="latin_PP-OCRv5_mobile_rec",
        use_doc_orientation_classify=False,
        use_doc_unwarping=False,
        use_textline_orientation=orientation,
        device=DEVICE,
    )
    res = ocr.predict(np.array(make_page()))[0]
    texts = res.get("rec_texts", [])
    scores = res.get("rec_scores", [])
    print(f"\n--- device={DEVICE}  use_textline_orientation={orientation} ---")
    for t, s in zip(texts, scores):
        if any(k in t.upper() for k in ["WITNESS", "ALPHA", "GOLF", "MIKE"]):
            print(f"  [{s:.3f}] {t!r}")


if __name__ == "__main__":
    for orientation in (True, False):
        run(orientation)