From a6b2511a566f77a0838dc1dd0d5f3e3c49a8faa0 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sat, 25 Jun 2016 23:13:54 +0000
Subject: [PATCH] idk
---
src/data.c | 101 +++++++++++++-------------------------------------
1 files changed, 27 insertions(+), 74 deletions(-)
diff --git a/src/data.c b/src/data.c
index b0368ee..fcbdfc9 100644
--- a/src/data.c
+++ b/src/data.c
@@ -271,78 +271,37 @@
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, int num_boxes, 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 > num_boxes) count = num_boxes;
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;
+
+ for (i = 0; i < count; ++i) {
+ 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+0] = id;
+ truth[i*5+1] = x;
+ truth[i*5+2] = y;
+ truth[i*5+3] = w;
+ truth[i*5+4] = h;
}
free(boxes);
}
@@ -485,6 +444,7 @@
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 @@
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, char **paths, int m, int w, int h, int boxes, int classes, float jitter)
{
char **random_paths = get_random_paths(paths, n, m);
int i;
@@ -652,16 +612,15 @@
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 @@
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 @@
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], boxes, d.y.vals[i], classes, flip, dx, dy, 1./sx, 1./sy);
free_image(orig);
free_image(cropped);
@@ -700,6 +652,7 @@
return d;
}
+
void *load_thread(void *ptr)
{
@@ -716,12 +669,12 @@
*a.d = load_data_augment(a.paths, a.n, a.m, a.labels, a.classes, a.min, a.max, a.size);
} 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);
} 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){
*a.d = load_data_region(a.n, a.paths, a.m, a.w, a.h, a.num_boxes, a.classes, a.jitter);
+ } else if (a.type == DETECTION_DATA){
+ *a.d = load_data_detection(a.n, a.paths, a.m, a.w, a.h, a.num_boxes, a.classes, a.jitter);
} else if (a.type == SWAG_DATA){
*a.d = load_data_swag(a.paths, a.n, a.classes, a.jitter);
} else if (a.type == COMPARE_DATA){
--
Gitblit v1.10.0