mirror of https://github.com/AlexeyAB/darknet.git
Added flags -benchmark and -benchmark_layers for: ./darknet detector demo
This commit is contained in:
parent
3c134dc033
commit
2652263727
|
@ -396,5 +396,5 @@ void run_coco(int argc, char **argv)
|
|||
else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights);
|
||||
else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights);
|
||||
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, hier_thresh, cam_index, filename, coco_classes, 80, frame_skip,
|
||||
prefix, out_filename, mjpeg_port, json_port, dont_show, ext_output, 0, 0, 0);
|
||||
prefix, out_filename, mjpeg_port, json_port, dont_show, ext_output, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
|
39
src/demo.c
39
src/demo.c
|
@ -80,8 +80,6 @@ void *detect_in_thread(void *ptr)
|
|||
mean_arrays(predictions, NFRAMES, l.outputs, avg);
|
||||
l.output = avg;
|
||||
|
||||
free_image(det_s);
|
||||
|
||||
cv_images[demo_index] = det_img;
|
||||
det_img = cv_images[(demo_index + NFRAMES / 2 + 1) % NFRAMES];
|
||||
demo_index = (demo_index + 1) % NFRAMES;
|
||||
|
@ -104,7 +102,8 @@ double get_wall_time()
|
|||
}
|
||||
|
||||
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes,
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host)
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host,
|
||||
int benchmark, int benchmark_layers)
|
||||
{
|
||||
letter_box = letter_box_in;
|
||||
in_img = det_img = show_img = NULL;
|
||||
|
@ -122,6 +121,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
net.benchmark_layers = benchmark_layers;
|
||||
fuse_conv_batchnorm(net);
|
||||
calculate_binary_weights(net);
|
||||
srand(2222222);
|
||||
|
@ -202,7 +202,10 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
|
||||
int send_http_post_once = 0;
|
||||
const double start_time_lim = get_time_point();
|
||||
double before = get_wall_time();
|
||||
double before = get_time_point();
|
||||
double start_time = get_time_point();
|
||||
float avg_fps = 0;
|
||||
int frame_counter = 0;
|
||||
|
||||
while(1){
|
||||
++count;
|
||||
|
@ -211,7 +214,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
int local_nboxes = nboxes;
|
||||
detection *local_dets = dets;
|
||||
|
||||
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
|
||||
if (!benchmark) if (pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
|
||||
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
|
||||
|
||||
//if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results
|
||||
|
@ -242,10 +245,10 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
}
|
||||
}
|
||||
|
||||
draw_detections_cv_v3(show_img, local_dets, local_nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output);
|
||||
if (!benchmark) draw_detections_cv_v3(show_img, local_dets, local_nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output);
|
||||
free_detections(local_dets, local_nboxes);
|
||||
|
||||
printf("\nFPS:%.1f\n", fps);
|
||||
printf("\nFPS:%.1f \t AVG_FPS:%.1f\n", fps, avg_fps);
|
||||
|
||||
if(!prefix){
|
||||
if (!dont_show) {
|
||||
|
@ -282,9 +285,11 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
printf("\n cvWriteFrame \n");
|
||||
}
|
||||
|
||||
|
||||
pthread_join(fetch_thread, 0);
|
||||
pthread_join(detect_thread, 0);
|
||||
if (!benchmark) {
|
||||
pthread_join(fetch_thread, 0);
|
||||
free_image(det_s);
|
||||
}
|
||||
|
||||
if (time_limit_sec > 0 && (get_time_point() - start_time_lim)/1000000 > time_limit_sec) {
|
||||
printf(" start_time_lim = %f, get_time_point() = %f, time spent = %f \n", start_time_lim, get_time_point(), get_time_point() - start_time_lim);
|
||||
|
@ -294,7 +299,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
if (flag_exit == 1) break;
|
||||
|
||||
if(delay == 0){
|
||||
release_mat(&show_img);
|
||||
if(!benchmark) release_mat(&show_img);
|
||||
show_img = det_img;
|
||||
}
|
||||
det_img = in_img;
|
||||
|
@ -308,8 +313,17 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
//float curr = 1./(after - before);
|
||||
double after = get_time_point(); // more accurate time measurements
|
||||
float curr = 1000000. / (after - before);
|
||||
fps = curr;
|
||||
fps = fps*0.9 + curr*0.1;
|
||||
before = after;
|
||||
|
||||
float spent_time = (get_time_point() - start_time) / 1000000;
|
||||
frame_counter++;
|
||||
if (spent_time >= 3.0f) {
|
||||
//printf(" spent_time = %f \n", spent_time);
|
||||
avg_fps = frame_counter / spent_time;
|
||||
frame_counter = 0;
|
||||
start_time = get_time_point();
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("input video stream closed. \n");
|
||||
|
@ -345,7 +359,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
|||
}
|
||||
#else
|
||||
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes,
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host)
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host,
|
||||
int benchmark, int benchmark_layers)
|
||||
{
|
||||
fprintf(stderr, "Demo needs OpenCV for webcam images.\n");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes,
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host);
|
||||
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host, int benchmark, int benchmark_layers);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1589,7 +1589,10 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
|
|||
void run_detector(int argc, char **argv)
|
||||
{
|
||||
int dont_show = find_arg(argc, argv, "-dont_show");
|
||||
int benchmark = find_arg(argc, argv, "-benchmark");
|
||||
int benchmark_layers = find_arg(argc, argv, "-benchmark_layers");
|
||||
if (benchmark_layers) benchmark = 1;
|
||||
if (benchmark) dont_show = 1;
|
||||
int show = find_arg(argc, argv, "-show");
|
||||
int letter_box = find_arg(argc, argv, "-letter_box");
|
||||
int calc_map = find_arg(argc, argv, "-map");
|
||||
|
@ -1667,7 +1670,7 @@ void run_detector(int argc, char **argv)
|
|||
if (strlen(filename) > 0)
|
||||
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,
|
||||
mjpeg_port, json_port, dont_show, ext_output, letter_box, time_limit_sec, http_post_host);
|
||||
mjpeg_port, json_port, dont_show, ext_output, letter_box, time_limit_sec, http_post_host, benchmark, benchmark_layers);
|
||||
|
||||
free_list_contents_kvp(options);
|
||||
free_list(options);
|
||||
|
|
|
@ -359,5 +359,5 @@ void run_yolo(int argc, char **argv)
|
|||
else if(0==strcmp(argv[2], "valid")) validate_yolo(cfg, weights);
|
||||
else if(0==strcmp(argv[2], "recall")) validate_yolo_recall(cfg, weights);
|
||||
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, hier_thresh, cam_index, filename, voc_names, 20, frame_skip,
|
||||
prefix, out_filename, mjpeg_port, json_port, dont_show, ext_output, 0, 0, 0);
|
||||
prefix, out_filename, mjpeg_port, json_port, dont_show, ext_output, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue