mirror of https://github.com/AlexeyAB/darknet.git
..... and back to coords
This commit is contained in:
parent
ad59d7e68e
commit
81751b47dd
43
src/data.c
43
src/data.c
|
@ -114,7 +114,7 @@ void fill_truth_detection(char *path, float *truth, int classes, int num_boxes,
|
||||||
int count = 0;
|
int count = 0;
|
||||||
box *boxes = read_boxes(labelpath, &count);
|
box *boxes = read_boxes(labelpath, &count);
|
||||||
randomize_boxes(boxes, count);
|
randomize_boxes(boxes, count);
|
||||||
float l,r,t,b;
|
float x,y,w,h;
|
||||||
int id;
|
int id;
|
||||||
int i;
|
int i;
|
||||||
if(background){
|
if(background){
|
||||||
|
@ -123,46 +123,41 @@ void fill_truth_detection(char *path, float *truth, int classes, int num_boxes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 0; i < count; ++i){
|
for(i = 0; i < count; ++i){
|
||||||
l = boxes[i].left;
|
x = boxes[i].x;
|
||||||
r = boxes[i].right;
|
y = boxes[i].y;
|
||||||
t = boxes[i].top;
|
w = boxes[i].w;
|
||||||
b = boxes[i].bottom;
|
h = boxes[i].h;
|
||||||
id = boxes[i].id;
|
id = boxes[i].id;
|
||||||
|
|
||||||
if(flip){
|
if(flip){
|
||||||
float left = l;
|
x = 1-x;
|
||||||
float right = r;
|
|
||||||
r = 1-left;
|
|
||||||
l = 1-right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l = l*sx-dx;
|
x = x*sx-dx;
|
||||||
r = r*sx-dx;
|
y = y*sy-dy;
|
||||||
t = t*sy-dy;
|
w = w*sx;
|
||||||
b = b*sy-dy;
|
h = h*sy;
|
||||||
|
|
||||||
float x = (l+r)/2.;
|
|
||||||
float y = (t+b)/2.;
|
|
||||||
|
|
||||||
if (x < 0 || x >= 1 || y < 0 || y >= 1) continue;
|
if (x < 0 || x >= 1 || y < 0 || y >= 1) continue;
|
||||||
|
|
||||||
int i = (int)(x*num_boxes);
|
int i = (int)(x*num_boxes);
|
||||||
int j = (int)(y*num_boxes);
|
int j = (int)(y*num_boxes);
|
||||||
|
|
||||||
l = constrain(0, 1, l);
|
x = x*num_boxes - i;
|
||||||
r = constrain(0, 1, r);
|
y = y*num_boxes - j;
|
||||||
t = constrain(0, 1, t);
|
|
||||||
b = constrain(0, 1, b);
|
w = constrain(0, 1, w);
|
||||||
|
h = constrain(0, 1, h);
|
||||||
|
|
||||||
int index = (i+j*num_boxes)*(4+classes+background);
|
int index = (i+j*num_boxes)*(4+classes+background);
|
||||||
if(truth[index+classes+background+2]) continue;
|
if(truth[index+classes+background+2]) continue;
|
||||||
if(background) truth[index++] = 0;
|
if(background) truth[index++] = 0;
|
||||||
truth[index+id] = 1;
|
truth[index+id] = 1;
|
||||||
index += classes;
|
index += classes;
|
||||||
truth[index++] = l;
|
truth[index++] = y;
|
||||||
truth[index++] = r;
|
truth[index++] = x;
|
||||||
truth[index++] = t;
|
truth[index++] = w;
|
||||||
truth[index++] = b;
|
truth[index++] = h;
|
||||||
}
|
}
|
||||||
free(boxes);
|
free(boxes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,9 @@ void validate_detection(char *cfgfile, char *weightfile)
|
||||||
int classes = 20;
|
int classes = 20;
|
||||||
int background = 0;
|
int background = 0;
|
||||||
int nuisance = 1;
|
int nuisance = 1;
|
||||||
int num_output = 7*7*(4+classes+background+nuisance);
|
int num_boxes = 7;
|
||||||
|
int per_box = 4+classes+background+nuisance;
|
||||||
|
int num_output = num_boxes*num_boxes*per_box;
|
||||||
|
|
||||||
int m = plist->size;
|
int m = plist->size;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -135,16 +137,19 @@ void validate_detection(char *cfgfile, char *weightfile)
|
||||||
matrix pred = network_predict_data(net, val);
|
matrix pred = network_predict_data(net, val);
|
||||||
int j, k, class;
|
int j, k, class;
|
||||||
for(j = 0; j < pred.rows; ++j){
|
for(j = 0; j < pred.rows; ++j){
|
||||||
for(k = 0; k < pred.cols; k += classes+4+background+nuisance){
|
for(k = 0; k < pred.cols; k += per_box){
|
||||||
float scale = 1.;
|
float scale = 1.;
|
||||||
|
int index = k/per_box;
|
||||||
|
int row = index / num_boxes;
|
||||||
|
int col = index % num_boxes;
|
||||||
if (nuisance) scale = 1.-pred.vals[j][k];
|
if (nuisance) scale = 1.-pred.vals[j][k];
|
||||||
for (class = 0; class < classes; ++class){
|
for (class = 0; class < classes; ++class){
|
||||||
int ci = k+classes+background+nuisance;
|
int ci = k+classes+background+nuisance;
|
||||||
float left = pred.vals[j][ci + 0];
|
float y = (pred.vals[j][ci + 0] + row)/num_boxes;
|
||||||
float right = pred.vals[j][ci + 1];
|
float x = (pred.vals[j][ci + 1] + col)/num_boxes;
|
||||||
float top = pred.vals[j][ci + 2];
|
float h = pred.vals[j][ci + 2];
|
||||||
float bot = pred.vals[j][ci + 3];
|
float w = pred.vals[j][ci + 3];
|
||||||
printf("%d %d %f %f %f %f %f\n", (i-1)*m/splits + j, class, scale*pred.vals[j][k+class+background+nuisance], left, right, top, bot);
|
printf("%d %d %f %f %f %f %f\n", (i-1)*m/splits + j, class, scale*pred.vals[j][k+class+background+nuisance], y, x, h, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue