Mike Azatov
Mike Azatov

Reputation: 452

Custom anchors in Yolov3

I'm training an object detector using Yolov3 on my custom dataset. Traditionally in Yolo you have a variety of object classes so you get a good mix of anchors. In my case, I only have one object class and it has pretty similar dimensions. So when I cluster the dimensions using K-means, I get 9 anchors of pretty similar size... which seems counterproductive.

In fact, I tried with some random anchor sizes that are not all similar and got better results than with 9 similar anchors. So I wonder, what's the best strategy for anchors for 1 class object detector?

Upvotes: 2

Views: 5755

Answers (1)

Venkatesh Wadawadagi
Venkatesh Wadawadagi

Reputation: 2943

This is what author says about anchor boxes here:

Only if you are an expert in neural detection networks - recalculate anchors for your dataset for width and height from cfg-file: darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416 then set the same 9 anchors in each of 3 [yolo]-layers in your cfg-file. But you should change indexes of anchors masks= for each [yolo]-layer, so for YOLOv4 the 1st-[yolo]-layer has anchors smaller than 30x30, 2nd smaller than 60x60, 3rd remaining, and vice versa for YOLOv3. Also you should change the filters=(classes + 5)* before each [yolo]-layer. If many of the calculated anchors do not fit under the appropriate layers - then just try using all the default anchors.

So to train single class object detector where in object dimensions are pretty similar, then:

  1. Use default anchor boxes as stated above
  2. Use random=0 in the cfg

To understand anchor box concept, go through this discussion.

Also since Yolov4 is available now, suggest you to use that for better accuracy/mAP. If you want to stick to Yolov3, use Yolov3-spp or Yolov3_5l for improved results.

Upvotes: 1

Related Questions