Search code examples
deep-learningyoloyolov7

Is there any limit to detected objects in YOLOv7?


I have trained a YOLOv7 model using the Roboflow notebook and my own dataset: https://colab.research.google.com/drive/1X9A8odmK4k6l26NDviiT6dd6TgR-piOa

I worked with these notebooks before, but never had images with more than 100 objects, but now, I have trained a model to detect microbiologic colonies, and the model is detecting up to a max of 100 objects.

At first I thought it was a problem of the network not being able of detecting all the objects because it was not well trained or due to precision (My dataset is composed of 500 images, and the final accuracy is about 80%).

But, I have some images that has between 15-30 objects, and it detects all fine. In my images that objects are clearly more than 100, the network always counts up to 100 objects, never more.

Is there any limit to yolov7 in object quantity? Or maybe a parameter that has to be changed in training phase?


Solution

  • Thank you to cherrywoods answer that gave me some tips to where to look, I've found out that when exporting the model to ONNX, using the export.py script provided by the official YOLO repository, there is a parameter named topk-all that can be changed in order to adjust the maximum number of detectable objects.

    So, in this case I am exporting the model from the original PyTorch model to an ONNX model using the export.py script like this:

    python export.py --weights best.pt \
            --grid --end2end --simplify \
            --topk-all 200 --iou-thres 0.65 --conf-thres 0.35 \
            --img-size 640 640 --max-wh 640
    

    Where topk-all parameter specifies the maximum number of objects to detect in every image, and now the limit of detectable objects is set up to 200.