Fix YOLOv8 .pt inference crashes and improve output handling#526
Fix YOLOv8 .pt inference crashes and improve output handling#526YUVAN0907 wants to merge 6 commits into
.pt inference crashes and improve output handling#526Conversation
Added detailed parameter descriptions to the evaluate method.
Added parameter and return type annotations to the inference method.
Updated docstring for the predict method to clarify parameters and return types.
|
Hi @dpascualhe , I've updated this PR and ensured there is no merge conflicts. This PR fixes YOLOv8 .pt inference crashes and improves output handling. |
|
Hi @YUVAN0907, This issue was already pointed out by me (#449). You can take a brief look at it and its related PR (#495). Thanks! |
Hi @kashtennyson, Thank you for pointing this out and for your work on #495 — I’ve reviewed your PR. From what I understand, your changes mainly handle model loading and normalization (e.g., checkpoint dictionaries, tuple outputs, dtype alignment, etc.), ensuring the model behaves consistently at inference time. In contrast, my PR focuses on a different stage of the pipeline — specifically postprocessing and UI inference handling. In particular, it:
So while both PRs are related to YOLOv8 compatibility, they address different layers of the pipeline (model loading vs. postprocessing). I believe the two approaches are complementary. I’d be happy to align my implementation with your wrapper logic if needed, or refactor parts to better integrate with your changes. If you’re open to it, maybe we can collaborate to consolidate both fixes and present a unified solution for review by @dpascualhe. Thanks again, and looking forward to your thoughts! Best regards, |
Just to add — my changes span both "torch_detection.py" and "yolo.py", whereas your PR primarily focuses on "torch_detection.py". Because of this, I think our approaches cover different parts of the pipeline, and combining them could lead to a more complete and robust solution for YOLOv8 support. Happy to collaborate and align the implementations if you're open to it. |
|
Yes @YUVAN0907, we can definitely collaborate! Currently, I am waiting for a feedback on my pull request from the maintainers. Once I receive that I will get back to you and we can collaborate on the final solution since I am already planning on to add a global support for models in |
|
That sounds great, I appreciate the direction you're taking. @dpascualhe, since both PRs address different parts of YOLOv8 ".pt" support (model loading and postprocessing), combining them could provide a more complete and robust solution. Happy to collaborate and align our implementations based on your feedback so we can integrate this cleanly into the codebase. Best regards, |
|
Hi @YUVAN0907 ! We are about to merge @kashtennyson changes in this regard, plus your PR does too many things at once. I'd recommend open up a new issue if you find any relevant changes to do beyond support for native YOLO models and max_detections (#497 ) handling which are already being addressed. We will close this PR for now, but thanks for your interest! |
|
Hi @dpascualhe, Thank you for the feedback 😄 I understand that the PR covers multiple concerns, and I appreciate the clarification regarding the scope already being handled in #497 and related changes. I’ll break down the remaining relevant improvements (such as postprocessing robustness, bounding box scaling, and ontology handling) into smaller, focused issues/PRs where appropriate. Thanks again for the guidance, and I’ll align future contributions more closely with the project’s structure. Best regards, |

Fix YOLOv8
.ptinference crashes and improve output handlingFixes #525
What this PR does
This PR fixes inference crashes when using native YOLOv8
.ptmodels in the UI and improves output handling for better compatibility.Problem
While testing YOLO models in the UI, inference failed even though the model loaded successfully.
Two common errors were observed:
Before Fix (Error Screenshots)
'Tensor' object has no attribute 'boxes'too many values to unpackRoot Cause
postprocess_detection()assumed the model always returns a torch.Tensor, but YOLOv8 (Ultralytics) models can return:Resultsobject (with.boxes)listortupletorch.TensorOnly the tensor case was handled previously, which caused crashes.
Additionally:
.ptmodels failed to load properlyChanges
1. YOLO output handling (
yolo.py)Resultsobject (output.boxes)list/tupleoutputsmax_detectionssupport2. Model loading improvements (
torch_detection.py).ptmodelsmodel,state_dict)3. Improved prediction output
4. Robust ontology handling
Supports:
"classes"After Fix (Working Output)
🧪 Testing
Tested via Streamlit UI:
.pt(Results output).pt(list/tuple output)Files changed
perceptionmetrics/models/utils/yolo.pyperceptionmetrics/models/torch_detection.pyNotes
Let me know if you'd like me to add tests for these cases or refine the implementation further.
@dpascualhe