GithubHelp home page GithubHelp logo

Comments (3)

glenn-jocher avatar glenn-jocher commented on June 27, 2024

Hello! It looks like you're on the right track with setting up dynamic dimensions for your custom YOLOv8 model export to TensorRT. However, the issue you're encountering with the first dimension not being set to -1 for certain tensors is likely due to how TensorRT handles dynamic shapes during the export process.

For TensorRT, when you specify dynamic axes, you need to ensure that the model's architecture and the export settings are correctly aligned to handle these dynamic dimensions. From your description, it seems that only the last two output tensors are correctly recognizing the dynamic batch size.

Here's a couple of things you might want to check or adjust:

  1. Ensure Consistency in Model Definition: Double-check your model's forward function and make sure that all tensors that should have dynamic dimensions are correctly defined to handle varying batch sizes.
  2. Adjust Export Settings: Sometimes, explicitly setting the dynamic axes for all outputs as you've done might not be recognized due to internal handling by the export function. You might need to adjust or simplify how you define these settings.

If these steps don't resolve the issue, consider providing a minimal reproducible example when you seek further help. This way, the community or the support team can replicate the issue exactly and provide more targeted assistance.

Here's a simplified dynamic setting you might try adjusting to:

dynamic_axes = {'input': {0: 'batch'}, 'output': {0: 'batch'}}
model.export(format='engine', imgsz=1920, batch=1, half=True, dynamic_axes=dynamic_axes, simplify=False, int8=False)

Hope this helps! Let us know how it goes. πŸš€

from ultralytics.

zvant avatar zvant commented on June 27, 2024

@glenn-jocher
My forward function is quite complicated, involving multiple stages of scaling, NMS, sorting, indexing, matching, etc. It uses a for loop to iterate the samples in each batch. If TensorRT requires the dynamic dimension to be aligned through all these steps, it is not surprising it cannot work.

And yes, a simpler example does work with dynamic batch size.

My application does not really require dynamic batch size, so I might just set it to 1 for now. Thanks for the advice!

from ultralytics.

glenn-jocher avatar glenn-jocher commented on June 27, 2024

Hi there! πŸ‘‹

It sounds like you've got a complex forward function with multiple operations that might indeed complicate the handling of dynamic dimensions in TensorRT. Sticking to a fixed batch size, especially if dynamic batching isn't a requirement for your application, is a practical approach. Setting the batch size to 1, as you mentioned, should help maintain consistency and stability in your model's performance.

If you ever need to revisit dynamic batching or encounter any other issues, feel free to reach out. Happy coding! 😊

from ultralytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.