|
|
|
@ -1187,7 +1187,7 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_index, const char *filename) |
|
|
|
|
void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_index, const char *filename, int benchmark) |
|
|
|
|
{ |
|
|
|
|
#ifdef OPENCV |
|
|
|
|
printf("Classifier Demo\n"); |
|
|
|
@ -1220,22 +1220,35 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind |
|
|
|
|
int* indexes = (int*)calloc(top, sizeof(int)); |
|
|
|
|
|
|
|
|
|
if(!cap) error("Couldn't connect to webcam.\n"); |
|
|
|
|
create_window_cv("Classifier", 0, 512, 512); |
|
|
|
|
if (!benchmark) create_window_cv("Classifier", 0, 512, 512); |
|
|
|
|
float fps = 0; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
double start_time = get_time_point(); |
|
|
|
|
float avg_fps = 0; |
|
|
|
|
int frame_counter = 0; |
|
|
|
|
|
|
|
|
|
while(1){ |
|
|
|
|
struct timeval tval_before, tval_after, tval_result; |
|
|
|
|
gettimeofday(&tval_before, NULL); |
|
|
|
|
|
|
|
|
|
//image in = get_image_from_stream(cap);
|
|
|
|
|
image in = get_image_from_stream_cpp(cap); |
|
|
|
|
image in_s = resize_image(in, net.w, net.h); |
|
|
|
|
image in_s, in; |
|
|
|
|
if (!benchmark) { |
|
|
|
|
in = get_image_from_stream_cpp(cap); |
|
|
|
|
in_s = resize_image(in, net.w, net.h); |
|
|
|
|
show_image(in, "Classifier"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
static image tmp; |
|
|
|
|
if (!tmp.data) tmp = make_image(net.w, net.h, 3); |
|
|
|
|
in_s = tmp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double time = get_time_point(); |
|
|
|
|
float *predictions = network_predict(net, in_s.data); |
|
|
|
|
double frame_time_ms = (get_time_point() - time)/1000; |
|
|
|
|
frame_counter++; |
|
|
|
|
|
|
|
|
|
if(net.hierarchy) hierarchy_predictions(predictions, net.outputs, net.hierarchy, 1); |
|
|
|
|
top_predictions(net, top, indexes); |
|
|
|
@ -1244,17 +1257,21 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind |
|
|
|
|
printf("\033[2J"); |
|
|
|
|
printf("\033[1;1H"); |
|
|
|
|
#endif |
|
|
|
|
printf("\nFPS: %.2f \n", fps); |
|
|
|
|
printf("\rFPS: %.2f \t AVG_FPS = %.2f ", fps, avg_fps); |
|
|
|
|
|
|
|
|
|
for(i = 0; i < top; ++i){ |
|
|
|
|
if (!benchmark) { |
|
|
|
|
printf("\n"); |
|
|
|
|
for (i = 0; i < top; ++i) { |
|
|
|
|
int index = indexes[i]; |
|
|
|
|
printf("%.1f%%: %s\n", predictions[index]*100, names[index]); |
|
|
|
|
printf("%.1f%%: %s\n", predictions[index] * 100, names[index]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free_image(in_s); |
|
|
|
|
free_image(in); |
|
|
|
|
|
|
|
|
|
wait_key_cv(10);// cvWaitKey(10);
|
|
|
|
|
int c = wait_key_cv(10);// cvWaitKey(10);
|
|
|
|
|
if (c == 27 || c == 1048603) break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//gettimeofday(&tval_after, NULL);
|
|
|
|
|
//timersub(&tval_after, &tval_before, &tval_result);
|
|
|
|
@ -1262,6 +1279,14 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind |
|
|
|
|
float curr = 1000.f / frame_time_ms; |
|
|
|
|
if (fps == 0) fps = curr; |
|
|
|
|
else fps = .9*fps + .1*curr; |
|
|
|
|
|
|
|
|
|
float spent_time = (get_time_point() - start_time) / 1000000; |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -1299,6 +1324,7 @@ void run_classifier(int argc, char **argv) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int dont_show = find_arg(argc, argv, "-dont_show"); |
|
|
|
|
int benchmark = find_arg(argc, argv, "-benchmark"); |
|
|
|
|
int dontuse_opencv = find_arg(argc, argv, "-dontuse_opencv"); |
|
|
|
|
int show_imgs = find_arg(argc, argv, "-show_imgs"); |
|
|
|
|
int calc_topk = find_arg(argc, argv, "-topk"); |
|
|
|
@ -1314,7 +1340,7 @@ void run_classifier(int argc, char **argv) |
|
|
|
|
if(0==strcmp(argv[2], "predict")) predict_classifier(data, cfg, weights, filename, top); |
|
|
|
|
else if(0==strcmp(argv[2], "try")) try_classifier(data, cfg, weights, filename, atoi(layer_s)); |
|
|
|
|
else if(0==strcmp(argv[2], "train")) train_classifier(data, cfg, weights, gpus, ngpus, clear, dontuse_opencv, dont_show, mjpeg_port, calc_topk, show_imgs); |
|
|
|
|
else if(0==strcmp(argv[2], "demo")) demo_classifier(data, cfg, weights, cam_index, filename); |
|
|
|
|
else if(0==strcmp(argv[2], "demo")) demo_classifier(data, cfg, weights, cam_index, filename, benchmark); |
|
|
|
|
else if(0==strcmp(argv[2], "gun")) gun_classifier(data, cfg, weights, cam_index, filename); |
|
|
|
|
else if(0==strcmp(argv[2], "threat")) threat_classifier(data, cfg, weights, cam_index, filename); |
|
|
|
|
else if(0==strcmp(argv[2], "test")) test_classifier(data, cfg, weights, layer); |
|
|
|
|