From 0cbfa4646128206300b9a30586615c3698abfb76 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 08 May 2015 17:33:47 +0000
Subject: [PATCH] stuff

---
 src/parser.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/src/parser.c b/src/parser.c
index d7c4a31..46bd8ef 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -14,6 +14,7 @@
 #include "softmax_layer.h"
 #include "dropout_layer.h"
 #include "detection_layer.h"
+#include "route_layer.h"
 #include "list.h"
 #include "option_list.h"
 #include "utils.h"
@@ -34,6 +35,7 @@
 int is_cost(section *s);
 int is_detection(section *s);
 int is_normalization(section *s);
+int is_route(section *s);
 list *read_cfg(char *filename);
 
 void free_section(section *s)
@@ -165,7 +167,9 @@
     int coords = option_find_int(options, "coords", 1);
     int classes = option_find_int(options, "classes", 1);
     int rescore = option_find_int(options, "rescore", 1);
-    detection_layer *layer = make_detection_layer(params.batch, params.inputs, classes, coords, rescore);
+    int nuisance = option_find_int(options, "nuisance", 0);
+    int background = option_find_int(options, "background", 1);
+    detection_layer *layer = make_detection_layer(params.batch, params.inputs, classes, coords, rescore, background, nuisance);
     option_unused(options);
     return layer;
 }
@@ -184,6 +188,9 @@
     int crop_height = option_find_int(options, "crop_height",1);
     int crop_width = option_find_int(options, "crop_width",1);
     int flip = option_find_int(options, "flip",0);
+    float angle = option_find_float(options, "angle",0);
+    float saturation = option_find_float(options, "saturation",1);
+    float exposure = option_find_float(options, "exposure",1);
 
     int batch,h,w,c;
     h = params.h;
@@ -192,7 +199,7 @@
     batch=params.batch;
     if(!(h && w && c)) error("Layer before crop layer must output image.");
 
-    crop_layer *layer = make_crop_layer(batch,h,w,c,crop_height,crop_width,flip);
+    crop_layer *layer = make_crop_layer(batch,h,w,c,crop_height,crop_width,flip, angle, saturation, exposure);
     option_unused(options);
     return layer;
 }
@@ -241,6 +248,32 @@
     return layer;
 }
 
+route_layer *parse_route(list *options, size_params params, network net)
+{
+    char *l = option_find(options, "layers");   
+    int len = strlen(l);
+    if(!l) error("Route Layer must specify input layers");
+    int n = 1;
+    int i;
+    for(i = 0; i < len; ++i){
+        if (l[i] == ',') ++n;
+    }
+
+    int *layers = calloc(n, sizeof(int));
+    int *sizes = calloc(n, sizeof(int));
+    for(i = 0; i < n; ++i){
+        int index = atoi(l);
+        l = strchr(l, ',')+1;
+        layers[i] = index;
+        sizes[i] = get_network_output_size_layer(net, index);
+    }
+    int batch = params.batch;
+
+    route_layer *layer = make_route_layer(batch, n, layers, sizes);
+    option_unused(options);
+    return layer;
+}
+
 void parse_net_options(list *options, network *net)
 {
     net->batch = option_find_int(options, "batch",1);
@@ -248,12 +281,16 @@
     net->momentum = option_find_float(options, "momentum", .9);
     net->decay = option_find_float(options, "decay", .0001);
     net->seen = option_find_int(options, "seen",0);
+    int subdivs = option_find_int(options, "subdivisions",1);
+    net->batch /= subdivs;
+    net->subdivisions = subdivs;
 
     net->h = option_find_int_quiet(options, "height",0);
     net->w = option_find_int_quiet(options, "width",0);
     net->c = option_find_int_quiet(options, "channels",0);
     net->inputs = option_find_int_quiet(options, "inputs", net->h * net->w * net->c);
     if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied");
+    option_unused(options);
 }
 
 network parse_network_cfg(char *filename)
@@ -317,6 +354,10 @@
             normalization_layer *layer = parse_normalization(options, params);
             net.types[count] = NORMALIZATION;
             net.layers[count] = layer;
+        }else if(is_route(s)){
+            route_layer *layer = parse_route(options, params, net);
+            net.types[count] = ROUTE;
+            net.layers[count] = layer;
         }else if(is_dropout(s)){
             dropout_layer *layer = parse_dropout(options, params);
             net.types[count] = DROPOUT;
@@ -393,6 +434,10 @@
     return (strcmp(s->type, "[lrnorm]")==0
             || strcmp(s->type, "[localresponsenormalization]")==0);
 }
+int is_route(section *s)
+{
+    return (strcmp(s->type, "[route]")==0);
+}
 
 int read_option(char *s, list *options)
 {
@@ -545,7 +590,7 @@
 void print_detection_cfg(FILE *fp, detection_layer *l, network net, int count)
 {
     fprintf(fp, "[detection]\n");
-    fprintf(fp, "classes=%d\ncoords=%d\nrescore=%d\n", l->classes, l->coords, l->rescore);
+    fprintf(fp, "classes=%d\ncoords=%d\nrescore=%d\nnuisance=%d\n", l->classes, l->coords, l->rescore, l->nuisance);
     fprintf(fp, "\n");
 }
 
@@ -614,6 +659,7 @@
     fread(&net->momentum, sizeof(float), 1, fp);
     fread(&net->decay, sizeof(float), 1, fp);
     fread(&net->seen, sizeof(int), 1, fp);
+    fprintf(stderr, "%f %f %f %d\n", net->learning_rate, net->momentum, net->decay, net->seen);
 
     int i;
     for(i = 0; i < net->n && i < cutoff; ++i){

--
Gitblit v1.10.0