From c50b0e0c8af16f7ff89ed340fe65d6c22a4eb530 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Wed, 6 Feb 2019 14:38:12 +0300 Subject: [PATCH] Minor Python and C API improvement --- build/darknet/x64/darknet.py | 4 ++-- build/darknet/x64/darknet_video.py | 4 ++-- darknet.py | 2 +- darknet_video.py | 4 ++-- include/darknet.h | 2 ++ src/detector.c | 5 +++-- src/image.h | 2 +- src/network.c | 1 + src/network.h | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/build/darknet/x64/darknet.py b/build/darknet/x64/darknet.py index 3d885d20..81a96d28 100644 --- a/build/darknet/x64/darknet.py +++ b/build/darknet/x64/darknet.py @@ -125,7 +125,7 @@ lib.network_width.restype = c_int lib.network_height.argtypes = [c_void_p] lib.network_height.restype = c_int -predict = lib.network_predict +predict = lib.network_predict_ptr predict.argtypes = [c_void_p, POINTER(c_float)] predict.restype = POINTER(c_float) @@ -151,7 +151,7 @@ free_detections.argtypes = [POINTER(DETECTION), c_int] free_ptrs = lib.free_ptrs free_ptrs.argtypes = [POINTER(c_void_p), c_int] -network_predict = lib.network_predict +network_predict = lib.network_predict_ptr network_predict.argtypes = [c_void_p, POINTER(c_float)] reset_rnn = lib.reset_rnn diff --git a/build/darknet/x64/darknet_video.py b/build/darknet/x64/darknet_video.py index 1a486ced..a02d2782 100644 --- a/build/darknet/x64/darknet_video.py +++ b/build/darknet/x64/darknet_video.py @@ -60,7 +60,7 @@ lib.network_width.restype = c_int lib.network_height.argtypes = [c_void_p] lib.network_height.restype = c_int -predict = lib.network_predict +predict = lib.network_predict_ptr predict.argtypes = [c_void_p, POINTER(c_float)] predict.restype = POINTER(c_float) @@ -88,7 +88,7 @@ free_detections.argtypes = [POINTER(DETECTION), c_int] free_ptrs = lib.free_ptrs free_ptrs.argtypes = [POINTER(c_void_p), c_int] -network_predict = lib.network_predict +network_predict = lib.network_predict_ptr network_predict.argtypes = [c_void_p, POINTER(c_float)] reset_rnn = lib.reset_rnn diff --git a/darknet.py b/darknet.py index 5d0fe14a..81a96d28 100644 --- a/darknet.py +++ b/darknet.py @@ -151,7 +151,7 @@ free_detections.argtypes = [POINTER(DETECTION), c_int] free_ptrs = lib.free_ptrs free_ptrs.argtypes = [POINTER(c_void_p), c_int] -network_predict = lib.network_predict +network_predict = lib.network_predict_ptr network_predict.argtypes = [c_void_p, POINTER(c_float)] reset_rnn = lib.reset_rnn diff --git a/darknet_video.py b/darknet_video.py index 7a8e8f00..19e2345a 100644 --- a/darknet_video.py +++ b/darknet_video.py @@ -60,7 +60,7 @@ lib.network_width.restype = c_int lib.network_height.argtypes = [c_void_p] lib.network_height.restype = c_int -predict = lib.network_predict +predict = lib.network_predict_ptr predict.argtypes = [c_void_p, POINTER(c_float)] predict.restype = POINTER(c_float) @@ -88,7 +88,7 @@ free_detections.argtypes = [POINTER(DETECTION), c_int] free_ptrs = lib.free_ptrs free_ptrs.argtypes = [POINTER(c_void_p), c_int] -network_predict = lib.network_predict +network_predict = lib.network_predict_ptr network_predict.argtypes = [c_void_p, POINTER(c_float)] reset_rnn = lib.reset_rnn diff --git a/include/darknet.h b/include/darknet.h index 93312d28..6675599c 100644 --- a/include/darknet.h +++ b/include/darknet.h @@ -745,6 +745,7 @@ LIB_API void do_nms_obj(detection *dets, int total, int classes, float thresh); // network.h LIB_API float *network_predict(network net, float *input); +LIB_API float *network_predict_ptr(network *net, float *input); LIB_API detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter); LIB_API void free_detections(detection *dets, int n); LIB_API void fuse_conv_batchnorm(network net); @@ -766,6 +767,7 @@ LIB_API void optimize_picture(network *net, image orig, int max_layer, float sca // image.h LIB_API image resize_image(image im, int w, int h); +LIB_API void copy_image_from_bytes(image im, char *pdata); LIB_API image letterbox_image(image im, int w, int h); LIB_API void rgbgr_image(image im); LIB_API image make_image(int w, int h, int c); diff --git a/src/detector.c b/src/detector.c index 79bcdaae..fb29ff18 100644 --- a/src/detector.c +++ b/src/detector.c @@ -247,6 +247,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i if (mean_average_precision > 0) { printf("\n Last accuracy mAP@0.5 = %2.2f %% ", mean_average_precision*100); } + int calc_map_for_each = 4 * train_images_num / (net.batch * net.subdivisions); // calculate mAP for each 4 Epochs + if (calc_map) printf("\n (next mAP calculation at %d iterations) ", (iter_map + calc_map_for_each)); + if (net.cudnn_half) { if (i < net.burn_in * 3) printf("\n Tensor Cores are disabled until the first %d iterations are reached.", 3 * net.burn_in); else printf("\n Tensor Cores are used."); @@ -254,8 +257,6 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i 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); int draw_precision = 0; - int calc_map_for_each = 4 * train_images_num / (net.batch * net.subdivisions); // calculate mAP for each 4 Epochs - if (calc_map) printf(" Next mAP calculation at %d iterations \n", (iter_map + calc_map_for_each)); if (calc_map && (i >= (iter_map + calc_map_for_each) || i == net.max_batches) && i >= net.burn_in && i >= 1000) { if (l.random) { printf("Resizing to initial size: %d x %d \n", init_w, init_h); diff --git a/src/image.h b/src/image.h index dd38d3ff..5c759b4d 100644 --- a/src/image.h +++ b/src/image.h @@ -33,7 +33,7 @@ image random_crop_image(image im, int w, int h); image random_augment_image(image im, float angle, float aspect, int low, int high, int size); void random_distort_image(image im, float hue, float saturation, float exposure); //LIB_API image resize_image(image im, int w, int h); -LIB_API void copy_image_from_bytes(image im, char *pdata); +//LIB_API void copy_image_from_bytes(image im, char *pdata); void fill_image(image m, float s); void letterbox_image_into(image im, int w, int h, image boxed); //LIB_API image letterbox_image(image im, int w, int h); diff --git a/src/network.c b/src/network.c index ef55f7f1..ba8a1721 100644 --- a/src/network.c +++ b/src/network.c @@ -738,6 +738,7 @@ float *network_predict_image(network *net, image im) { //image imr = letterbox_image(im, net->w, net->h); float *p; + if(net->batch != 1) set_batch_network(net, 1); if (im.w == net->w && im.h == net->h) { // Input image is the same size as our net, predict on that image p = network_predict(*net, im.data); diff --git a/src/network.h b/src/network.h index 4247efb0..10bd99f2 100644 --- a/src/network.h +++ b/src/network.h @@ -122,7 +122,7 @@ float train_network_datum(network net, float *x, float *y); matrix network_predict_data(network net, data test); //LIB_API float *network_predict(network net, float *input); -LIB_API float *network_predict_ptr(network *net, float *input); +//LIB_API float *network_predict_ptr(network *net, float *input); float network_accuracy(network net, data d); float *network_accuracies(network net, data d, int n); float network_accuracy_multi(network net, data d, int n);