From 89c11f83ed49c58c3031200d8ed053b4f671db09 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Wed, 16 May 2018 15:05:46 +0300 Subject: [PATCH] Fixed darknet.py - uses batch=1 by default --- build/darknet/x64/darknet.py | 6 +++++- build/darknet/x64/darknet_python.cmd | 8 ++++++++ darknet.py | 6 +++++- src/data.c | 5 ++++- src/network.c | 9 +++++++-- src/network.h | 1 + 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/build/darknet/x64/darknet.py b/build/darknet/x64/darknet.py index 700ed0c8..2deff4fb 100644 --- a/build/darknet/x64/darknet.py +++ b/build/darknet/x64/darknet.py @@ -160,6 +160,10 @@ load_net = lib.load_network 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 @@ def performDetect(imagePath="data/dog.jpg", thresh= 0.25, configPath = "./cfg/yo 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 b45f6798..2c9243c6 100644 --- a/build/darknet/x64/darknet_python.cmd +++ b/build/darknet/x64/darknet_python.cmd @@ -6,4 +6,12 @@ rem C:\Python27\Scripts\pip install scipy 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 700ed0c8..2deff4fb 100644 --- a/darknet.py +++ b/darknet.py @@ -160,6 +160,10 @@ load_net = lib.load_network 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 @@ def performDetect(imagePath="data/dog.jpg", thresh= 0.25, configPath = "./cfg/yo 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 3b014b47..4bb1b0f9 100644 --- a/src/data.c +++ b/src/data.c @@ -137,7 +137,10 @@ box_label *read_boxes(char *filename, int *n) { 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 81b53f39..f992fef9 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 @@ network *load_network(char *cfg, char *weights, int clear) 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 fe160a9b..01a6ab90 100644 --- a/src/network.h +++ b/src/network.h @@ -138,6 +138,7 @@ YOLODLL_API detection *get_network_boxes(network *net, int w, int h, float thres 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);