From 0713fd9784bbd0c67eb82df6f6e2c072a53e09e8 Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Thu, 31 May 2018 11:20:19 +0000
Subject: [PATCH] Merge pull request #936 from IlyaOvodov/Fix_GrayScale_PR

---
 src/detector.c |   41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/detector.c b/src/detector.c
index 8b53907..202fbf9 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -1,8 +1,3 @@
-#ifdef _DEBUG
-#include <stdlib.h> 
-#include <crtdbg.h>  
-#endif
-
 #include "network.h"
 #include "region_layer.h"
 #include "cost_layer.h"
@@ -92,7 +87,8 @@
     load_args args = {0};
     args.w = net.w;
     args.h = net.h;
-    args.paths = paths;
+	args.c = net.c;
+	args.paths = paths;
     args.n = imgs;
     args.m = plist->size;
     args.classes = classes;
@@ -194,7 +190,7 @@
         avg_loss = avg_loss*.9 + loss*.1;
 
         i = get_current_batch(net);
-        printf("\n %d: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), loss, avg_loss, get_current_rate(net), (what_time_is_it_now()-time), i*imgs);
+        printf("\n %d: %f, %f avg loss, %f rate, %lf seconds, %d images\n", get_current_batch(net), loss, avg_loss, get_current_rate(net), (what_time_is_it_now()-time), i*imgs);
 
 #ifdef OPENCV
 		if(!dont_show)
@@ -221,8 +217,25 @@
     sprintf(buff, "%s/%s_final.weights", backup_directory, base);
     save_weights(net, buff);
 
-	//cvReleaseImage(&img);
-	//cvDestroyAllWindows();
+#ifdef OPENCV
+	cvReleaseImage(&img);
+	cvDestroyAllWindows();
+#endif
+
+	// free memory
+	pthread_join(load_thread, 0);
+	free_data(buffer);
+
+	free(base);
+	free(paths);
+	free_list_contents(plist);
+	free_list(plist);
+
+	free_list_contents_kvp(options);
+	free_list(options);
+
+	free(nets);
+	free_network(net);
 }
 
 
@@ -376,6 +389,7 @@
 	load_args args = { 0 };
 	args.w = net.w;
 	args.h = net.h;
+	args.c = net.c;
 	args.type = IMAGE_DATA;
 	//args.type = LETTERBOX_DATA;
 
@@ -470,7 +484,7 @@
 
 	for (i = 0; i < m; ++i) {
 		char *path = paths[i];
-		image orig = load_image_color(path, 0, 0);
+		image orig = load_image(path, 0, 0, net.c);
 		image sized = resize_image(orig, net.w, net.h);
 		char *id = basecfg(path);
 		network_predict(net, sized.data);
@@ -583,6 +597,7 @@
 	load_args args = { 0 };
 	args.w = net.w;
 	args.h = net.h;
+	args.c = net.c;
 	args.type = IMAGE_DATA;
 	//args.type = LETTERBOX_DATA;
 
@@ -1081,7 +1096,7 @@
             if(!input) return;
             strtok(input, "\n");
         }
-        image im = load_image_color(input,0,0);
+        image im = load_image(input,0,0,net.c);
 		int letterbox = 0;
         //image sized = resize_image(im, net.w, net.h);
 		image sized = letterbox_image(im, net.w, net.h); letterbox = 1;
@@ -1150,6 +1165,7 @@
 
 	// free memory
 	free_ptrs(names, net.layers[net.n - 1].classes);
+	free_list_contents_kvp(options);
 	free_list(options);
 
 	int i;
@@ -1236,6 +1252,9 @@
 				if (filename[strlen(filename) - 1] == 0x0d) filename[strlen(filename) - 1] = 0;
         demo(cfg, weights, thresh, hier_thresh, cam_index, filename, names, classes, frame_skip, prefix, out_filename,
 			http_stream_port, dont_show, ext_output);
+
+		free_list_contents_kvp(options);
+		free_list(options);
     }
 	else printf(" There isn't such command: %s", argv[2]);
 }

--
Gitblit v1.10.0