From 89c11f83ed49c58c3031200d8ed053b4f671db09 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Wed, 16 May 2018 12:05:46 +0000
Subject: [PATCH] Fixed darknet.py - uses batch=1 by default

---
 src/network.c                        |    9 +++++++--
 build/darknet/x64/darknet.py         |    6 +++++-
 build/darknet/x64/darknet_python.cmd |    8 ++++++++
 src/network.h                        |    1 +
 darknet.py                           |    6 +++++-
 src/data.c                           |    5 ++++-
 6 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/build/darknet/x64/darknet.py b/build/darknet/x64/darknet.py
index 700ed0c..2deff4f 100644
--- a/build/darknet/x64/darknet.py
+++ b/build/darknet/x64/darknet.py
@@ -160,6 +160,10 @@
 load_net.argtypes = [c_char_p, c_char_p, c_int]
 load_net.restype = c_void_p
 
+load_net_custom = lib.load_network_custom
+load_net_custom.argtypes = [c_char_p, c_char_p, c_int, c_int]
+load_net_custom.restype = c_void_p
+
 do_nms_obj = lib.do_nms_obj
 do_nms_obj.argtypes = [POINTER(DETECTION), c_int, c_int, c_float]
 
@@ -325,7 +329,7 @@
     if not os.path.exists(metaPath):
         raise ValueError("Invalid data file path `"+os.path.abspath(metaPath)+"`")
     if netMain is None:
-        netMain = load_net(configPath.encode("ascii"), weightPath.encode("ascii"), 0)
+        netMain = load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)  # batch size = 1
     if metaMain is None:
         metaMain = load_meta(metaPath.encode("ascii"))
     if altNames is None:
diff --git a/build/darknet/x64/darknet_python.cmd b/build/darknet/x64/darknet_python.cmd
index b45f679..2c9243c 100644
--- a/build/darknet/x64/darknet_python.cmd
+++ b/build/darknet/x64/darknet_python.cmd
@@ -6,4 +6,12 @@
 C:\Python27\python.exe darknet.py
 
 
+
+rem Python 3.6
+rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install numpy
+rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install scikit-image
+rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install scipy
+
+rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\python.exe darknet.py
+
 pause
\ No newline at end of file
diff --git a/darknet.py b/darknet.py
index 700ed0c..2deff4f 100644
--- a/darknet.py
+++ b/darknet.py
@@ -160,6 +160,10 @@
 load_net.argtypes = [c_char_p, c_char_p, c_int]
 load_net.restype = c_void_p
 
+load_net_custom = lib.load_network_custom
+load_net_custom.argtypes = [c_char_p, c_char_p, c_int, c_int]
+load_net_custom.restype = c_void_p
+
 do_nms_obj = lib.do_nms_obj
 do_nms_obj.argtypes = [POINTER(DETECTION), c_int, c_int, c_float]
 
@@ -325,7 +329,7 @@
     if not os.path.exists(metaPath):
         raise ValueError("Invalid data file path `"+os.path.abspath(metaPath)+"`")
     if netMain is None:
-        netMain = load_net(configPath.encode("ascii"), weightPath.encode("ascii"), 0)
+        netMain = load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)  # batch size = 1
     if metaMain is None:
         metaMain = load_meta(metaPath.encode("ascii"))
     if altNames is None:
diff --git a/src/data.c b/src/data.c
index 3b014b4..4bb1b0f 100644
--- a/src/data.c
+++ b/src/data.c
@@ -137,7 +137,10 @@
 {
     box_label *boxes = calloc(1, sizeof(box_label));
     FILE *file = fopen(filename, "r");
-    if(!file) file_error(filename);
+	if (!file) {
+		printf("Can't open label file. \n");
+		file_error(filename);
+	}
     float x, y, h, w;
     int id;
     int count = 0;
diff --git a/src/network.c b/src/network.c
index 81b53f3..f992fef 100644
--- a/src/network.c
+++ b/src/network.c
@@ -30,11 +30,11 @@
 #include "yolo_layer.h"
 #include "parser.h"
 
-network *load_network(char *cfg, char *weights, int clear)
+network *load_network_custom(char *cfg, char *weights, int clear, int batch)
 {
 	printf(" Try to load cfg: %s, weights: %s, clear = %d \n", cfg, weights, clear);
 	network *net = calloc(1, sizeof(network));
-	*net = parse_network_cfg(cfg);
+	*net = parse_network_cfg_custom(cfg, batch);
 	if (weights && weights[0] != 0) {
 		load_weights(net, weights);
 	}
@@ -42,6 +42,11 @@
 	return net;
 }
 
+network *load_network(char *cfg, char *weights, int clear)
+{
+	return load_network_custom(cfg, weights, clear, 0);
+}
+
 int get_current_batch(network net)
 {
     int batch_num = (*net.seen)/(net.batch*net.subdivisions);
diff --git a/src/network.h b/src/network.h
index fe160a9..01a6ab9 100644
--- a/src/network.h
+++ b/src/network.h
@@ -138,6 +138,7 @@
 YOLODLL_API detection *make_network_boxes(network *net, float thresh, int *num);
 YOLODLL_API void free_detections(detection *dets, int n);
 YOLODLL_API void reset_rnn(network *net);
+YOLODLL_API network *load_network_custom(char *cfg, char *weights, int clear, int batch);
 YOLODLL_API network *load_network(char *cfg, char *weights, int clear);
 YOLODLL_API float *network_predict_image(network *net, image im);
 YOLODLL_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show);

--
Gitblit v1.10.0