darknet_scripts icon indicating copy to clipboard operation
darknet_scripts copied to clipboard

Generate anchors error !

Open phongnhhn92 opened this issue 6 years ago • 11 comments

Hello guys, I am trying to run gen_anchors.py but I have this error: capture I am using python 3.5, opencv 3.2 installed and I already fixed print function with parentheses. Please help me to fix it !

phongnhhn92 avatar Jul 10 '17 06:07 phongnhhn92

Hi @phongnhhn92 , I think your labels are not generated correctly. Could you post here your annotations. For example, the content of the file */labels/2011_003275.txt You should have annotations in the following format: 0 0.49 0.411910669975 0.812 0.575682382134

Jumabek avatar Jul 10 '17 18:07 Jumabek

@Jumabek I have the same problem,My annotations is here 0 0.7895148669796558 0.65625 0.10485133020344288 0.07916666666666666 but have the same problem,could you help me> Thank you!

wzhang16 avatar Aug 15 '17 06:08 wzhang16

hi @wzhang16 , is your filelist.txt contains correct path to annotations? To make sure code is reading your annotations correctly, try to print the 'line' variable after this line: https://github.com/Jumabek/darknet_scripts/blob/master/gen_anchors.py#L141

Jumabek avatar Aug 15 '17 12:08 Jumabek

I have the same issue @Jumabek , and the program is reading my files correct: /home/mikeyr/data/create/detection_annotation/labels/39198.txt 0 0.12421769391832904 0.410257141706863 0.0589970501474926 0.089928057553957 0 0.04845086485233696 0.938150917785313 0.0589970501474925 0.0899280575539564

TheMikeyR avatar Sep 05 '17 13:09 TheMikeyR

@phongnhhn92 @wzhang16 and @Jumabek found the mistake, it is regarding running the code in python3, if you instead switch to python 2.7 there are no issues other than i get nan after 2 iter.


/home/mikeyr/data/create/detection_annotation/labels/03795.txt
0 0.875920775369144 0.958289169434247 0.0589970501474926 0.0899280575539565
0 0.933315296953791 0.400019868089978 0.0589970501474925 0.0899280575539567
0 0.927916731307702 0.678050493163444 0.0589970501474926 0.0899280575539574
0 0.872447086517035 0.147653038279658 0.0589970501474926 0.0899280575539571
[[ 0.05899705  0.08992806]
 [ 0.05899705  0.08992806]
 [ 0.05899705  0.08992806]
 [ 0.05899705  0.08992806]
 [ 0.05899705  0.08992806]]
iter 1: dists = 334.232505441
iter 2: dists = 265.093090244
gen_anchors.py:101: RuntimeWarning: invalid value encountered in divide
  centroids[j] = centroid_sums[j]/(np.sum(assignments==j))
iter 3: dists = nan
iter 4: dists = nan

TheMikeyR avatar Sep 06 '17 06:09 TheMikeyR

the error was encountered with number of clusters > 3, everything from 3 and below works fine.

TheMikeyR avatar Sep 06 '17 07:09 TheMikeyR

So, python 2.7 only for this script? Not working with python 3.6:

the error was encountered with number of clusters > 3, everything from 3 and below works fine.

4F2E4A2E avatar Sep 27 '17 00:09 4F2E4A2E

@4F2E4A2E Yes python2 made the script run in first try where python 3 failed. I guess you could port it to python3, but it will require you to debug the code since errors can occur.

Number of clusters available to set changes with your data, on my own data I could not go over 3, but with voc data I had no issues with 5.

TheMikeyR avatar Sep 27 '17 06:09 TheMikeyR

Python3 changes behaviour of / operator. change lines (notice // vs / ) cell_w = image['width']//grid_w cell_h = image['height']//grid_h

gevorgter avatar Jan 18 '18 12:01 gevorgter

@gevorgter can you please list the lines that should be changed?I changed some lines but result in failed as well.

line 105:

   centroids[j] = centroid_sums[j] / (np.sum(assignments == j))

line 55-56

    anchors[i][0] *= width_in_cfg_file // 32.
    anchors[i][1] *= height_in_cfg_file // 32.

shartoo avatar Jul 16 '18 10:07 shartoo

@shartoo I did (replace // with / and you will get original code). But the code was changed. So my fix might be not relevant anymore. But in a nutshell problem was that python 3 operation '/' produces float (real) number instead of integer.

gevorgter avatar Jul 16 '18 16:07 gevorgter