AlexeyAB / darknet

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

masks in csresnext50 configs #5203

Open Luux opened 4 years ago

Luux commented 4 years ago

Hi there, the README states the following for the mask settings:

But you should change indexes of anchors masks= for each [yolo]-layer, so that 1st-[yolo]-layer has anchors larger than 60x60, 2nd larger than 30x30, 3rd remaining. 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.

In https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov3-spp.cfg, this results in

[yolo] # first yolo layer
mask = 6,7,8
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326
...
[yolo] # second yolo layer
mask = 3,4,5
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326
...
[yolo] # third yolo layer
mask = 0,1,2
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326

Considering the README, this is the correct order. However, in the newer https://github.com/AlexeyAB/darknet/blob/master/cfg/csresnext50-panet-spp-original-optimal.cfg, this order is reversed:

[yolo] # yolo layer 1
mask = 0,1,2
anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
...
[yolo] # yolo layer 2
mask = 3,4,5
anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
...
[yolo] # yolo layer 3
mask = 6,7,8
anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401

According to the README, this mask order does not seem to be set correctly and it should be like in the yolov3-spp config. Or did I miss something?

VolkovAK commented 4 years ago

Hi @Luux You missed that csresnext50 has 512 input size, and yolov3-spp - 416, and difference between anchor boxes is the same as between input sizes.

But there is another question - do we need to scale them when changing input size? Seems like it still works, so anchors scaling does not matter?

Luux commented 4 years ago

@VolkovAK The scaling is not the probem - of course the anchor boxes can have different sizes. What I mean is which anchor boxes are used in which layers. In the README is written that the first yolo layer should begin with these greater than 60x60px, the 2nd gets the ones between 60x60 and 30x30 and the 3rd one the remaining. This means, you start with the biggest anchors in yolo layer 1 and proceed to the smaller ones in the remaining yolo layers.

However, in the csresnext configs the first yolo layer gets the smallest anchors instead of the biggest - the order is reversed. I wonder if I missed some architecture-specific thing (then it should be documented) or if this just a mistake in the csresnext config.

WongKinYiu commented 4 years ago

https://github.com/AlexeyAB/darknet/issues/5134