wang-xinyu / tensorrtx

Implementation of popular deep learning networks with TensorRT network definition API
MIT License
6.84k stars 1.75k forks source link

run yolov3-tiny engine tensorrt with python detection #565

Closed SokPhanith closed 3 years ago

SokPhanith commented 3 years ago

Env

About this repo

yolov3-tiny

Your problem

Sorry, When I build yolov3-tiny I run detection with ./yolov3-tiny -d ../sample. It's work . How can get example with python detection with yolov3-tiny.engine and also scaled-yolov4, yolov3, yolov3-spp, yolov4

wang-xinyu commented 3 years ago

You can refer to yolov5_trt.py to implement it by yourself.

SokPhanith commented 3 years ago

I try run it and edit some code but I don't know why I got index of class sometime > 100 or sometime got wrong

wang-xinyu commented 3 years ago

You have to debug it yourself, since you have modified it.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

vjsrinivas commented 2 years ago

@wang-xinyu If it's any use, here are the following modifications I did to get the yolov5_trt.py file working with YOLOv3:

  1. Change 6001 to 7001 on line 161
  2. Modify the post_process function to:
    def post_process(self, output, origin_h, origin_w):
        num = int(output[0])
        # Reshape to a two dimentional ndarray
        pred = np.reshape(output[1:], (-1, 7))[:num, :]
        if pred.shape[0] > 0:
            pred[:,4] *= pred[:,6]
            pred = pred[:,:-1]
        # Do nms
        boxes = self.non_max_suppression(pred, origin_h, origin_w, conf_thres=CONF_THRESH, nms_thres=IOU_THRESHOLD)
        result_boxes = boxes[:, :4] if len(boxes) else np.array([])
        result_scores = boxes[:, 4] if len(boxes) else np.array([])
        result_classid = boxes[:, 5] if len(boxes) else np.array([])
        return result_boxes, result_scores, result_classid

    For anyone else wondering the reason to the modifications, the output of YOLOv3 seemed to contain the objectness and class scores, so it was 7 elements in each prediction rather than YOLOv5's expected 6 elements (x,y,cw,ch,cls_id,cls_conf).

wang-xinyu commented 2 years ago

@vjsrinivas Can you please raise PR to add a yolov3_trt.py?

vjsrinivas commented 2 years ago

I will submit a PR in a couple days if someone else doesn't get to it first.