WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.37k stars 4.22k forks source link

ONNX output for object detection #1419

Open sathish331977 opened 1 year ago

sathish331977 commented 1 year ago

After exporting a trained Yolov7 model to ONNX i see the following output . I am looking to extract bounding box , confidence score and the classes from the predictions. What is the correct mapping from output of onnx to bounding boxes, confidence score and classes. Number of classes trained are 9

OnnxYv7

Krainez commented 1 year ago

You need to give " --grid --end2end " arguments when you are exporting.

sathish331977 commented 1 year ago

here are my export args (included --grid and --end2end) !python export.py --weights bestmodelsforexport/yv701122023/best.pt \ --grid --end2end --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 \ --img-size 640 640 --max-wh 600

the output looks like this now

OnnxYv7-1

Krainez commented 1 year ago

You can extract batch_id, xmin, ymin, xmax, ymax, cls_id, and score (which 7 stands for) from this.

LLsmile commented 1 year ago

In latest code, the exported onnx model seems different. How can I map it? Following is my training code and export code: python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml python export.py --weights runs/train/yolov7_box/weights/epoch_024.pt --grid --end2end --topk-all 100 --iou-thres 0.5 --conf-thres 0.35 --img-size 640 640 --max-wh 600

Screenshot from 2023-03-06 17-32-57

LukeAI commented 1 year ago

what execution env are you targetting? I export for TensorRT using:

python export.py --weights myweights.pt --grid --include-nms --conf-thres 0.01 --iou-thres 0.4 --img-size 640 640 --simplify

image

but it's using a TRT plugin so I don't think it'll work for other runtimes

Nandha95 commented 1 year ago

@LukeAI When I try to run the command with the TRT nms, I get the following error: image

And then exporting to tensorflow breaks with this error: image

Have you or anyone else faced this error?

LukeAI commented 1 year ago

And then exporting to tensorflow breaks with this error:

you mean tensorrt right?

I guess your tensorrt install isn't present or up to date

Nandha95 commented 1 year ago

Ah ok, didn't realise that I needed tensorrt to be installed as well, but I am trying to export the model to tensorflow. However, I did notice that if I include the --max-wh option with a value, it still throws an error when I try and convert to tensorflow.

image