From e63b3a6f912cc2b1f6f00f2a9d342624a06dc3a4 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 09 Jun 2015 18:17:46 +0000
Subject: [PATCH] syncing messed something up

---
 src/detection_layer.c |   93 ++++++++++++++++++----------------------------
 1 files changed, 37 insertions(+), 56 deletions(-)

diff --git a/src/detection_layer.c b/src/detection_layer.c
index 395146b..fcae7f3 100644
--- a/src/detection_layer.c
+++ b/src/detection_layer.c
@@ -330,9 +330,9 @@
             l.output[out_i++] = mask*state.input[in_i++];
         }
     }
-    if(l.does_cost && state.train && 0){
-        int count = 0;
-        float avg = 0;
+    float avg_iou = 0;
+    int count = 0;
+    if(l.does_cost && state.train){
         *(l.cost) = 0;
         int size = get_detection_layer_output_size(l) * l.batch;
         memset(l.delta, 0, size * sizeof(float));
@@ -343,63 +343,44 @@
                 *(l.cost) += pow(state.truth[j] - l.output[j], 2);
                 l.delta[j] =  state.truth[j] - l.output[j];
             }
-            box truth;
-            truth.x = state.truth[j+0];
-            truth.y = state.truth[j+1];
-            truth.w = state.truth[j+2];
-            truth.h = state.truth[j+3];
-            box out;
-            out.x = l.output[j+0];
-            out.y = l.output[j+1];
-            out.w = l.output[j+2];
-            out.h = l.output[j+3];
-            if(!(truth.w*truth.h)) continue;
-            //printf("iou: %f\n", iou);
-            dbox d = diou(out, truth);
-            l.delta[j+0] = d.dx;
-            l.delta[j+1] = d.dy;
-            l.delta[j+2] = d.dw;
-            l.delta[j+3] = d.dh;
 
-            int sqr = 1;
-            if(sqr){
-                truth.w *= truth.w;
-                truth.h *= truth.h;
-                out.w *= out.w;
-                out.h *= out.h;
-            }
-            float iou = box_iou(truth, out);
-            *(l.cost) += pow((1-iou), 2);
-            avg += iou;
+            box truth;
+            truth.x = state.truth[j+0]/7;
+            truth.y = state.truth[j+1]/7;
+            truth.w = pow(state.truth[j+2], 2);
+            truth.h = pow(state.truth[j+3], 2);
+            box out;
+            out.x = l.output[j+0]/7;
+            out.y = l.output[j+1]/7;
+            out.w = pow(l.output[j+2], 2);
+            out.h = pow(l.output[j+3], 2);
+
+            if(!(truth.w*truth.h)) continue;
+            float iou = box_iou(out, truth);
+            avg_iou += iou;
             ++count;
+            dbox delta = diou(out, truth);
+
+            l.delta[j+0] = 10 * delta.dx/7;
+            l.delta[j+1] = 10 * delta.dy/7;
+            l.delta[j+2] = 10 * delta.dw * 2 * sqrt(out.w);
+            l.delta[j+3] = 10 * delta.dh * 2 * sqrt(out.h);
+
+
+            *(l.cost) += pow((1-iou), 2);
+            l.delta[j+0] = 4 * (state.truth[j+0] - l.output[j+0]);
+            l.delta[j+1] = 4 * (state.truth[j+1] - l.output[j+1]);
+            l.delta[j+2] = 4 * (state.truth[j+2] - l.output[j+2]);
+            l.delta[j+3] = 4 * (state.truth[j+3] - l.output[j+3]);
+            if(0){
+                for (j = offset; j < offset+classes; ++j) {
+                    if(state.truth[j]) state.truth[j] = iou;
+                    l.delta[j] =  state.truth[j] - l.output[j];
+                }
+            }
         }
-        fprintf(stderr, "Avg IOU: %f\n", avg/count);
+        printf("Avg IOU: %f\n", avg_iou/count);
     }
-    /*
-       int count = 0;
-       for(i = 0; i < l.batch*locations; ++i){
-       for(j = 0; j < l.classes+l.background; ++j){
-       printf("%f, ", l.output[count++]);
-       }
-       printf("\n");
-       for(j = 0; j < l.coords; ++j){
-       printf("%f, ", l.output[count++]);
-       }
-       printf("\n");
-       }
-     */
-    /*
-       if(l.background || 1){
-       for(i = 0; i < l.batch*locations; ++i){
-       int index = i*(l.classes+l.coords+l.background);
-       for(j= 0; j < l.classes; ++j){
-       if(state.truth[index+j+l.background]){
-//dark_zone(l, j, index, state);
-}
-}
-}
-}
-     */
 }
 
 void backward_detection_layer(const detection_layer l, network_state state)

--
Gitblit v1.10.0