Repository navigation
[Fix] Rename StandardizeImag -> StandardizeImage to fix deepdoc OCR preprocessing (#7316) - #16785
Conversation
…reprocessing (infiniflow#7316) The preprocessing operator class in `deepdoc/vision/operators.py` was defined as `StandardizeImag` (missing the final `e`), but every caller — including `deepdoc/vision/recognizer.py::Recognizer.preprocess` — looks the class up by the canonical string `"StandardizeImage"` via:: op_type = new_op_info.pop("type") # "StandardizeImage" preprocess_ops.append(getattr(operators, op_type)(**new_op_info)) so `getattr(operators, "StandardizeImage")` raised `AttributeError` and the "StandardizeImage" preprocessing step never ran for any image pipeline that used the dynamic dispatch (LayoutLMv3 and friends). This renames the class to match the dispatch key. No public API change — the class is only referenced by name from within `recognizer.py`, and only by the string `"StandardizeImage"`. Also adds `test/unit_test/deepdoc/vision/test_operators_standardize_image.py` with six regression tests: - Pin that the module exposes `StandardizeImage` (contract used by recognizer) - Pin that the legacy misspelled name is gone - Behavioural: mean-std normalization with is_scale=True - Behavioural: is_scale=False skips /255 - Behavioural: norm_type='none' skips mean/std - End-to-end via the same `getattr(operators, "StandardizeImage")` call the recognizer uses, so any future rename or accidental removal will fail loudly with `AttributeError` instead of silently skipping the step.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughFixes a class-name typo in ChangesStandardizeImage typo fix and tests
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/unit_test/deepdoc/vision/test_operators_standardize_image.py`:
- Around line 45-76: The _load_operators_module helper leaves temporary entries
in sys.modules for rag, rag.utils, and rag.utils.lazy_image, which can leak into
later tests. Update the test setup to isolate these stubs by using
mock.patch.dict around the sys.modules injection or by restoring the original
modules after import completes. Keep the change localized to
_load_operators_module so test_operators_standardize_image.py does not affect
other tests that import rag.utils.lazy_image or related modules.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 77b35419-8503-4271-9ef1-2c67c6543ef2
📒 Files selected for processing (2)
deepdoc/vision/operators.pytest/unit_test/deepdoc/vision/test_operators_standardize_image.py
…w#7316 review) CodeRabbit review on infiniflow#16785: the helper that stubs ``rag.utils.lazy_image`` into ``sys.modules`` so we can load ``deepdoc/vision/operators.py`` without the full RAGFlow runtime never restored the pre-test state. A later test that imports the real module would silently get the identity-passthrough stub instead. Move the loader into a ``pytest.fixture`` that snapshots the relevant ``sys.modules`` entries before mutation and restores them in a ``finally`` teardown — including the case where the entry was already populated at fixture entry. Tests now consume the loaded module via the fixture parameter rather than the module-level ``operators`` constant, so the import-time side effect is gone. Verified end-to-end with a temporary sibling probe that walks ``sys.modules`` for ``rag.utils.lazy_image`` and asserts it no longer carries a stub ``ModuleType`` (no ``__file__``/``__loader__``). The probe fails against the pre-fix code and passes against the new fixture — confirming both that the leak existed and that the fixture now closes it. All six standardize-image tests still green. Co-authored-by: Cursor <[email protected]>
|
Addressed in cc7d32a. The I went with a fixture rather than
Verified end-to-end by temporarily reverting the helper to the leaky version and adding a sibling probe that walks All six |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16785 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Friendly bump on this one — it's been clean (CI ✅, review ✅, codecov ✅) since yesterday and there are no open threads. Happy to address any final feedback if anything's been missed. No rush; just flagging in case it got buried in the queue. Thanks! Resolves #7316 |
Fixes #7316.
Problem
deepdoc/vision/operators.pydefines the image-standardize preprocessing op asclass StandardizeImag(missing the finale), but every caller — includingdeepdoc/vision/recognizer.py::Recognizer.preprocess— looks the class up by the canonical string"StandardizeImage"via:So
getattr(operators, "StandardizeImage")raisedAttributeError, and the "StandardizeImage" preprocessing step silently never ran for any image pipeline that used the dynamic dispatch (LayoutLMv3 and friends). The user-visible symptom is that the standardize step is missing entirely from the preprocessing chain, so the model gets un-normalized images.Production fix
That's the entire production change — a one-character class rename. The misnamed
StandardizeImaghad no other references in the codebase (verified viagit grep), so removing it is safe; every caller uses the canonical"StandardizeImage"string and will now resolve correctly.Tests
New
test/unit_test/deepdoc/vision/test_operators_standardize_image.pywith six regression tests, all green locally:The tests:
hasattr(operators, "StandardizeImage")) — this is the exact check the recognizer'sgetattrwould do, so any future regression fails the same way the runtime would.3–5. Behavioural coverage of the three documented code paths:
is_scale=True, norm_type="mean_std",is_scale=False, norm_type="mean_std", andnorm_type="none".getattr(operators, "StandardizeImage")call the recognizer uses, with a real numpy image, so any rename or removal surfaces asAttributeErrorinstead of silently skipping the step.Verified both ways:
'StandardizeImag' → 'StandardizeImage')The test file follows the project's existing pattern (
test/unit_test/deepdoc/parser/test_html_parser.py): load the target module viaimportlib.util.spec_from_file_location, stub the only project-internal import (rag.utils.lazy_image), and assert against the loaded module — no full RAGFlow runtime required.Risk
Very low. The class is renamed; no public Python API was using the misnamed class. The only reference path is the
"StandardizeImage"string inrecognizer.py:270, which now resolves correctly.Out of scope
operators.pyare affected; checked all the others (DecodeImage, NormalizeImage, Permute, etc.) and they all use correct names.recognizer.pyforLinearResize,StandardizeImage,Permute,PadStrideall use the same dispatch path; only theStandardizeImagekey was broken. No other keys need fixing.Made with Cursor