Closed brimoor closed 4 months ago
The refactoring in fiftyone/utils/super_gradients.py
simplifies the _convert_yolo_nas_detection_model
function and modifies the TorchYoloNasModel
class, improving model initialization and prediction handling. These changes are aimed at resolving issues with YOLO-NAS inference, ensuring correct detection visualization in FiftyOne's Web UI.
Files/Modules | Change Summary |
---|---|
fiftyone/utils/super_gradients.py |
Refactored _convert_yolo_nas_detection_model to simplify config_model setup and modified TorchYoloNasModel to handle model loading and prediction differently. |
sequenceDiagram
participant User
participant FiftyOne
participant TorchYoloNasModel
participant SuperGradients
User->>FiftyOne: Apply YOLO-NAS model on dataset
FiftyOne->>TorchYoloNasModel: Initialize model
TorchYoloNasModel->>SuperGradients: Load YOLO-NAS model
SuperGradients-->>TorchYoloNasModel: Return model
TorchYoloNasModel-->>FiftyOne: Model initialized
FiftyOne->>TorchYoloNasModel: Predict on images
TorchYoloNasModel->>SuperGradients: Perform prediction
SuperGradients-->>TorchYoloNasModel: Return predictions
TorchYoloNasModel-->>FiftyOne: Return predictions
FiftyOne-->>User: Display predictions in Web UI
Objective | Addressed | Explanation |
---|---|---|
Resolve YOLO-NAS inference issue in FiftyOne's Web UI (#4428) | ✅ | |
Ensure detections appear correctly in labels_batch and labels (#4428) |
✅ |
In code's embrace, a bug was found, With tweaks and care, it’s now unbound. Predictions clear, on screen they show, The YOLO-NAS, in perfect flow. FiftyOne's joy, a fix profound.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Resolves https://github.com/voxel51/fiftyone/issues/4428
Context
@jacobmarks as far as I can tell,
TorchYoloNasModel
was previously broken because its_predict_all()
method returned a singleDetections
instance, but theTorchImageModel
contract requires_predict_all()
to return a list ofDetections
.Note that, as currently implemented,
TorchYoloNasModel
does not support batching because it produces a model withragged_batches == True
:which means that
apply_model()
will not allow abatch_size
to be provided: https://github.com/voxel51/fiftyone/blob/6faa5d72f61a566f58b85c4a8dbd8df39b9f4e18/fiftyone/core/models.py#L1807If the underlying SuperGradients model instance does in fact support batching, then the
TorchYoloNasModel
wrapper would need to be tweaked to allow this to occur.In the meantime, this PR fixes inference by implementing
predict()
andpredict_all()
correctly.Example usage
The following now works as expected:
Summary by CodeRabbit