From 371f21171a2606b4ad5f60651ed6f63cb8d08d99 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Fri, 16 Mar 2018 01:49:01 +0300 Subject: [PATCH] shortcut_layer resize for random=1 --- src/data.c | 4 ++-- src/detector.c | 10 +++++++--- src/network.c | 2 ++ src/shortcut_layer.c | 20 ++++++++++++++++++++ src/shortcut_layer.h | 1 + 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/data.c b/src/data.c index 6187b34c..379756a4 100644 --- a/src/data.c +++ b/src/data.c @@ -269,7 +269,7 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int h = boxes[i].h; id = boxes[i].id; - if (w < .01 || h < .01) continue; + if (w < .001 || h < .001) continue; int col = (int)(x*num_boxes); int row = (int)(y*num_boxes); @@ -326,7 +326,7 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, id = boxes[i].id; // not detect small objects - if ((w < 0.001 || h < 0.001)) { printf("small w = %f, h = %f \n", w, h); continue; } + if ((w < 0.001 || h < 0.001)) continue; truth[i*5+0] = x; truth[i*5+1] = y; diff --git a/src/detector.c b/src/detector.c index 59182c4e..6d60cf00 100644 --- a/src/detector.c +++ b/src/detector.c @@ -43,6 +43,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i float avg_loss = -1; network *nets = calloc(ngpus, sizeof(network)); + int iter_save; + iter_save = 100; + srand(time(0)); int seed = rand(); int i; @@ -89,7 +92,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i args.small_object = l.small_object; args.d = &buffer; args.type = DETECTION_DATA; - args.threads = 4;// 8; + args.threads = 8; // 64 args.angle = net.angle; args.exposure = net.exposure; @@ -113,7 +116,6 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i if(l.random && count++%10 == 0){ printf("Resizing\n"); int dim = (rand() % 12 + (init_w/32 - 5)) * 32; // +-160 - //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); @@ -177,7 +179,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i #endif // OPENCV //if (i % 1000 == 0 || (i < 1000 && i % 100 == 0)) { - if (i % 100 == 0) { + //if (i % 100 == 0) { + if(i >= iter_save) { + iter_save += 100; #ifdef GPU if (ngpus != 1) sync_nets(nets, ngpus, 0); #endif diff --git a/src/network.c b/src/network.c index 964d3e8a..61f87c5d 100644 --- a/src/network.c +++ b/src/network.c @@ -375,6 +375,8 @@ int resize_network(network *net, int w, int h) resize_region_layer(&l, w, h); }else if(l.type == ROUTE){ resize_route_layer(&l, net); + }else if (l.type == SHORTCUT) { + resize_shortcut_layer(&l, w, h); }else if(l.type == REORG){ resize_reorg_layer(&l, w, h); }else if(l.type == AVGPOOL){ diff --git a/src/shortcut_layer.c b/src/shortcut_layer.c index 8bca50fb..01e133b0 100644 --- a/src/shortcut_layer.c +++ b/src/shortcut_layer.c @@ -36,6 +36,26 @@ layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int return l; } +void resize_shortcut_layer(layer *l, int w, int h) +{ + assert(l->w == l->out_w); + assert(l->h == l->out_h); + l->w = l->out_w = w; + l->h = l->out_h = h; + l->outputs = w*h*l->out_c; + l->inputs = l->outputs; + l->delta = realloc(l->delta, l->outputs*l->batch * sizeof(float)); + l->output = realloc(l->output, l->outputs*l->batch * sizeof(float)); + +#ifdef GPU + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); + l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch); +#endif + +} + void forward_shortcut_layer(const layer l, network_state state) { copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1); diff --git a/src/shortcut_layer.h b/src/shortcut_layer.h index c09a8097..912d72e0 100644 --- a/src/shortcut_layer.h +++ b/src/shortcut_layer.h @@ -7,6 +7,7 @@ layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); void forward_shortcut_layer(const layer l, network_state state); void backward_shortcut_layer(const layer l, network_state state); +void resize_shortcut_layer(layer *l, int w, int h); #ifdef GPU void forward_shortcut_layer_gpu(const layer l, network_state state);