From d0b9326a352ed2fbc3ae66fdef40b4533a2f211d Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 11 Aug 2015 06:22:27 +0000
Subject: [PATCH] Hacks to get nightmare to not break gridsizing

---
 src/network.c |   46 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/src/network.c b/src/network.c
index c691600..ff5cd61 100644
--- a/src/network.c
+++ b/src/network.c
@@ -4,13 +4,16 @@
 #include "image.h"
 #include "data.h"
 #include "utils.h"
+#include "blas.h"
 
 #include "crop_layer.h"
 #include "connected_layer.h"
 #include "convolutional_layer.h"
 #include "deconvolutional_layer.h"
 #include "detection_layer.h"
+#include "normalization_layer.h"
 #include "maxpool_layer.h"
+#include "avgpool_layer.h"
 #include "cost_layer.h"
 #include "softmax_layer.h"
 #include "dropout_layer.h"
@@ -27,6 +30,8 @@
             return "connected";
         case MAXPOOL:
             return "maxpool";
+        case AVGPOOL:
+            return "avgpool";
         case SOFTMAX:
             return "softmax";
         case DETECTION:
@@ -39,6 +44,8 @@
             return "cost";
         case ROUTE:
             return "route";
+        case NORMALIZATION:
+            return "normalization";
         default:
             break;
     }
@@ -62,10 +69,15 @@
     int i;
     for(i = 0; i < net.n; ++i){
         layer l = net.layers[i];
+        if(l.delta){
+            scal_cpu(l.outputs * l.batch, 0, l.delta, 1);
+        }
         if(l.type == CONVOLUTIONAL){
             forward_convolutional_layer(l, state);
         } else if(l.type == DECONVOLUTIONAL){
             forward_deconvolutional_layer(l, state);
+        } else if(l.type == NORMALIZATION){
+            forward_normalization_layer(l, state);
         } else if(l.type == DETECTION){
             forward_detection_layer(l, state);
         } else if(l.type == CONNECTED){
@@ -78,6 +90,8 @@
             forward_softmax_layer(l, state);
         } else if(l.type == MAXPOOL){
             forward_maxpool_layer(l, state);
+        } else if(l.type == AVGPOOL){
+            forward_avgpool_layer(l, state);
         } else if(l.type == DROPOUT){
             forward_dropout_layer(l, state);
         } else if(l.type == ROUTE){
@@ -112,13 +126,20 @@
 
 float get_network_cost(network net)
 {
-    if(net.layers[net.n-1].type == COST){
-        return net.layers[net.n-1].output[0];
+    int i;
+    float sum = 0;
+    int count = 0;
+    for(i = 0; i < net.n; ++i){
+        if(net.layers[net.n-1].type == COST){
+            sum += net.layers[net.n-1].output[0];
+            ++count;
+        }
+        if(net.layers[net.n-1].type == DETECTION){
+            sum += net.layers[net.n-1].cost[0];
+            ++count;
+        }
     }
-    if(net.layers[net.n-1].type == DETECTION){
-        return net.layers[net.n-1].cost[0];
-    }
-    return 0;
+    return sum/count;
 }
 
 int get_predicted_class_network(network net)
@@ -147,8 +168,12 @@
             backward_convolutional_layer(l, state);
         } else if(l.type == DECONVOLUTIONAL){
             backward_deconvolutional_layer(l, state);
+        } else if(l.type == NORMALIZATION){
+            backward_normalization_layer(l, state);
         } else if(l.type == MAXPOOL){
             if(i != 0) backward_maxpool_layer(l, state);
+        } else if(l.type == AVGPOOL){
+            backward_avgpool_layer(l, state);
         } else if(l.type == DROPOUT){
             backward_dropout_layer(l, state);
         } else if(l.type == DETECTION){
@@ -167,9 +192,9 @@
 
 float train_network_datum(network net, float *x, float *y)
 {
-    #ifdef GPU
+#ifdef GPU
     if(gpu_index >= 0) return train_network_datum_gpu(net, x, y);
-    #endif
+#endif
     network_state state;
     state.input = x;
     state.delta = 0;
@@ -266,6 +291,11 @@
             resize_convolutional_layer(&l, w, h);
         }else if(l.type == MAXPOOL){
             resize_maxpool_layer(&l, w, h);
+        }else if(l.type == AVGPOOL){
+            resize_avgpool_layer(&l, w, h);
+            break;
+        }else if(l.type == NORMALIZATION){
+            resize_normalization_layer(&l, w, h);
         }else{
             error("Cannot resize this type of layer");
         }

--
Gitblit v1.10.0