feature: support native YOLO .pt models while ensuring compatibility with Torchvision models#495
Open
kashtennyson wants to merge 2 commits intoJdeRobot:masterfrom
Open
feature: support native YOLO .pt models while ensuring compatibility with Torchvision models#495kashtennyson wants to merge 2 commits intoJdeRobot:masterfrom
kashtennyson wants to merge 2 commits intoJdeRobot:masterfrom
Conversation
Collaborator
|
Hi, thanks for your contribution! I'll review the PR thoroughly when I can since this is an important upgrade. |
Author
|
Alright @dpascualhe. Thanks for the update! I am also currently working on a broader refactor to provide global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for loading native Ultralytics YOLOv8
.ptmodels while ensuring a consistent interface for the rest of the library. This is a fix for #449The Problem:
Native YOLO
.ptmodels often return a tuple(inference_tensor, loss_tensor)rather than a raw tensor, which causes "too many values to unpack" errors in theinferenceandevalmethods. Additionally, these models frequently usefloat16(Half) precision, leading toDTypemismatches with input images or NMS kernel errors on certain backends.The Solution:
Following previous feedback, I have centralized the fix within the
TorchImageDetectionModelclass. I implemented a local Adapter class (DetectionModelWrapper) that standardizes the model's behavior at the source:dtype(fixing "Float vs Half" errors).float32to maintain compatibility withtorchvision.ops.nms..ptloading logic to provide a clear error message suggesting the installation ofultralyticsif it is missing.This PR Supersedes #469. It implements a more stable version by ensuring compatibility with
Torchvisionmodels along with theUltralyticsYOLO models.Architectural Question for Maintainers