Closed wojciechpolchlopek closed 6 months ago
Hi! Thanks for reaching out with the details on your issue integrating the OBB model with the Triton server.
Based on your description, it sounds like there might be a mismatch in tensor dimensions or configuration between the TorchScript model and how Triton is set up to handle it, especially considering the negative dimension error.
Hereβs a quick suggestion:
config.pbtxt
for Triton, ensuring that output
dimensions align properly with your expected model outputs. For OBB tasks, dimensions might differ compared to standard detection models.Here's a slightly adjusted snippet for instantiating your model:
class YOLOOBBWrapper:
def __init__(self, model_url, task='obb'):
self.model = YOLO(model_url, task=task)
def predict(self, image_path):
return self.model(image_path)
We are indeed here to help further if this adjustment doesnβt resolve the issue! π
Hi, I have found a reason in
https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/obb/predict.py#L38
nc=len(self.model.names)
is a large number - correcting this to real nc value (e.g. 2) leads to correct results.
My question is: where model.names
should be set to have correct length?
Hi! Great job diving into the code and identifying the workaround! π
The model.names
should reflect the class names found in your dataset. Typically, this is set when you load your model using the dataset's YAML file, where the number of classes (nc
) and their respective names are specified.
If you are directly loading a model without associating it with a specific data YAML, you can manually adjust model.names
after loading your model as follows:
from ultralytics import YOLO
# Load your model
model = YOLO('your_model.pt')
# Set the correct class names
model.names = ['class1', 'class2'] # Update this list with your actual class names
Ensure the names are consistent with the nc
value and your class labels. That should align everything correctly! Let us know if this helps or if you need any more details!
Thank for your help. As a the workaround I finally used nc = detection.shape[1] - 5
for nms algorithm and my custom triton evaluation code with triton_client.async_infer
works fine :) The Issue could be closed, but...
Please consider this as a potential bug because exported model has proper model.names in the inner config.txt e.g. for nc=2:
{"description": "Ultralytics YOLOv8m-obb model trained on config.yaml", "author": "Ultralytics", "date": "2024-05-10T07:38:22.845204", "version": "8.2.1", "license": "AGPL-3.0 License (https://ultralytics.com/license)", "docs": "https://docs.ultralytics.com", "stride": 32, "task": "obb", "batch": 1, "imgsz": [640, 640], "names": {"0": "var", "1": "dontcare"}}
Hi there! π Great to hear you've found a workaround that suits your needs for now. We appreciate you sharing it!
Thanks also for pointing out this discrepancy with how model.names
is being handled for your use case. That's definitely something we'll consider investigating deeper to ensure consistency and correctness in exported model configurations. Iβll pass your feedback to our team.
For now, don't hesitate to reach out if you encounter any other issues or have further suggestions. Thank you for contributing to the YOLOv8 community by sharing these insights! π
Search before asking
YOLOv8 Component
Integrations
Bug
The local evaluation is correct on torchscript model but on triton seems to evaluate on task 'detect' instead of OBB I trained two models: with task='obb'
nc =2 -> exported size (1, 7, 8400) --local evaluation on exported torchscript model is correct -> correctly detected two rotated frames (with high score) using
model = YOLO(f'best.torchscript', task='obb')
--evaluaion on triton caused RuntimeError: Trying to create tensor with negative dimension -991: [0, -991] - formodel = YOLOOBBWrapper(f'http://localhost:8000/yolo_obb_1', task='obb')
where: