From fc2996968ecaa8ce36508f4036bea082684850a1 Mon Sep 17 00:00:00 2001 From: Josh Veitch-Michaelis Date: Fri, 15 Mar 2019 21:58:53 +0000 Subject: [PATCH 1/4] find annotation files for tiff images --- src/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.c b/src/utils.c index b4d17c23..904aa2e0 100644 --- a/src/utils.c +++ b/src/utils.c @@ -252,6 +252,8 @@ void replace_image_to_label(const char* input_path, char* output_path) find_replace_extension(output_path, ".BMP", ".txt", output_path); find_replace_extension(output_path, ".ppm", ".txt", output_path); find_replace_extension(output_path, ".PPM", ".txt", output_path); + find_replace_extension(output_path, ".tiff", ".txt", output_path); + find_replace_extension(output_path, ".TIFF", ".txt", output_path); } float sec(clock_t clocks) From 1a3971f5f72db513f388dfa0617aa07afcb3022b Mon Sep 17 00:00:00 2001 From: Josh Veitch-Michaelis Date: Fri, 15 Mar 2019 22:01:04 +0000 Subject: [PATCH 2/4] alert user if annotation file doesn't exist Currently darknet will continue silently if an annotation file isn't found. This can happen when the user provides an unsupported image format and the extension is not replaced. Probably this function should be modified to change any extension to .txt, since OpenCV (for example) supports many image extensions. --- src/utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils.c b/src/utils.c index 904aa2e0..e11b4f3b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -254,6 +254,13 @@ void replace_image_to_label(const char* input_path, char* output_path) find_replace_extension(output_path, ".PPM", ".txt", output_path); find_replace_extension(output_path, ".tiff", ".txt", output_path); find_replace_extension(output_path, ".TIFF", ".txt", output_path); + + // Check file ends with txt and exists: + char output_path_ext[3]; + memcpy( output_path_ext, &output_path[strlen(output_path)-3], 3); + if( strcmp("txt", output_path_ext) != 0){ + fprintf(stderr, "Failed to find valid annotation file: %s \n", output_path_ext); + } } float sec(clock_t clocks) From f73ace38fafa605d21d5c8e86f16c30f72dfb8ac Mon Sep 17 00:00:00 2001 From: Josh Veitch-Michaelis Date: Fri, 15 Mar 2019 22:10:38 +0000 Subject: [PATCH 3/4] fix output message --- src/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index e11b4f3b..2ab20acc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -255,11 +255,11 @@ void replace_image_to_label(const char* input_path, char* output_path) find_replace_extension(output_path, ".tiff", ".txt", output_path); find_replace_extension(output_path, ".TIFF", ".txt", output_path); - // Check file ends with txt and exists: + // Check file ends with txt: char output_path_ext[3]; memcpy( output_path_ext, &output_path[strlen(output_path)-3], 3); if( strcmp("txt", output_path_ext) != 0){ - fprintf(stderr, "Failed to find valid annotation file: %s \n", output_path_ext); + fprintf(stderr, "Failed to infer label file name (check image extension is supported): %s \n", output_path); } } From 328cce0bf53c22ed2ea829a13614060bf41b47d2 Mon Sep 17 00:00:00 2001 From: Josh Veitch-Michaelis Date: Fri, 15 Mar 2019 22:51:15 +0000 Subject: [PATCH 4/4] cleaner check for extension --- src/utils.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils.c b/src/utils.c index 2ab20acc..a2a6178a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -256,10 +256,13 @@ void replace_image_to_label(const char* input_path, char* output_path) find_replace_extension(output_path, ".TIFF", ".txt", output_path); // Check file ends with txt: - char output_path_ext[3]; - memcpy( output_path_ext, &output_path[strlen(output_path)-3], 3); - if( strcmp("txt", output_path_ext) != 0){ - fprintf(stderr, "Failed to infer label file name (check image extension is supported): %s \n", output_path); + if(strlen(output_path) > 4) { + char *output_path_ext = output_path + strlen(output_path) - 4; + if( strcmp(".txt", output_path_ext) != 0){ + fprintf(stderr, "Failed to infer label file name (check image extension is supported): %s \n", output_path); + } + }else{ + fprintf(stderr, "Label file name is too short: %s \n", output_path); } }