🔥 ARE YOU NOT ENTERTAINED 🔥

This commit is contained in:
Joseph Redmon
2016-11-26 20:02:46 -08:00
parent 75fe603722
commit b3c4fc9f22
6 changed files with 314 additions and 40 deletions

View File

@ -66,7 +66,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
args.num_boxes = l.max_boxes;
args.d = &buffer;
args.type = DETECTION_DATA;
args.threads = 4;
args.threads = 8;
args.angle = net.angle;
args.exposure = net.exposure;
@ -81,6 +81,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
if(l.random && count++%10 == 0){
printf("Resizing\n");
int dim = (rand() % 10 + 10) * 32;
if (get_current_batch(net)+100 > net.max_batches) dim = 544;
//int dim = (rand() % 4 + 16) * 32;
printf("%d\n", dim);
args.w = dim;
@ -208,7 +209,7 @@ void print_detector_detections(FILE **fps, char *id, box *boxes, float **probs,
}
}
void print_imagenet_detections(FILE *fp, int id, box *boxes, float **probs, int total, int classes, int w, int h, int *map)
void print_imagenet_detections(FILE *fp, int id, box *boxes, float **probs, int total, int classes, int w, int h)
{
int i, j;
for(i = 0; i < total; ++i){
@ -224,7 +225,6 @@ void print_imagenet_detections(FILE *fp, int id, box *boxes, float **probs, int
for(j = 0; j < classes; ++j){
int class = j;
if (map) class = map[j];
if (probs[i][class]) fprintf(fp, "%d %d %f %f %f %f %f\n", id, j+1, probs[i][class],
xmin, ymin, xmax, ymax);
}
@ -233,6 +233,7 @@ void print_imagenet_detections(FILE *fp, int id, box *boxes, float **probs, int
void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
{
int j;
list *options = read_data_cfg(datacfg);
char *valid_images = option_find_str(options, "valid", "data/train.list");
char *name_list = option_find_str(options, "names", "data/names.list");
@ -242,23 +243,6 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
int *map = 0;
if (mapf) map = read_map(mapf);
char buff[1024];
char *type = option_find_str(options, "eval", "voc");
FILE *fp = 0;
int coco = 0;
int imagenet = 0;
if(0==strcmp(type, "coco")){
snprintf(buff, 1024, "%s/coco_results.json", prefix);
fp = fopen(buff, "w");
fprintf(fp, "[\n");
coco = 1;
} else if(0==strcmp(type, "imagenet")){
snprintf(buff, 1024, "%s/imagenet-detection.txt", prefix);
fp = fopen(buff, "w");
imagenet = 1;
}
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
@ -274,12 +258,31 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
layer l = net.layers[net.n-1];
int classes = l.classes;
int j;
FILE **fps = calloc(classes, sizeof(FILE *));
for(j = 0; j < classes; ++j){
snprintf(buff, 1024, "%s/%s%s.txt", prefix, base, names[j]);
fps[j] = fopen(buff, "w");
char buff[1024];
char *type = option_find_str(options, "eval", "voc");
FILE *fp = 0;
FILE **fps = 0;
int coco = 0;
int imagenet = 0;
if(0==strcmp(type, "coco")){
snprintf(buff, 1024, "%s/coco_results.json", prefix);
fp = fopen(buff, "w");
fprintf(fp, "[\n");
coco = 1;
} else if(0==strcmp(type, "imagenet")){
snprintf(buff, 1024, "%s/imagenet-detection.txt", prefix);
fp = fopen(buff, "w");
imagenet = 1;
classes = 200;
} else {
fps = calloc(classes, sizeof(FILE *));
for(j = 0; j < classes; ++j){
snprintf(buff, 1024, "%s/%s%s.txt", prefix, base, names[j]);
fps[j] = fopen(buff, "w");
}
}
box *boxes = calloc(l.w*l.h*l.n, sizeof(box));
float **probs = calloc(l.w*l.h*l.n, sizeof(float *));
for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = calloc(classes, sizeof(float *));
@ -330,12 +333,12 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
network_predict(net, X);
int w = val[t].w;
int h = val[t].h;
get_region_boxes(l, w, h, thresh, probs, boxes, 0);
get_region_boxes(l, w, h, thresh, probs, boxes, 0, map);
if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, classes, nms);
if (coco){
print_cocos(fp, path, boxes, probs, l.w*l.h*l.n, classes, w, h);
} else if (imagenet){
print_imagenet_detections(fp, i+t-nthreads+1 + 9741, boxes, probs, l.w*l.h*l.n, 200, w, h, map);
print_imagenet_detections(fp, i+t-nthreads+1, boxes, probs, l.w*l.h*l.n, classes, w, h);
} else {
print_detector_detections(fps, id, boxes, probs, l.w*l.h*l.n, classes, w, h);
}
@ -345,7 +348,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
}
}
for(j = 0; j < classes; ++j){
fclose(fps[j]);
if(fps) fclose(fps[j]);
}
if(coco){
fseek(fp, -2, SEEK_CUR);
@ -394,7 +397,7 @@ void validate_detector_recall(char *cfgfile, char *weightfile)
image sized = resize_image(orig, net.w, net.h);
char *id = basecfg(path);
network_predict(net, sized.data);
get_region_boxes(l, 1, 1, thresh, probs, boxes, 1);
get_region_boxes(l, 1, 1, thresh, probs, boxes, 1, 0);
if (nms) do_nms(boxes, probs, l.w*l.h*l.n, 1, nms);
char labelpath[4096];
@ -473,7 +476,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
time=clock();
network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
get_region_boxes(l, 1, 1, thresh, probs, boxes, 0);
get_region_boxes(l, 1, 1, thresh, probs, boxes, 0, 0);
if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, names, alphabet, l.classes);
save_image(im, "predictions");