From 0d6b107ed20c22412ccf3a5056cffdb35bc25534 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Wed, 16 Nov 2016 06:53:58 +0000
Subject: [PATCH] hey
---
src/detector.c | 88 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 72 insertions(+), 16 deletions(-)
diff --git a/src/detector.c b/src/detector.c
index f18ae51..3853ebb 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -75,8 +75,27 @@
pthread_t load_thread = load_data(args);
clock_t time;
+ int count = 0;
//while(i*imgs < N*120){
while(get_current_batch(net) < net.max_batches){
+ if(l.random && count++%10 == 0){
+ printf("Resizing\n");
+ int dim = (rand() % 10 + 10) * 32;
+ //int dim = (rand() % 4 + 16) * 32;
+ printf("%d\n", dim);
+ args.w = dim;
+ args.h = dim;
+
+ pthread_join(load_thread, 0);
+ train = buffer;
+ free_data(train);
+ load_thread = load_data(args);
+
+ for(i = 0; i < ngpus; ++i){
+ resize_network(nets + i, dim, dim);
+ }
+ net = nets[0];
+ }
time=clock();
pthread_join(load_thread, 0);
train = buffer;
@@ -117,13 +136,15 @@
i = get_current_batch(net);
printf("%d: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), loss, avg_loss, get_current_rate(net), sec(clock()-time), i*imgs);
- if(i%1000==0 || (i < 1000 && i%100 == 0)){
+ if(i%100==0 || (i < 1000 && i%100 == 0)){
+ if(ngpus != 1) sync_nets(nets, ngpus, 0);
char buff[256];
sprintf(buff, "%s/%s_%d.weights", backup_directory, base, i);
save_weights(net, buff);
}
free_data(train);
}
+ if(ngpus != 1) sync_nets(nets, ngpus, 0);
char buff[256];
sprintf(buff, "%s/%s_final.weights", backup_directory, base);
save_weights(net, buff);
@@ -183,6 +204,29 @@
}
}
+void print_imagenet_detections(FILE *fp, int id, box *boxes, float **probs, int total, int classes, int w, int h, int *map)
+{
+ int i, j;
+ for(i = 0; i < total; ++i){
+ float xmin = boxes[i].x - boxes[i].w/2.;
+ float xmax = boxes[i].x + boxes[i].w/2.;
+ float ymin = boxes[i].y - boxes[i].h/2.;
+ float ymax = boxes[i].y + boxes[i].h/2.;
+
+ if (xmin < 0) xmin = 0;
+ if (ymin < 0) ymin = 0;
+ if (xmax > w) xmax = w;
+ if (ymax > h) ymax = h;
+
+ 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);
+ }
+ }
+}
+
void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
{
list *options = read_data_cfg(datacfg);
@@ -190,15 +234,25 @@
char *name_list = option_find_str(options, "names", "data/names.list");
char *prefix = option_find_str(options, "results", "results");
char **names = get_labels(name_list);
+ char *mapf = option_find_str(options, "map", 0);
+ int *map = 0;
+ if (mapf) map = read_map(mapf);
char buff[1024];
- int coco = option_find_int_quiet(options, "coco", 0);
- FILE *coco_fp = 0;
- if(coco){
+ 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);
- coco_fp = fopen(buff, "w");
- fprintf(coco_fp, "[\n");
+ 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);
@@ -230,10 +284,10 @@
int i=0;
int t;
- float thresh = .001;
- float nms = .5;
+ float thresh = .005;
+ float nms = .45;
- int nthreads = 2;
+ int nthreads = 4;
image *val = calloc(nthreads, sizeof(image));
image *val_resized = calloc(nthreads, sizeof(image));
image *buf = calloc(nthreads, sizeof(image));
@@ -274,9 +328,11 @@
int h = val[t].h;
get_region_boxes(l, w, h, thresh, probs, boxes, 0);
if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, classes, nms);
- if(coco_fp){
- print_cocos(coco_fp, path, boxes, probs, l.w*l.h*l.n, classes, w, h);
- }else{
+ 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);
+ } else {
print_detector_detections(fps, id, boxes, probs, l.w*l.h*l.n, classes, w, h);
}
free(id);
@@ -287,10 +343,10 @@
for(j = 0; j < classes; ++j){
fclose(fps[j]);
}
- if(coco_fp){
- fseek(coco_fp, -2, SEEK_CUR);
- fprintf(coco_fp, "\n]\n");
- fclose(coco_fp);
+ if(coco){
+ fseek(fp, -2, SEEK_CUR);
+ fprintf(fp, "\n]\n");
+ fclose(fp);
}
fprintf(stderr, "Total Detection Time: %f Seconds\n", (double)(time(0) - start));
}
--
Gitblit v1.10.0