|
|
|
@ -271,78 +271,37 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int |
|
|
|
|
free(boxes); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fill_truth_detection(char *path, float *truth, int classes, int num_boxes, int flip, int background, float dx, float dy, float sx, float sy) |
|
|
|
|
void fill_truth_detection(char *path, float *truth, int classes, int flip, float dx, float dy, float sx, float sy) |
|
|
|
|
{ |
|
|
|
|
char *labelpath = find_replace(path, "JPEGImages", "labels"); |
|
|
|
|
char *labelpath = 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"); |
|
|
|
|
int count = 0; |
|
|
|
|
box_label *boxes = read_boxes(labelpath, &count); |
|
|
|
|
randomize_boxes(boxes, count); |
|
|
|
|
correct_boxes(boxes, count, dx, dy, sx, sy, flip); |
|
|
|
|
if(count > 17) count = 17; |
|
|
|
|
float x,y,w,h; |
|
|
|
|
float left, top, right, bot; |
|
|
|
|
int id; |
|
|
|
|
int i; |
|
|
|
|
if(background){ |
|
|
|
|
for(i = 0; i < num_boxes*num_boxes*(4+classes+background); i += 4+classes+background){ |
|
|
|
|
truth[i] = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) { |
|
|
|
|
left = boxes[i].left * sx - dx; |
|
|
|
|
right = boxes[i].right * sx - dx; |
|
|
|
|
top = boxes[i].top * sy - dy; |
|
|
|
|
bot = boxes[i].bottom* sy - dy; |
|
|
|
|
x = boxes[i].x; |
|
|
|
|
y = boxes[i].y; |
|
|
|
|
w = boxes[i].w; |
|
|
|
|
h = boxes[i].h; |
|
|
|
|
id = boxes[i].id; |
|
|
|
|
|
|
|
|
|
if(flip){ |
|
|
|
|
float swap = left; |
|
|
|
|
left = 1. - right; |
|
|
|
|
right = 1. - swap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
left = constrain(0, 1, left); |
|
|
|
|
right = constrain(0, 1, right); |
|
|
|
|
top = constrain(0, 1, top); |
|
|
|
|
bot = constrain(0, 1, bot); |
|
|
|
|
|
|
|
|
|
x = (left+right)/2; |
|
|
|
|
y = (top+bot)/2; |
|
|
|
|
w = (right - left); |
|
|
|
|
h = (bot - top); |
|
|
|
|
|
|
|
|
|
if (x <= 0 || x >= 1 || y <= 0 || y >= 1) continue; |
|
|
|
|
|
|
|
|
|
int col = (int)(x*num_boxes); |
|
|
|
|
int row = (int)(y*num_boxes); |
|
|
|
|
|
|
|
|
|
x = x*num_boxes - col; |
|
|
|
|
y = y*num_boxes - row; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
float maxwidth = distance_from_edge(i, num_boxes); |
|
|
|
|
float maxheight = distance_from_edge(j, num_boxes); |
|
|
|
|
w = w/maxwidth; |
|
|
|
|
h = h/maxheight; |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
w = constrain(0, 1, w); |
|
|
|
|
h = constrain(0, 1, h); |
|
|
|
|
if (w < .01 || h < .01) continue; |
|
|
|
|
if(1){ |
|
|
|
|
w = pow(w, 1./2.); |
|
|
|
|
h = pow(h, 1./2.); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int index = (col+row*num_boxes)*(4+classes+background); |
|
|
|
|
if(truth[index+classes+background+2]) continue; |
|
|
|
|
if(background) truth[index++] = 0; |
|
|
|
|
truth[index+id] = 1; |
|
|
|
|
index += classes; |
|
|
|
|
truth[index++] = x; |
|
|
|
|
truth[index++] = y; |
|
|
|
|
truth[index++] = w; |
|
|
|
|
truth[index++] = h; |
|
|
|
|
truth[i*5] = id; |
|
|
|
|
truth[i*5+2] = x; |
|
|
|
|
truth[i*5+3] = y; |
|
|
|
|
truth[i*5+4] = w; |
|
|
|
|
truth[i*5+5] = h; |
|
|
|
|
} |
|
|
|
|
free(boxes); |
|
|
|
|
} |
|
|
|
@ -485,6 +444,7 @@ data load_data_region(int n, char **paths, int m, int w, int h, int size, int cl |
|
|
|
|
d.X.vals = calloc(d.X.rows, sizeof(float*)); |
|
|
|
|
d.X.cols = h*w*3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int k = size*size*(5+classes); |
|
|
|
|
d.y = make_matrix(n, k); |
|
|
|
|
for(i = 0; i < n; ++i){ |
|
|
|
@ -641,7 +601,7 @@ data load_data_swag(char **paths, int n, int classes, float jitter) |
|
|
|
|
return d; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
data load_data_detection(int n, char **paths, int m, int classes, int w, int h, int num_boxes, int background) |
|
|
|
|
data load_data_detection(int n, int boxes, char **paths, int m, int w, int h, int classes, float jitter) |
|
|
|
|
{ |
|
|
|
|
char **random_paths = get_random_paths(paths, n, m); |
|
|
|
|
int i; |
|
|
|
@ -652,16 +612,15 @@ data load_data_detection(int n, char **paths, int m, int classes, int w, int h, |
|
|
|
|
d.X.vals = calloc(d.X.rows, sizeof(float*)); |
|
|
|
|
d.X.cols = h*w*3; |
|
|
|
|
|
|
|
|
|
int k = num_boxes*num_boxes*(4+classes+background); |
|
|
|
|
d.y = make_matrix(n, k); |
|
|
|
|
d.y = make_matrix(n, 5*boxes); |
|
|
|
|
for(i = 0; i < n; ++i){ |
|
|
|
|
image orig = load_image_color(random_paths[i], 0, 0); |
|
|
|
|
|
|
|
|
|
int oh = orig.h; |
|
|
|
|
int ow = orig.w; |
|
|
|
|
|
|
|
|
|
int dw = ow/10; |
|
|
|
|
int dh = oh/10; |
|
|
|
|
int dw = (ow*jitter); |
|
|
|
|
int dh = (oh*jitter); |
|
|
|
|
|
|
|
|
|
int pleft = rand_uniform(-dw, dw); |
|
|
|
|
int pright = rand_uniform(-dw, dw); |
|
|
|
@ -674,13 +633,6 @@ data load_data_detection(int n, char **paths, int m, int classes, int w, int h, |
|
|
|
|
float sx = (float)swidth / ow; |
|
|
|
|
float sy = (float)sheight / oh; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
float angle = rand_uniform()*.1 - .05; |
|
|
|
|
image rot = rotate_image(orig, angle); |
|
|
|
|
free_image(orig); |
|
|
|
|
orig = rot; |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
int flip = rand_r(&data_seed)%2; |
|
|
|
|
image cropped = crop_image(orig, pleft, ptop, swidth, sheight); |
|
|
|
|
|
|
|
|
@ -691,7 +643,7 @@ data load_data_detection(int n, char **paths, int m, int classes, int w, int h, |
|
|
|
|
if(flip) flip_image(sized); |
|
|
|
|
d.X.vals[i] = sized.data; |
|
|
|
|
|
|
|
|
|
fill_truth_detection(random_paths[i], d.y.vals[i], classes, num_boxes, flip, background, dx, dy, 1./sx, 1./sy); |
|
|
|
|
fill_truth_detection(random_paths[i], d.y.vals[i], classes, flip, dx, dy, 1./sx, 1./sy); |
|
|
|
|
|
|
|
|
|
free_image(orig); |
|
|
|
|
free_image(cropped); |
|
|
|
@ -700,6 +652,7 @@ data load_data_detection(int n, char **paths, int m, int classes, int w, int h, |
|
|
|
|
return d; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void *load_thread(void *ptr) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
@ -717,7 +670,7 @@ void *load_thread(void *ptr) |
|
|
|
|
} else if (a.type == STUDY_DATA){ |
|
|
|
|
*a.d = load_data_study(a.paths, a.n, a.m, a.labels, a.classes, a.min, a.max, a.size); |
|
|
|
|
} else if (a.type == DETECTION_DATA){ |
|
|
|
|
*a.d = load_data_detection(a.n, a.paths, a.m, a.classes, a.w, a.h, a.num_boxes, a.background); |
|
|
|
|
*a.d = load_data_detection(a.n, a.num_boxes, a.paths, a.m, a.classes, a.w, a.h, a.background); |
|
|
|
|
} else if (a.type == WRITING_DATA){ |
|
|
|
|
*a.d = load_data_writing(a.paths, a.n, a.m, a.w, a.h, a.out_w, a.out_h); |
|
|
|
|
} else if (a.type == REGION_DATA){ |
|
|
|
|