[PR #24996] fix: ocr gpu memory usage #18029

Open
opened 2026-02-05 16:31:27 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/24996
Author: @bb159
Created: 1/3/2026
Status: 🔄 Open

Base: mainHead: fix-ocr-gpu


📝 Commits (3)

📊 Changes

2 files changed (+67 additions, -12 deletions)

View changed files

📝 machine-learning/immich_ml/models/ocr/detection.py (+21 -2)
📝 machine-learning/immich_ml/models/ocr/recognition.py (+46 -10)

📄 Description

Description

This PR fixes excessive GPU memory usage in the OCR pipeline.

  • In text recognition, extremely wide text crops could cause batch-level padding to grow unbounded, leading to steadily increasing GPU memory usage. The fix processes these extreme crops separately while keeping normal recognition behavior unchanged.
  • In text detection, a missing image shape normalization step was added to ensure consistent input dimensions.

These changes stabilize GPU memory usage while preserving OCR accuracy.

Fixes #23462


How Has This Been Tested?

  • OCR on images with a large number of detected text boxes.
  • OCR on images containing very long horizontal text.
  • Verified stable GPU memory usage compared to previous behavior.

Tested locally using the default Immich OCR configuration with ONNX Runtime.


Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code

Please describe to which degree, if any, an LLM was used in creating this pull request.

An LLM was used as a general coding and reasoning assistant during development.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/24996 **Author:** [@bb159](https://github.com/bb159) **Created:** 1/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-ocr-gpu` --- ### 📝 Commits (3) - [`646b466`](https://github.com/immich-app/immich/commit/646b4664021776901447ebb2e68464672b2ef754) ``` - [`40e0bfc`](https://github.com/immich-app/immich/commit/40e0bfc8827744ea43e90b49b9ff22433156ef3b) 无代码更改,提交空白 - [`dfa934d`](https://github.com/immich-app/immich/commit/dfa934d3b7d3d93671bc95660051cdead8f5f404) Merge branch 'main' into fix-ocr-gpu ### 📊 Changes **2 files changed** (+67 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `machine-learning/immich_ml/models/ocr/detection.py` (+21 -2) 📝 `machine-learning/immich_ml/models/ocr/recognition.py` (+46 -10) </details> ### 📄 Description ## Description This PR fixes excessive GPU memory usage in the OCR pipeline. - In **text recognition**, extremely wide text crops could cause batch-level padding to grow unbounded, leading to steadily increasing GPU memory usage. The fix processes these extreme crops separately while keeping normal recognition behavior unchanged. - In **text detection**, a missing image shape normalization step was added to ensure consistent input dimensions. These changes stabilize GPU memory usage while preserving OCR accuracy. Fixes #23462 --- ## How Has This Been Tested? - OCR on images with a large number of detected text boxes. - OCR on images containing very long horizontal text. - Verified stable GPU memory usage compared to previous behavior. Tested locally using the default Immich OCR configuration with ONNX Runtime. --- ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation if applicable - [x] I have no unrelated changes in the PR. - [x] I have confirmed that any new dependencies are strictly necessary. - [ ] I have written tests for new code (if applicable) - [x] I have followed naming conventions/patterns in the surrounding code --- ## Please describe to which degree, if any, an LLM was used in creating this pull request. An LLM was used as a general coding and reasoning assistant during development. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 16:31:27 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#18029