Jumabek / darknet_scripts

Auxilary scripts to work with (YOLO) darknet deep learning famework. AKA -> How to generate YOLO anchors?
223 stars 96 forks source link

Issue when executing gen_anchors #1

Closed StevenPuttemans closed 7 years ago

StevenPuttemans commented 7 years ago

Hello @Jumabek

First of all, thanks for providing the necessary scripts to do some customizations of darknet.

I tried the gen_anchors script, with the following command python gen_anchors.py -filelist ~/Github/darknet/train.txt -num_clusters 5 -output_dir coconut_anchors/ but whenever running it, it seems I have an error through python

Traceback (most recent call last):
  File "gen_anchors.py", line 154, in <module>
    main(sys.argv)
  File "gen_anchors.py", line 128, in main
    w,h = line.split(' ')[3:]
ValueError: too many values to unpack

Any idea what could be the reason of this?

StevenPuttemans commented 7 years ago

Also, the file looks like this, which is the file called before this error is raised.

0 0.366279 0.707731 0.100000 0.100000 0 0.281418 0.061305 0.100000 0.100000 0 0.506687 0.026250 0.100000 0.100000 0 0.613862 0.108427 0.100000 0.100000 0 0.619609 0.019929 0.100000 0.100000 0 0.176829 0.143769 0.100000 0.100000 0 0.292912 0.164457 0.100000 0.100000 0 0.403247 0.166181 0.100000 0.100000 0 0.429107 0.239164 0.100000 0.100000 0 0.279694 0.252381 0.100000 0.100000 0 0.527375 0.239738 0.100000 0.100000 0 0.640872 0.244336 0.100000 0.100000 0 0.630528 0.351080 0.100000 0.100000 0 0.522491 0.351655 0.100000 0.100000 0 0.437440 0.360275 0.100000 0.100000 0 0.628229 0.439722 0.100000 0.100000 0 0.629953 0.524773 0.100000 0.100000 0 0.626505 0.643154 0.100000 0.100000 0 0.513871 0.637982 0.100000 0.100000 0 0.513871 0.527646 0.100000 0.100000 0 0.514445 0.450066 0.100000 0.100000 0 0.164761 0.527646 0.100000 0.100000 0 0.158440 0.624765 0.100000 0.100000 0 0.153842 0.714556 0.100000 0.100000 0 0.723336 0.640568 0.100000 0.100000 0 0.949755 0.640568 0.100000 0.100000 0 0.948031 0.512130 0.100000 0.100000 0 0.956651 0.421333 0.100000 0.100000 0 0.841717 0.429953 0.100000 0.100000 0 0.826201 0.512705 0.100000 0.100000 0 0.728508 0.522474 0.100000 0.100000 0 0.746323 0.356683 0.100000 0.100000 0 0.749771 0.243474 0.100000 0.100000 0 0.854935 0.344040 0.100000 0.100000 0 0.857808 0.257266 0.100000 0.100000 0 0.917573 0.227958 0.100000 0.100000 0 0.968719 0.256116 0.100000 0.100000 0 0.964121 0.346914 0.100000 0.100000 0 0.916424 0.023233 0.100000 0.100000 0 0.819306 0.027256 0.100000 0.100000 0 0.833672 0.103686 0.100000 0.100000 0 0.726784 0.100813 0.100000 0.100000 0 0.719314 0.017486 0.100000 0.100000

StevenPuttemans commented 7 years ago

Ok I solved it, seemed that my files had trailing whitespaces. That was solved rather quickly and then the script ran just fine. Executed on my data, finally got anchors that make sense.

Centroids =  [[ 0.09999999  0.09999999]
 [ 0.          0.        ]
 [ 0.          0.        ]
 [ 0.          0.        ]
 [ 0.          0.        ]]

Anchors =  [[ 0.          0.        ]
 [ 0.          0.        ]
 [ 0.          0.        ]
 [ 0.          0.        ]
 [ 1.29999981  1.29999981]]

centroids.shape (5, 2)
StevenPuttemans commented 7 years ago

Does it mean that once you get zeros, there is no use for adding multiple anchors?

Jumabek commented 7 years ago

Hi @StevenPuttemans , Yes, it seems for your dataset single anchor is enough. Meaning most of your objects probably have the same ratio of height to width.

StevenPuttemans commented 7 years ago

@Jumabek thanks for getting back to me! I will experiment with this new insight. Did you even tried adding manual anchors? For example I know objects have to be 100x100 pixels, so in principle a 1.0,1.0 anchor would be more fitting than the oversized 1.3,1.3?

Or is there a reason for the oversizing?

StevenPuttemans commented 7 years ago

image

As you can see, I managed to force it to learn square detections, however it is still not performing as I desire. Now my detections are very small. Any suggestions always welcome!

ps. edited - wron image

Jumabek commented 7 years ago

what is your input image size in cfg file? If it is not 416, then you have to change this line accordingly

Jumabek commented 7 years ago

Or you can just scale 1.3,1.3 3x and put anchor as 3.9,3.9 Another thing to try is having more than one anchors. For example make 4 anchors all of them are the scaled version of 1.3, 1.3

StevenPuttemans commented 7 years ago

Yeah I noticed. So it was 992 in that case. Changed it back to original and it worked. Now further finetuning the model. If it is 992 we need 2.0,2.0?

StevenPuttemans commented 7 years ago

Ok thnx for feedback!

Jumabek commented 7 years ago

No, you need to change 416 -> 992 in https://github.com/Jumabek/darknet_scripts/blob/master/gen_anchors/gen_anchors/gen_anchors.py#L44 line. and then compute the anchors again.