Fix PaddleOCR 2.9+ args, Box Sorting, and pin Transformers (Florence-2 fix) - #349
Conversation
|
@microsoft-github-policy-service agree |
|
Hi Alexey Taymanov (@ataymano), this is the fix for setting up the environment with the latest version of paddleocr (v2.9.1) - Fixed PaddleOCR Initialization: Newer versions of paddleocr have deprecated or removed the max_batch_size, use_gpu, and use_dilation arguments. Passing them was causing a ValueError on startup. I’ve updated the initialization to rely on the default argument parsing, which correctly handles GPU detection automatically. I noticed that filtered_boxes occasionally contained mixed types (dictionaries and raw lists) depending on the detection results, which caused the sorted() function to crash with an AttributeError. I added a safety check to standardize all elements to dictionaries before sorting. I verified these changes on Windows with Python 3.11 and PaddleOCR 2.9.1. The model now loads correctly and performs inference without crashing.
|
|
See #354 |
The crash in your logs is actually coming from the Florence-2 model, not Paddle. The AttributeError: 'NoneType' object... error occurs because recent versions of the Transformers library break the custom model code. I have updated requirements.txt in the PR above to pin the correct version. Quick fix - |
|
I also had to add on the utils.py attn_implementation="eager" on : |
|
Shivaansh Gusain (@ShivaanshGusain) i encounter this issue with your repo, could you help to fix this
|
|
XingdongZeng This crash happens because the custom Florence-2 model code is incompatible with the latest versions of the transformers library. I recently updated the requirements.txt to pin the stable version You can either run the requirements files to install the correct module versions. Or downgrade transformers module to 4.40.0 'pip install transformers==4.40.0' |
|
Can we merge this ? |
|
Jorge (@jomach) I would love to get this merged into the official repository. |
|
Shivaansh Gusain (@ShivaanshGusain) I don't :( ping the repo owners |
There was a problem hiding this comment.
Pull request overview
This PR aims to improve runtime compatibility with newer dependency versions by updating PaddleOCR initialization, making OCR/Yolo box post-processing more robust, and pinning transformers to a known-good version for Florence-2.
Changes:
- Removed deprecated PaddleOCR constructor arguments to avoid startup failures on PaddleOCR 2.9+.
- Added normalization around
filtered_boxesto prevent sorting crashes when mixed element types appear. - Pinned
transformers==4.40.0(and clarified OpenCV/Paddle installation notes) to avoid Florence-2 inference crashes.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| util/utils.py | Updates PaddleOCR init, adjusts BoxAnnotator import, hardens box sorting logic, and modifies get_som_labeled_img output handling. |
| requirements.txt | Pins transformers==4.40.0 and adds guidance/comments around OpenCV and Paddle CPU vs GPU installs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi ahmed-awadallah / Adam (@adamlu123), just checking in on this PR! |


Summary of Changes
This PR addresses two compatibility issues encountered when setting up the environment with recent library versions (specifically PaddleOCR v2.9.1).
Fix PaddleOCR Initialization
Newer versions of
paddleocrhave deprecated/removed arguments likemax_batch_size,use_gpu, anduse_dilationfrom the constructor. Keeping them causes aValueErrorcrash on startup.Change: Updated
PaddleOCR()initialization to rely on default argument parsing, which correctly auto-detects GPU support.Box Sorting
Occasionally,
filtered_boxescontains mixed types (dictionaries and raw lists) depending on the detection results. This causes thesorted()function (line ~435) to crash with anAttributeErrorbecause raw lists do not have keys.Change: Added a safety check loop (
safe_boxes) to ensure all elements infiltered_boxesare standardized dictionaries before sorting.Fix Florence-2 Inference Crash
The current dependency resolution installs a version of transformers (v4.41+) that is incompatible with the custom modeling_florence2.py, causing an AttributeError: 'NoneType' object has no attribute 'shape'. Change: Pinned transformers==4.40.0 in requirements.txt to ensure stability.
Testing