Skip to content

perf(ocr): convert PIL crops with numpy.asarray - #4920

Merged
dolfim-ibm merged 1 commit into
docling-project:mainfrom
quangdungluong:perf/ocr-numpy-asarray
Oct 21, 2026
Merged

dolfim-ibm merged 1 commit into
docling-project:mainfrom
quangdungluong:perf/ocr-numpy-asarray

Conversation

@quangdungluong

Copy link
Copy Markdown
Contributor

Summary

Use numpy.asarray to convert rendered PIL crops in RapidOCR, EasyOCR, and Nemotron OCR. This avoids the explicit owning-array copy made by numpy.array at the crop boundary.

Validation

  • RapidOCR, EasyOCR and Nemotron tests: passed.
  • Ruff and formatting checks passed.

Signed-off-by: quangdungluong <luongquangdung00@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @quangdungluong, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) ocr performance labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 7f9c724489. The analysis read the diff only. It did not run code from this pull request.

The PR replaces numpy.array with numpy.asarray when it converts PIL crops in the RapidOCR, EasyOCR and Nemotron OCR models. The aim is to avoid an extra copy of each crop.

Topic labels added: performance, ocr.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4709 open changes the same code related: Both PRs change the same numpy.array(high_res_image) line in rapid_ocr_model.py. PR 4709 adds page orientation detection and moves that call into a new _read method. The two PRs do different things, but they will conflict when merged.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 7f9c724489. It read the code and did not run it.

The change swaps numpy.array for numpy.asarray in three OCR models. A PIL image exports its pixels as bytes, so the new array may be read-only. The three OCR libraries may write to the array or hand it to torch.from_numpy. I could not read their source here to check.

A maintainer makes the merge decision. This review never approves the pull request.

Comment thread docling/models/stages/ocr/nemotron_ocr_model.py
@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 20, 2026

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dolfim-ibm dolfim-ibm changed the title perf(ocr): avoid redundant copies when converting PIL crops perf(ocr): convert PIL crops with numpy.asarray Oct 21, 2026
@dolfim-ibm
dolfim-ibm merged commit de7a4ea into docling-project:main Oct 21, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) ocr performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants