ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
36.33k stars 7k forks source link

The confidence of the YOLO11 TensorRT inference #19079

Closed Ian-Work-AI closed 4 days ago

Ian-Work-AI commented 5 days ago

Search before asking

Question

I write a TensorRT inference code. The output shape obtained from TensorRT inference using the YOLO11n pre-training weight is 705600. During preprocessing, I apply padding before performing resizing.

padding_images = []
# Padding black
for image in imgs:
    row, col, _ = image.shape
    _max = max(col, row)

    padding_image = np.zeros((_max, _max, 3), np.uint8)
    padding_image[0:row, 0:col] = image
    padding_images.append(padding_image)

blob = cv2.dnn.blobFromImages(
    padding_images, 
    1 / 255.0, 
    (self.INPUT_WIDTH, self.INPUT_HEIGHT), 
    swapRB=True, 
    crop=False
    )      

blob = {"images" : blob}

return blob, padding_shapes

In postprocessing, I process the tensor as follows. However, the results I obtain are different from those using Ultralytics.

n_values = 4 + self.num_classes
total_predictions = infer_results.shape[0]
num_boxes = total_predictions // (n_values * batch_size)
# Transpose to [batch, num_boxes, (4 + num_classes)]
batch_result = infer_results.reshape(batch_size, n_values, num_boxes).transpose(0, 2, 1)

Why is this happening?

Additional

No response

UltralyticsAssistant commented 5 days ago

👋 Hello @Ian-Work-AI, thank you for reaching out and for your interest in Ultralytics 🚀! We recommend taking a look at the Docs where you’ll find helpful guidance, including examples for both Python and CLI, as well as insights into inference and other common tasks.

If this is a 🐛 Bug Report, please provide a minimum reproducible example (MRE) that includes all necessary steps, such as your exact setup and model configuration. This will help us replicate the issue and investigate it further.

If this is a ❓ Question, please provide more information about your setup, such as:

  1. The version of the ultralytics package and any relevant dependencies you are using.
  2. Any observed outputs versus the expected ones.
  3. Specific details or logs that highlight the difference between your TensorRT results and Ultralytics results.

To ensure you’re running the most stable version, please upgrade to the latest ultralytics package and dependencies. Use the following command in your Python>=3.8 environment with PyTorch>=1.8:

pip install -U ultralytics

Verified Environments

YOLO models can be tested in several verified environments. We recommend exploring these options if applicable:

Community Support

You may also find solutions or connect with others who’ve tackled similar tasks in our community:

CI Testing Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are passing. CI tests validate YOLO functionality across various platforms every 24 hours and upon every commit.

This is an automated response to guide you effectively 🛠️. An Ultralytics engineer will take a closer look and assist you further soon. Thank you for your patience! 😊

Y-T-G commented 5 days ago

It's not exactly the same padding as what Ultralytics uses.

https://github.com/ultralytics/ultralytics/blob/c5ac5548aeac8ed1554ef6224bd3d839974abc5b/examples/YOLOv8-TFLite-Python/main.py#L72

Ian-Work-AI commented 4 days ago

I have solved this problem. Thank you for your answer.

glenn-jocher commented 3 days ago

@Ian-Work-AI i'm glad to hear you solved the issue – many thanks to the YOLO community and the Ultralytics team for their continuous contributions.