-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keeping aspect ratio with CropAndResize Plugin #4271
Comments
You can ref tf.image.crop_and_resize. |
cc @venkywonka for additional comment |
Hi @MaximeDebarbat , thank you for taking the time to create the github issue. Could you provide more details on which specific part of the plugin you're facing problem with?
I'm afraid I don't understand how this might be related to the plugin. You mean the above was the alternative you tried? Thanks! |
Hi @venkywonka, thank you for answering. Here are some details: Let's say, you have 2 bounding boxes like these (x1, y1, x2, y2): The plugin would distort these 2 rectangular crops to resize them into 256x256. What I would love to have, would be a crop and "padded" resize which resizes the crops while adding padding: As a picture is worth a thousand words : Also I mentioned the torch model as I tried to add some features to the TensorRT crop-and-resize plugin in torch->onnx->tensorRT but without success unfortunately. I mostly tried to resize the boxes to fit the aspect ratio of the expected output while keeping for each bboxes the amount of stretching applied, then turning the stretching into padding afterwards. |
Thank you for the above details! Unfortunately I don't see a trivial way of doing that through the existing But what I do believe is that you can encode that logic to custom-pad it, into the plugin's source, and recompile the plugin library and try. The full custom compute definition of how the cropAndResize Plugin works is open to local modifications, so until we have a new version/variant of the same plugin officially shipped by TensorRT to do the task of preserving the aspect ratio, unfortunately you'd probably have to get dirty with the plugin's C++ code. I shall take this as useful user feedback and internally push towards adding this feature. |
for an easier pythonic way to do the same, do checkout Writing custom operators with TensorRT Python plugins, which shows an example of defining the Circular padding plugin. PS: make sure you have an updated TensorRT to leverage the above feature. Hopefully that helps. |
That could be amazing to integrate it directly yes as many models require to keep a good aspect ratio, that could speed up the process a lot! Cheers! |
Hi,
I'm looking for a way to keep the aspect ration with the plugin CropAndResize (yolo style):
https://github.com/NVIDIA/TensorRT/blob/release/10.6/plugin/cropAndResizePlugin/cropAndResizePlugin.cpp
I tried to create a custom torch model which would do this padding but it's unsuccessful for now.
Any help would be greatly appreciated!
Cheers
The text was updated successfully, but these errors were encountered: