AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.7k stars 7.96k forks source link

IoU threshold for training? #8448

Closed DieBirke closed 2 years ago

DieBirke commented 2 years ago

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 commented 2 years ago

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

0) More data will definitely help. Applying oversampling techniques can help too.

1) 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 #7645

2) Recalculate anchors or you can even increase the number of anchors. #7856, #6548, #6740

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

All the best.

DieBirke commented 2 years ago

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 commented 2 years ago

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