There appears to be an issue caused by the difference between Windows vs Linux line-endings, when running a COCO evaluation. When running the detector on the COCO dataset, e.g. "detector valid cfg/coco.data ../cfg/yolov3.cfg ../weights/yolov3.weights", a "results/coco_results.json" file is generated. After running on a Linux system, an example of the last few lines of this file is:
{"image_id":284282, "category_id":65, "bbox":[0.000000, 18.000229, 106.680382, 308.656616], "score":0.010804},
{"image_id":284282, "category_id":47, "bbox":[350.594543, 30.112206, 36.254150, 39.351761], "score":0.112114}
]
However, when run under Windows, the output includes a trailing comma after the last entry, e.g.:
{"image_id":284282, "category_id":65, "bbox":[0.000000, 18.000229, 106.680382, 308.656616], "score":0.010804},
{"image_id":284282, "category_id":47, "bbox":[350.594543, 30.112206, 36.254150, 39.351761], "score":0.112114},
]
Because a trailing comma is typically not allowed in a JSON object, the subsequent COCO evaluation python scripts fail when parsing a coco_results.json file generated from a darknet run on Windows.
Currently, detector.c (lines 557-559) and coco.c (lines 221-223) are:
fseek(fp, -2, SEEK_CUR);
fprintf(fp, "\n]\n");
fclose(fp);
After running darknet, an ASCII dump of the end of coco_results.json from Linux is:
162447420 9 . 3 5 1 7 6 1 ] , sp " s c o r
162447440 e " : 0 . 1 1 2 1 1 4 } nl ] nl
From Windows, it's:
163477420 sp " s c o r e " : 0 . 1 3 1 5 5
163477440 7 } , cr nl ] cr nl
So for coco evaluation to work properly on Windows, it looks like the fseek() offset should be -3 on Windows and -2 on Linux. Another solution may be to pass a flag to print_cocos() so that the comma delimiter is not printed for the last line.
@robertc-git Hi, Thanks!
I added this fix: https://github.com/AlexeyAB/darknet/commit/378d49e1c33cc8c064cb27c99815de0698b2ad93
Hi, Thanks for the quick fix! Should the same fix also be made to coco.c (lines 221-223)?
Most helpful comment
Hi, Thanks for the quick fix! Should the same fix also be made to coco.c (lines 221-223)?