From b3c4fc9f223d9b6f50a1652d8d116fcdcc16f2e8 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sun, 27 Nov 2016 04:02:46 +0000
Subject: [PATCH] :fire: ARE YOU NOT ENTERTAINED :fire:
---
src/detector.c | 63 ++++++++++++++++---------------
1 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/src/detector.c b/src/detector.c
index 695b068..31c44c0 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -66,7 +66,7 @@
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 @@
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_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 @@
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 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 @@
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 @@
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 @@
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 @@
}
}
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 @@
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 @@
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");
--
Gitblit v1.10.0