From fdcc096694791f92d2cff0e4fd74fbabfca12936 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 24 Jul 2015 22:14:23 +0000
Subject: [PATCH] Fixed some problems with visualizing networks

---
 src/captcha.c |   50 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/src/captcha.c b/src/captcha.c
index ccefa45..f47b35e 100644
--- a/src/captcha.c
+++ b/src/captcha.c
@@ -41,13 +41,13 @@
     //net.seen=0;
     int imgs = 1024;
     int i = net.seen/imgs;
-    int solved = 1;
+    int solved = 0;
     list *plist;
     char **labels = get_labels("/data/captcha/reimgs.labels2.list");
     if (solved){
         plist = get_paths("/data/captcha/reimgs.solved.list");
     }else{
-        plist = get_paths("/data/captcha/reimgs.train.list");
+        plist = get_paths("/data/captcha/reimgs.raw.list");
     }
     char **paths = (char **)list_to_array(plist);
     printf("%d\n", plist->size);
@@ -96,7 +96,6 @@
     srand(2222222);
     int i = 0;
     char **names = get_labels("/data/captcha/reimgs.labels2.list");
-    clock_t time;
     char input[256];
     int indexes[26];
     while(1){
@@ -110,7 +109,6 @@
         }
         image im = load_image_color(input, net.w, net.h);
         float *X = im.data;
-        time=clock();
         float *predictions = network_predict(net, X);
         top_predictions(net, 26, indexes);
         //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
@@ -126,6 +124,47 @@
     }
 }
 
+void valid_captcha(char *cfgfile, char *weightfile, char *filename)
+{
+    char **labels = get_labels("/data/captcha/reimgs.labels.list");
+    network net = parse_network_cfg(cfgfile);
+    if(weightfile){
+        load_weights(&net, weightfile);
+    }
+    list *plist = get_paths("/data/captcha/reimgs.fg.list");
+    char **paths = (char **)list_to_array(plist);
+    int N = plist->size;
+    int outputs = net.outputs;
+
+    set_batch_network(&net, 1);
+    srand(2222222);
+    int i, j;
+    for(i = 0; i < N; ++i){
+        if (i%100 == 0) fprintf(stderr, "%d\n", i);
+        image im = load_image_color(paths[i], net.w, net.h);
+        float *X = im.data;
+        float *predictions = network_predict(net, X);
+        //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
+        int truth = -1;
+        for(j = 0; j < 13; ++j){
+            if (strstr(paths[i], labels[j])) truth = j;
+        }
+        if (truth == -1){
+            fprintf(stderr, "bad: %s\n", paths[i]);
+            return;
+        }
+        printf("%d, ", truth);
+        for(j = 0; j < outputs; ++j){
+            if (j != 0) printf(", ");
+            printf("%f", predictions[j]);
+        }
+        printf("\n");
+        fflush(stdout);
+        free_image(im);
+        if (filename) break;
+    }
+}
+
 void train_captcha(char *cfgfile, char *weightfile)
 {
     data_seed = time(0);
@@ -189,7 +228,6 @@
     srand(2222222);
     int i = 0;
     char **names = get_labels("/data/captcha/reimgs.labels.list");
-    clock_t time;
     char input[256];
     int indexes[13];
     while(1){
@@ -203,7 +241,6 @@
         }
         image im = load_image_color(input, net.w, net.h);
         float *X = im.data;
-        time=clock();
         float *predictions = network_predict(net, X);
         top_predictions(net, 13, indexes);
         //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
@@ -400,6 +437,7 @@
     char *filename = (argc > 5) ? argv[5]: 0;
     if(0==strcmp(argv[2], "train")) train_captcha2(cfg, weights);
     else if(0==strcmp(argv[2], "test")) test_captcha2(cfg, weights, filename);
+    else if(0==strcmp(argv[2], "valid")) valid_captcha(cfg, weights, filename);
     //if(0==strcmp(argv[2], "test")) test_captcha(cfg, weights);
     //else if(0==strcmp(argv[2], "encode")) encode_captcha(cfg, weights);
     //else if(0==strcmp(argv[2], "decode")) decode_captcha(cfg, weights);

--
Gitblit v1.10.0