Skip to content
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

Code Modification and Object Detection Implementation with Jetson RT [error] "gain=ratio_pad[0] is not subscritable" #1040

Open
1 of 2 tasks
OscarAmayaEIA opened this issue Apr 26, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@OscarAmayaEIA
Copy link

Search before asking

  • I have searched the YOLOv6 issues and found no similar feature requests.

Description

when i try to implement YOLOv6 over TensorRT in a jetson orin , i have errors using the module Processor.py , i solved this with it:
Changes in the post_process method: The line self.scale_coords(self.input_shape, det_t[0][:, :4], img_shape[0], img_shape[1]) in the post_process method was commented out to avoid an error. This line was responsible for scaling the object detection coordinates, but passing img_shape[0] and img_shape[1] as arguments caused an error because these values did not meet the expectations of the scale_coords function.

Use case

Final code used (save in root path: YOLOv6\testRT.py):

import cv2
import deploy.TensorRT.Processor as YOLORT

Load the image

image_path = "IMG_DIR/22.png"
image = cv2.imread(image_path)

Instantiate the processor with the TensorRT model

model_path = "best.trt"
img_model_size = 192
processor = YOLORT.Processor(model_path,)

Detect objects in the image

outputs = processor.detect(image)

Post-process the outputs

ratio_pat = None # No ratio_pad provided
img_shape = [img_model_size, ratio_pat] # Input image size to the model
detected_objects = processor.post_process(outputs, img_shape)

Print the detected objects

print(detected_objects)

Draw bounding boxes around the detected objects

for detection in detected_objects:
x1, y1, x2, y2, conf, cls = detection
color = (0, 255, 0) # Green color for the bounding box
label = f"Class: {int(cls)}, Confidence: {conf:.2f}"
cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
cv2.putText(image, label, (int(x1), int(y1) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)

Display the resulting image

cv2.imshow("Detected Objects", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
In this code, an image is loaded, objects are detected using a TensorRT model, post-processing of the outputs is performed, and the detected objects are visualized by drawing bounding boxes around them in the original image. The calculation of ratio_pad has been omitted as it was not used in the scale_coords function.

Use:
cd YOLOv6
python3 testRT.py

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@OscarAmayaEIA OscarAmayaEIA added the enhancement New feature or request label Apr 26, 2024
@mtjhl
Copy link
Collaborator

mtjhl commented Apr 30, 2024

Gain ratio is not a part of tensorrt model. In tensorrt inference, you need to preprocess image (get the padding and scale ratio), tensorrt inference, post process(use padding and scale ratio to rescale the coordinates).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants