mirror of https://github.com/pjreddie/darknet.git
Use set_file_ending for label file paths
This commit is contained in:
parent
f6d8617360
commit
62fe374edc
45
src/data.c
45
src/data.c
|
@ -218,9 +218,7 @@ void fill_truth_swag(char *path, float *truth, int classes, int flip, float dx,
|
|||
char labelpath[4096];
|
||||
find_replace(path, "images", "labels", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "labels", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
int count = 0;
|
||||
box_label *boxes = read_boxes(labelpath, &count);
|
||||
|
@ -256,11 +254,8 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int
|
|||
char labelpath[4096];
|
||||
find_replace(path, "images", "labels", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "labels", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".png", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
int count = 0;
|
||||
box_label *boxes = read_boxes(labelpath, &count);
|
||||
randomize_boxes(boxes, count);
|
||||
|
@ -365,9 +360,8 @@ void fill_truth_iseg(char *path, int num_boxes, float *truth, int classes, int w
|
|||
char labelpath[4096];
|
||||
find_replace(path, "images", "mask", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "mask", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
FILE *file = fopen(labelpath, "r");
|
||||
if(!file) file_error(labelpath);
|
||||
char buff[32788];
|
||||
|
@ -412,10 +406,8 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
|
|||
find_replace(labelpath, "JPEGImages", "labels", labelpath);
|
||||
|
||||
find_replace(labelpath, "raw", "labels", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".png", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
int count = 0;
|
||||
box_label *boxes = read_boxes(labelpath, &count);
|
||||
randomize_boxes(boxes, count);
|
||||
|
@ -556,18 +548,7 @@ matrix load_regression_labels_paths(char **paths, int n, int k)
|
|||
char labelpath[4096];
|
||||
find_replace(paths[i], "images", "labels", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "labels", labelpath);
|
||||
find_replace(labelpath, ".BMP", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPeG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".Jpeg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".PNG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".TIF", ".txt", labelpath);
|
||||
find_replace(labelpath, ".bmp", ".txt", labelpath);
|
||||
find_replace(labelpath, ".jpeg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".png", ".txt", labelpath);
|
||||
find_replace(labelpath, ".tif", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
FILE *file = fopen(labelpath, "r");
|
||||
for(j = 0; j < k; ++j){
|
||||
|
@ -599,7 +580,7 @@ matrix load_tags_paths(char **paths, int n, int k)
|
|||
for(i = 0; i < n; ++i){
|
||||
char label[4096];
|
||||
find_replace(paths[i], "images", "labels", label);
|
||||
find_replace(label, ".jpg", ".txt", label);
|
||||
set_file_ending(label, ".txt", label);
|
||||
FILE *file = fopen(label, "r");
|
||||
if (!file) continue;
|
||||
//++count;
|
||||
|
@ -639,9 +620,8 @@ image get_segmentation_image(char *path, int w, int h, int classes)
|
|||
char labelpath[4096];
|
||||
find_replace(path, "images", "mask", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "mask", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
image mask = make_image(w, h, classes);
|
||||
FILE *file = fopen(labelpath, "r");
|
||||
if(!file) file_error(labelpath);
|
||||
|
@ -666,9 +646,8 @@ image get_segmentation_image2(char *path, int w, int h, int classes)
|
|||
char labelpath[4096];
|
||||
find_replace(path, "images", "mask", labelpath);
|
||||
find_replace(labelpath, "JPEGImages", "mask", labelpath);
|
||||
find_replace(labelpath, ".jpg", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPG", ".txt", labelpath);
|
||||
find_replace(labelpath, ".JPEG", ".txt", labelpath);
|
||||
set_file_ending(labelpath, ".txt", labelpath);
|
||||
|
||||
image mask = make_image(w, h, classes+1);
|
||||
int i;
|
||||
for(i = 0; i < w*h; ++i){
|
||||
|
|
15
src/utils.c
15
src/utils.c
|
@ -229,6 +229,21 @@ void find_replace(char *str, char *orig, char *rep, char *output)
|
|||
sprintf(output, "%s%s%s", buffer, rep, p+strlen(orig));
|
||||
}
|
||||
|
||||
void set_file_ending(char *file_name, char *new_file_ending, char *output)
|
||||
{
|
||||
int last_index = -1;
|
||||
int len = strlen(file_name);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (file_name[i] == '.') {
|
||||
last_index = i;
|
||||
}
|
||||
}
|
||||
if (last_index < 0) {
|
||||
last_index = len;
|
||||
}
|
||||
sprintf(output, "%.*s%s", last_index, output, new_file_ending);
|
||||
}
|
||||
|
||||
float sec(clock_t clocks)
|
||||
{
|
||||
return (float)clocks/CLOCKS_PER_SEC;
|
||||
|
|
|
@ -27,6 +27,7 @@ void write_all(int fd, char *buffer, size_t bytes);
|
|||
int read_all_fail(int fd, char *buffer, size_t bytes);
|
||||
int write_all_fail(int fd, char *buffer, size_t bytes);
|
||||
void find_replace(char *str, char *orig, char *rep, char *output);
|
||||
void set_file_ending(char *file_name, char *new_file_ending, char *output);
|
||||
void malloc_error();
|
||||
void file_error(char *s);
|
||||
void strip(char *s);
|
||||
|
|
Loading…
Reference in New Issue