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

recaculate anchors #1517

Open
Gumballing opened this issue Aug 31, 2018 · 15 comments
Open

recaculate anchors #1517

Gumballing opened this issue Aug 31, 2018 · 15 comments

Comments

@Gumballing
Copy link

Gumballing commented Aug 31, 2018

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
Copy link
Author

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

@AlexeyAB
Copy link
Owner

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
Copy link
Author

@AlexeyAB
Copy link
Owner

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

@Gumballing
Copy link
Author

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

@AlexeyAB
Copy link
Owner

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

@AshleyRoth
Copy link

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

@AlexeyAB
Copy link
Owner

@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
Copy link

@AlexeyAB Thank you!

@SteveBetter
Copy link

SteveBetter commented Sep 10, 2018

pjreddie#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
Copy link

hahakid commented Oct 4, 2018

@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
Copy link
Owner

AlexeyAB commented Oct 4, 2018

@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
Copy link

hahakid commented Oct 5, 2018

@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
Copy link

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
Copy link

Sim-ai commented Oct 11, 2020

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.

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

7 participants