2

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?

juan carlos
  • 184
  • 1
  • 11

2 Answers2

2

I am not an expert in this, but I have the following suspicion:

YOLO divides the input image into a grid of cells. Each cell predicts bounding boxes, confidences and class probabilities. I think YOLO can not predict more objects than there are cells in the grid. Talking about the original YOLO paper they define the S the number of grid cells in one dimension. Assume S = 10 in the code you are using for training, that would yield at maximum 100 objects that can be detected. If my reasoning is sound, you should be able to detect more objects when you increase this number.

cherrywoods
  • 1,284
  • 1
  • 7
  • 18
  • 1
    Hey, I just solved the problem, your answer gave me tips about where to look, but I forget a thing... I was using the model exported to ONNX, using the `export.py` script has a parameter named `topk`, that defines the maximum number of objects to be detected. It was set to 100 by default, I put 200 then I can detect more than 100... Maybe I need to edit my question to add the ONNX thing, and then answer to the question? I don't know what it needs to be done in that cases. – juan carlos Feb 22 '23 at 08:48
  • 1
    Great that you got it solved! I think it's fine if you leave your question as-is and add and accept the answer you found. – cherrywoods Feb 22 '23 at 09:30
1

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.

juan carlos
  • 184
  • 1
  • 11