hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

digits in `.names`-file causes `prob_loss: 0` #29

Closed mjkvaak closed 4 years ago

mjkvaak commented 4 years ago

Hi, first of all thank you so much for this awesome package!

I noticed, while training a model to detect handwritten symbols, that if you insert digits (or floats) into the .names file (to replace the default coco.names), the training will fail because prob_loss: 0. I bet this is because somewhere under the bonnet python reads the lines and casts them as integers (floats). Renaming the labels as something that python casts as strings will solve the issue. For example, if names has

I think it would be simple to fix this by enforcing the labels to be string-objects after reading them from names. However, I'm posting this mostly as a warning for others that might suffer from same behavior.

hhk7734 commented 4 years ago

I will check.

https://github.com/hhk7734/tensorflow-yolov4/blob/0e73c11ebdfc22f6776b49f6d4dd53415592b585/py_src/yolov4/common/media.py#L177-L190

Maybe, I will fix this part. If you can, submit PR.

Thank you:)

hhk7734 commented 4 years ago

Hi~

I tested digit names. There seems to be no problem.

0
1
2
3.14
4
In [1]: from yolov4.tf import YOLOv4

In [2]: yolo = YOLOv4()

In [3]: yolo.classes = "test/custom.names"

In [4]: yolo.classes
Out[4]: {0: '0', 1: '1', 2: '2', 3: '3.14', 4: '4'}
Epoch 1/400
grid: 38 iou_loss: 43.7973251 conf_loss: 3025.49951 prob_loss: 655.996 total_loss 3725.29297
grid: 19 iou_loss: 24.7095528 conf_loss: 718.25415 prob_loss: 432.113922 total_loss 1175.07764
grid: 38 iou_loss: 33.9643173 conf_loss: 2997.89746 prob_loss: 494.985413 total_loss 3526.84717
grid: 19 iou_loss: 27.314003 conf_loss: 701.960083 prob_loss: 469.517 total_loss 1198.79102
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/summary_ops_v2.py:1277: stop (from tensorflow.python.eager.profiler) is deprecated and will be removed after 2020-07-01.
Instructions for updating:
use `tf.profiler.experimental.stop` instead.
grid: 38 iou_loss: 42.1775055 conf_loss: 2971.35498 prob_loss: 622.553162 total_loss 3636.08569
grid: 19 iou_loss: 22.6043396 conf_loss: 692.122314 prob_loss: 392.317535 total_loss 1107.04419
grid: 38 iou_loss: 39.6796265 conf_loss: 2940.94482 prob_loss: 584.173767 total_loss 3564.79834
grid: 19 iou_loss: 20.1870766 conf_loss: 678.909 prob_loss: 369.016296 total_loss 1068.11243
grid: 38 iou_loss: 36.8784866 conf_loss: 2918.10669 prob_loss: 541.558472 total_loss 3496.54346
grid: 19 iou_loss: 22.827879 conf_loss: 665.791138 prob_loss: 397.131195 total_loss 1085.75024
grid: 38 iou_loss: 36.6682739 conf_loss: 2894.15527 prob_loss: 525.914368 total_loss 3456.73779
grid: 19 iou_loss: 19.9354744 conf_loss: 653.168518 prob_loss: 346.853271 total_loss 1019.95728
grid: 38 iou_loss: 31.4933624 conf_loss: 2869.08838 prob_loss: 450.500336 total_loss 3351.08203
grid: 19 iou_loss: 13.2280397 conf_loss: 639.689697 prob_loss: 231.819 total_loss 884.736694
grid: 38 iou_loss: 35.8448486 conf_loss: 2844.04395 prob_loss: 529.823059 total_loss 3409.71191
grid: 19 iou_loss: 23.2581539 conf_loss: 627.171326 prob_loss: 409.014374 total_loss 1059.44385
grid: 38 iou_loss: 28.9285297 conf_loss: 2819.96118 prob_loss: 419.130432 total_loss 3268.02
grid: 19 iou_loss: 17.7735519 conf_loss: 614.898926 prob_loss: 302.814209 total_loss 935.486694
grid: 38 iou_loss: 22.1152554 conf_loss: 2795.89551 prob_loss: 316.325134 total_loss 3134.33594
grid: 19 iou_loss: 17.0755157 conf_loss: 606.050049 prob_loss: 286.621735 total_loss 909.747253
grid: 38 iou_loss: 37.4852943 conf_loss: 2773.20288 prob_loss: 544.452637 total_loss 3355.14087
grid: 19 iou_loss: 25.5551434 conf_loss: 593.78894 prob_loss: 428.554077 total_loss 1047.89819
grid: 38 iou_loss: 43.3539467 conf_loss: 2748.94873 prob_loss: 581.657104 total_loss 3373.96
grid: 19 iou_loss: 22.3558102 conf_loss: 583.762878 prob_loss: 360.585815 total_loss 966.704529
grid: 38 iou_loss: 25.5126858 conf_loss: 2728.49097 prob_loss: 369.909485 total_loss 3123.91309
grid: 19 iou_loss: 23.1707687 conf_loss: 573.150818 prob_loss: 355.733826 total_loss 952.05542
grid: 38 iou_loss: 31.7709446 conf_loss: 2711.03247 prob_loss: 389.269348 total_loss 3132.07275
grid: 19 iou_loss: 14.5240116 conf_loss: 568.729126 prob_loss: 226.238388 total_loss 809.491516
grid: 38 iou_loss: 40.1396027 conf_loss: 2689.23291 prob_loss: 483.035797 total_loss 3212.40845
grid: 19 iou_loss: 19.1325645 conf_loss: 550.801514 prob_loss: 301.72821 total_loss 871.662292
grid: 38 iou_loss: 39.1578026 conf_loss: 2664.82617 prob_loss: 461.029663 total_loss 3165.01367
grid: 19 iou_loss: 22.6750565 conf_loss: 541.950134 prob_loss: 341.102234 total_loss 905.727417
grid: 38 iou_loss: 22.1398239 conf_loss: 2649.01709 prob_loss: 251.945114 total_loss 2923.10205
grid: 19 iou_loss: 17.7947235 conf_loss: 533.137939 prob_loss: 274.132721 total_loss 825.065369
grid: 38 iou_loss: 31.3372707 conf_loss: 2626.30054 prob_loss: 352.196838 total_loss 3009.83447
grid: 19 iou_loss: 21.8718166 conf_loss: 522.76709 prob_loss: 327.475983 total_loss 872.114868
grid: 38 iou_loss: 22.6329632 conf_loss: 2611.34717 prob_loss: 248.06842 total_loss 2882.04858
mjkvaak commented 4 years ago

Oh, I also ran two otherwise identical settings with same data but with only the names differing and the loss vanished with digits. Must've been something else then: maybe something with the annotations themselvea. Thanks for the effort and sorry for the trouble: this can be closed now as resolved.

hhk7734 commented 4 years ago

Among the problems that need to be solved, It seems that the priority of this is low. So closed. Thanks for reporting the problem :)

mjkvaak commented 4 years ago

Totally understand plus my main idea for posting this was for others facing the same issue to be mindful that the solution might be simply to rename the target classes. Thank you for the effort and keep up the good work!