Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IoU threshold for training? #8448

Closed
DieBirke opened this issue Apr 4, 2022 · 3 comments
Closed

IoU threshold for training? #8448

DieBirke opened this issue Apr 4, 2022 · 3 comments

Comments

@DieBirke
Copy link

DieBirke commented Apr 4, 2022

Is there a way to modify the loss function so the bounding boxes are more precise?
I know I can calculate map with an IoU threshold (standard 0.5) but can I adjust how the model is trained by inputting such a threshold?

While the model works well enough in detecting my objects, the bounding box isn't quite right sometimes and will cut off small parts of the obejct. Maybe this problem vanishes with more training data, which I am generating atm.
I already looked through my data and the bounding boxes there are as accurate as they can be.

IoU threshold = 0.5 results in a 98% map
IoU threshold = 0.8 drops this down to 45%
Average IoU is 64.58% which is good but I am trying to maximize the precision of the bounding boxes

@bulatnv
Copy link

bulatnv commented Apr 5, 2022

Hello @DieBirke
I'm not sure about loss function or IoU threshold. I can suggest you other ways to improve precision of bounding box:

  1. More data will definitely help. Applying oversampling techniques can help too.

  2. If objects in dataset are big enough (bigger than 32x32 pix), add new_coords=1 flag in the last yolo layer. Read more about it what is the use of new_coords=1 ?? in previous version we have not tried this but in yolov4-csp,yolov4-mish we used this new_coords concept.  #7645

  3. Recalculate anchors or you can even increase the number of anchors. howto: calculating custom anchors for YOLOv4-tiny #7856, Custom achors and small objects with yolov4-tiny-3l  #6548, Recalculating anchors for your dataset #6740

  4. Postprocessing: Instead of NMS use something more complex, like WBF (weigted box fusion). Read more about it here, here, here

All the best.

@DieBirke
Copy link
Author

DieBirke commented Apr 5, 2022

Hello, thanks for the amount of infos.
Going to try new_coords = 1 for sure as its super easy.

But I have some questions regarding the other methods:

For 2. anchors: First calculate anchors for my dataset with the calc_anchors command thenI would just add or change the values in the .cfg file for that?

Also I found options in my .cfg file for each yolo layer (where the anchors are incidently) that there is an iou-thresh

[yolo]
mask = 6,7,8
anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
classes=2
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
scale_x_y = 1.05
iou_thresh=0.213
cls_normalizer=1.0
iou_normalizer=0.07
iou_loss=ciou
nms_kind=greedynms
beta_nms=0.6
max_delta=5

So there are options for tweaking the iuo right?
threshold, normalizer and loss. Can you or someone explain these options?

@bulatnv
Copy link

bulatnv commented Apr 5, 2022

First calculate anchors for my dataset with the calc_anchors command thenI would just add or change the values in the .cfg file for that?

Yes. That's right. You need to change mask and anchors, and also change number of filters in previous layer if required.

Most of the parameters in yolo layer are explained in wiki

Unfortunately, I'm not very good at understating loss functions for yolo. This two papers are major papers for bounding box regression training:

  1. CIoU loss and Cluster NMS,
  2. DIoU loss.
  3. This is main repo: Complete-IoU Loss and Cluster-NMS

@DieBirke DieBirke closed this as completed Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants