AlexeyAB / darknet

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

recaculate anchors #1517

Open Gumballing opened 6 years ago

Gumballing commented 6 years ago

I used the command : ./darknet detector calc_anchors data/voc.data -num_of_clusters 9 -width 416 -height 416 to recaculate the anchors about my dataset. But the result is there no output,just like this:

zhengli@zhengli-K55VD:~/darknet$ ./darknet detector calc_anchors data/voc.data -num_of_clusters 9 -width 416 -height 416 zhengli@zhengli-K55VD:~/darknet$

Why did this happen?

And in "https://github.com/AlexeyAB/darknet/blob/master/scripts/gen_anchors.py ",Where can I to change the path to recaculate for my dataset?

It's there? ` parser.add_argument('-filelist', default = '\path\to\voc\filelist\train.txt',

                    help='path to filelist\n' )

parser.add_argument('-output_dir', default = 'generated_anchors/anchors', type = str, 

                    help='Output anchor directory\n' )  

parser.add_argument('-num_clusters', default = 0, type = int, 

                    help='number of clusters\n' )  `
Gumballing commented 6 years ago

I want to recaculate anchors for yolov3-tiny.cfg.

AlexeyAB commented 6 years ago

Do you use code from this repository?

I want to recaculate anchors for yolov3-tiny.cfg.

Use the command: ./darknet detector calc_anchors data/voc.data -num_of_clusters 6 -width 416 -height 416

But the result is there no output

Can you show screenshot?

Gumballing commented 6 years ago

@AlexeyAB The screenshot: https://github.com/gzhengli/YOLO-for-my-data/blob/master/screen%20of%20anchors%20command.png

AlexeyAB commented 6 years ago

@gzhengli Do you use code from this repository or from https://github.com/pjreddie/darknet ?

Gumballing commented 6 years ago

@AlexeyAB The latter .Frome https://github.com/pjreddie/darknet

AlexeyAB commented 6 years ago

@gzhengli Try to use this repository: https://github.com/AlexeyAB/darknet

AshleyRoth commented 6 years ago

hi! @gzhengli @AlexeyAB What is it "-num_of_clusters"? I want to recalculate to 608x608. Thanks!

AlexeyAB commented 6 years ago

@AshleyRoth It is number of anchors (number of pairs of values), it is equal 5 for yolov2, 6 for yolov3-tiny, 9 for yolov3.

AshleyRoth commented 6 years ago

@AlexeyAB Thank you!

SteveBetter commented 6 years ago

https://github.com/pjreddie/darknet/issues/577

https://github.com/AlexeyAB/darknet/blob/master/scripts/gen_anchors.py

How to use the above python code for YOLOv3? Are the modifications below all that needed?

# change picture width and height according to the .cfg file
width_in_cfg_file = 448.
height_in_cfg_file = 448.
# comment out "/32."
anchors[i][0]*=width_in_cfg_file #/32.
anchors[i][1]*=height_in_cfg_file #/32.
hahakid commented 6 years ago

@AshleyRoth It is number of anchors (number of pairs of values), it is equal 5 for yolov2, 6 for yolov3-tiny, 9 for yolov3.

should the values be fixed according to the architectures or we can random define the number of anchors, i.e., using 7 for yolo3-tiny?

AlexeyAB commented 6 years ago

@ouyangkid

You can use any number of anchors, but then you should change number of filters before each [yolo]-layer: https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

filters=(classes + coords + 1)*num)

hahakid commented 6 years ago

@AlexeyAB I am a little confused, therefore, I paste the last two layers from yolov3.cfg

[convolutional] size=1 stride=1 pad=1 filters=255 activation=linear

[yolo] mask = 0,1,2 anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 classes=80 num=9 jitter=.3 ignore_thresh = .7 truth_thresh = 1 random=1

according to the explain filters=255=(classes+4+1)*3 classes=80, 4 for coords and 1 for objectness. According to the equation from you: filters=(classes + coords + 1)*num), I should modify the 3?

However, the anchors=9 and the "num" in the Yolo layer also equal to 9. Do you mean by modifying this value instead of the one in the filters? Or they all should be modified?

By the way, what does the mask=0,1,2 mean? according to 1 and 2 the last parameter is the mask?

apatsekin commented 5 years ago

However, the anchors=9 and the "num" in the Yolo layer also equal to 9. Do you mean by modifying this value instead of the one in the filters? Or they all should be modified? filters=(classes + coords + 1)*num)

num in this equation should be equal to the number of anchors actually used by following [yolo] entity.

And in [yolo] you set this number by setting mask=. Hence, during training, output of this layer will be matched to ground truth relatively to 1st, 2nd, 3rd anchors from your list, since you set mask=0,1,2. On the next [yolo] entity you probably have mask=3,4,5 implying that 4th, 5th, and 6th anchors should be employed.

However, num in [yolo] params:

num=9

  • is the number of total anchors in the whole model (so it's constant in all [yolo] params). It should be constant and equal to number of pairs of w/h you have in anchors= (which is also constant through out all [yolo] entities in cfg).

p.s. this num= and anchors= thing seems weird too me actually, but there should be reason for that.

Sim-ai commented 4 years ago

I also try to calculate anchors of yolov3 by using google colab, and my command line was inputed as below: !./darknet detector calc_anchors obj.data -num_of_clusters 9 -width 416 -height 416 after conducting this command line, the performing log update some new lines as below: image and then, 30 mins past, there has nothing updated informatin in log windows, but the button was still rotating. I'm wondering whether this state was good and need I input anything into the command line box in the bottom of the log window? Looking forward for reply, thanks.