ibaiGorordo / ONNX-YOLOv8-Object-Detection

Python scripts performing object detection using the YOLOv8 model in ONNX.
MIT License
369 stars 93 forks source link

Accuracy degradation #8

Closed lyylsh closed 1 year ago

lyylsh commented 1 year ago

When I converted the yolov8n model to onnx, the accuracy of the model dropped a lot. What should I do?Thanks

AllenMingWei commented 1 year ago

hahah,me too

lyylsh commented 1 year ago

hahah,me too

I found that the drop in accuracy was due to the fact that the image scaling process used was not proportional scaling, which is used in the yolo source code.

ibaiGorordo commented 1 year ago

https://github.com/ibaiGorordo/ONNX-YOLOv8-Object-Detection#important

kopyl commented 1 year ago

@ibaiGorordo for anybody wondering how to add padding: https://gist.github.com/IdeaKing/11cf5e146d23c5bb219ba3508cca89ec

Example usage code:

class_names = {0: 'a', 1: 'b', 2: 'c'}
yolov8_detector = YOLOv8("yolov8_custom_trained_model.onnx", conf_thres=0.01, iou_thres=0.01)

def detect(img_url):
    class_names = {0: 'adult', 1: 'nipple', 2: 'underage'}
    img = imread_from_url(img_url)
    img = resize_with_pad(img, (800, 800))
    _, scores, class_ids = yolov8_detector(img)
    prediction = map(
        lambda x: [class_names[x[0]], float(x[1])], zip(class_ids, scores)
    )
    return list(prediction)
xbkaishui commented 1 year ago

great, thanks

pietz commented 11 months ago

This will fix the problem with lower scores. However, it will mess up the position of the bounding box on the smaller side axis. So there also needs to be some logic to recaculate the BBs without the padding.