|
|
@ -55,10 +55,8 @@ float *get_regression_values(char **labels, int n) |
|
|
|
void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear) |
|
|
|
void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef GPU |
|
|
|
#ifdef GPU |
|
|
|
int nthreads = 8; |
|
|
|
|
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
data_seed = time(0); |
|
|
|
|
|
|
|
srand(time(0)); |
|
|
|
srand(time(0)); |
|
|
|
float avg_loss = -1; |
|
|
|
float avg_loss = -1; |
|
|
|
char *base = basecfg(cfgfile); |
|
|
|
char *base = basecfg(cfgfile); |
|
|
@ -68,17 +66,20 @@ void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int |
|
|
|
for(i = 0; i < ngpus; ++i){ |
|
|
|
for(i = 0; i < ngpus; ++i){ |
|
|
|
cuda_set_device(gpus[i]); |
|
|
|
cuda_set_device(gpus[i]); |
|
|
|
nets[i] = parse_network_cfg(cfgfile); |
|
|
|
nets[i] = parse_network_cfg(cfgfile); |
|
|
|
|
|
|
|
if(clear) *nets[i].seen = 0; |
|
|
|
if(weightfile){ |
|
|
|
if(weightfile){ |
|
|
|
load_weights(&(nets[i]), weightfile); |
|
|
|
load_weights(&nets[i], weightfile); |
|
|
|
} |
|
|
|
} |
|
|
|
if(clear) *nets[i].seen = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
network net = nets[0]; |
|
|
|
network net = nets[0]; |
|
|
|
|
|
|
|
for(i = 0; i < ngpus; ++i){ |
|
|
|
|
|
|
|
*nets[i].seen = *net.seen; |
|
|
|
|
|
|
|
nets[i].learning_rate *= ngpus; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); |
|
|
|
int imgs = net.batch * net.subdivisions * ngpus; |
|
|
|
int imgs = net.batch*ngpus/nthreads; |
|
|
|
|
|
|
|
assert(net.batch*ngpus % nthreads == 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); |
|
|
|
list *options = read_data_cfg(datacfg); |
|
|
|
list *options = read_data_cfg(datacfg); |
|
|
|
|
|
|
|
|
|
|
|
char *backup_directory = option_find_str(options, "backup", "/backup/"); |
|
|
|
char *backup_directory = option_find_str(options, "backup", "/backup/"); |
|
|
@ -93,13 +94,10 @@ void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int |
|
|
|
int N = plist->size; |
|
|
|
int N = plist->size; |
|
|
|
clock_t time; |
|
|
|
clock_t time; |
|
|
|
|
|
|
|
|
|
|
|
pthread_t *load_threads = calloc(nthreads, sizeof(pthread_t)); |
|
|
|
|
|
|
|
data *trains = calloc(nthreads, sizeof(data)); |
|
|
|
|
|
|
|
data *buffers = calloc(nthreads, sizeof(data)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_args args = {0}; |
|
|
|
load_args args = {0}; |
|
|
|
args.w = net.w; |
|
|
|
args.w = net.w; |
|
|
|
args.h = net.h; |
|
|
|
args.h = net.h; |
|
|
|
|
|
|
|
args.threads = 16; |
|
|
|
|
|
|
|
|
|
|
|
args.min = net.min_crop; |
|
|
|
args.min = net.min_crop; |
|
|
|
args.max = net.max_crop; |
|
|
|
args.max = net.max_crop; |
|
|
@ -117,36 +115,28 @@ void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int |
|
|
|
args.labels = labels; |
|
|
|
args.labels = labels; |
|
|
|
args.type = CLASSIFICATION_DATA; |
|
|
|
args.type = CLASSIFICATION_DATA; |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
data train; |
|
|
|
args.d = buffers + i; |
|
|
|
data buffer; |
|
|
|
load_threads[i] = load_data_in_thread(args); |
|
|
|
pthread_t load_thread; |
|
|
|
} |
|
|
|
args.d = &buffer; |
|
|
|
|
|
|
|
load_thread = load_data(args); |
|
|
|
|
|
|
|
|
|
|
|
int epoch = (*net.seen)/N; |
|
|
|
int epoch = (*net.seen)/N; |
|
|
|
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ |
|
|
|
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ |
|
|
|
time=clock(); |
|
|
|
time=clock(); |
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
pthread_join(load_threads[i], 0); |
|
|
|
|
|
|
|
trains[i] = buffers[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data train = concat_datas(trains, nthreads); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
pthread_join(load_thread, 0); |
|
|
|
args.d = buffers + i; |
|
|
|
train = buffer; |
|
|
|
load_threads[i] = load_data_in_thread(args); |
|
|
|
load_thread = load_data(args); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Loaded: %lf seconds\n", sec(clock()-time)); |
|
|
|
printf("Loaded: %lf seconds\n", sec(clock()-time)); |
|
|
|
time=clock(); |
|
|
|
time=clock(); |
|
|
|
|
|
|
|
|
|
|
|
float loss = train_networks(nets, ngpus, train); |
|
|
|
float loss = train_networks(nets, ngpus, train, 4); |
|
|
|
if(avg_loss == -1) avg_loss = loss; |
|
|
|
if(avg_loss == -1) avg_loss = loss; |
|
|
|
avg_loss = avg_loss*.9 + loss*.1; |
|
|
|
avg_loss = avg_loss*.9 + loss*.1; |
|
|
|
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen); |
|
|
|
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen); |
|
|
|
free_data(train); |
|
|
|
free_data(train); |
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
free_data(trains[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(*net.seen/N > epoch){ |
|
|
|
if(*net.seen/N > epoch){ |
|
|
|
epoch = *net.seen/N; |
|
|
|
epoch = *net.seen/N; |
|
|
|
char buff[256]; |
|
|
|
char buff[256]; |
|
|
@ -163,14 +153,6 @@ void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int |
|
|
|
sprintf(buff, "%s/%s.weights", backup_directory, base); |
|
|
|
sprintf(buff, "%s/%s.weights", backup_directory, base); |
|
|
|
save_weights(net, buff); |
|
|
|
save_weights(net, buff); |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
pthread_join(load_threads[i], 0); |
|
|
|
|
|
|
|
free_data(buffers[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
free(buffers); |
|
|
|
|
|
|
|
free(trains); |
|
|
|
|
|
|
|
free(load_threads); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free_network(net); |
|
|
|
free_network(net); |
|
|
|
free_ptrs((void**)labels, classes); |
|
|
|
free_ptrs((void**)labels, classes); |
|
|
|
free_ptrs((void**)paths, plist->size); |
|
|
|
free_ptrs((void**)paths, plist->size); |
|
|
@ -182,10 +164,6 @@ void train_classifier_multi(char *datacfg, char *cfgfile, char *weightfile, int |
|
|
|
|
|
|
|
|
|
|
|
void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int nthreads = 8; |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data_seed = time(0); |
|
|
|
|
|
|
|
srand(time(0)); |
|
|
|
srand(time(0)); |
|
|
|
float avg_loss = -1; |
|
|
|
float avg_loss = -1; |
|
|
|
char *base = basecfg(cfgfile); |
|
|
|
char *base = basecfg(cfgfile); |
|
|
@ -195,10 +173,10 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
load_weights(&net, weightfile); |
|
|
|
load_weights(&net, weightfile); |
|
|
|
} |
|
|
|
} |
|
|
|
if(clear) *net.seen = 0; |
|
|
|
if(clear) *net.seen = 0; |
|
|
|
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); |
|
|
|
|
|
|
|
int imgs = net.batch*net.subdivisions/nthreads; |
|
|
|
|
|
|
|
assert(net.batch*net.subdivisions % nthreads == 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int imgs = net.batch * net.subdivisions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); |
|
|
|
list *options = read_data_cfg(datacfg); |
|
|
|
list *options = read_data_cfg(datacfg); |
|
|
|
|
|
|
|
|
|
|
|
char *backup_directory = option_find_str(options, "backup", "/backup/"); |
|
|
|
char *backup_directory = option_find_str(options, "backup", "/backup/"); |
|
|
@ -213,13 +191,10 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
int N = plist->size; |
|
|
|
int N = plist->size; |
|
|
|
clock_t time; |
|
|
|
clock_t time; |
|
|
|
|
|
|
|
|
|
|
|
pthread_t *load_threads = calloc(nthreads, sizeof(pthread_t)); |
|
|
|
|
|
|
|
data *trains = calloc(nthreads, sizeof(data)); |
|
|
|
|
|
|
|
data *buffers = calloc(nthreads, sizeof(data)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_args args = {0}; |
|
|
|
load_args args = {0}; |
|
|
|
args.w = net.w; |
|
|
|
args.w = net.w; |
|
|
|
args.h = net.h; |
|
|
|
args.h = net.h; |
|
|
|
|
|
|
|
args.threads = 8; |
|
|
|
|
|
|
|
|
|
|
|
args.min = net.min_crop; |
|
|
|
args.min = net.min_crop; |
|
|
|
args.max = net.max_crop; |
|
|
|
args.max = net.max_crop; |
|
|
@ -237,24 +212,19 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
args.labels = labels; |
|
|
|
args.labels = labels; |
|
|
|
args.type = CLASSIFICATION_DATA; |
|
|
|
args.type = CLASSIFICATION_DATA; |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
data train; |
|
|
|
args.d = buffers + i; |
|
|
|
data buffer; |
|
|
|
load_threads[i] = load_data_in_thread(args); |
|
|
|
pthread_t load_thread; |
|
|
|
} |
|
|
|
args.d = &buffer; |
|
|
|
|
|
|
|
load_thread = load_data(args); |
|
|
|
|
|
|
|
|
|
|
|
int epoch = (*net.seen)/N; |
|
|
|
int epoch = (*net.seen)/N; |
|
|
|
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ |
|
|
|
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ |
|
|
|
time=clock(); |
|
|
|
time=clock(); |
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
pthread_join(load_threads[i], 0); |
|
|
|
|
|
|
|
trains[i] = buffers[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data train = concat_datas(trains, nthreads); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
pthread_join(load_thread, 0); |
|
|
|
args.d = buffers + i; |
|
|
|
train = buffer; |
|
|
|
load_threads[i] = load_data_in_thread(args); |
|
|
|
load_thread = load_data(args); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Loaded: %lf seconds\n", sec(clock()-time)); |
|
|
|
printf("Loaded: %lf seconds\n", sec(clock()-time)); |
|
|
|
time=clock(); |
|
|
|
time=clock(); |
|
|
@ -271,13 +241,11 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
float loss = train_network(net, train); |
|
|
|
float loss = train_network(net, train); |
|
|
|
|
|
|
|
free_data(train); |
|
|
|
|
|
|
|
|
|
|
|
if(avg_loss == -1) avg_loss = loss; |
|
|
|
if(avg_loss == -1) avg_loss = loss; |
|
|
|
avg_loss = avg_loss*.9 + loss*.1; |
|
|
|
avg_loss = avg_loss*.9 + loss*.1; |
|
|
|
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen); |
|
|
|
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen); |
|
|
|
free_data(train); |
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
free_data(trains[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(*net.seen/N > epoch){ |
|
|
|
if(*net.seen/N > epoch){ |
|
|
|
epoch = *net.seen/N; |
|
|
|
epoch = *net.seen/N; |
|
|
|
char buff[256]; |
|
|
|
char buff[256]; |
|
|
@ -294,14 +262,6 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int clear) |
|
|
|
sprintf(buff, "%s/%s.weights", backup_directory, base); |
|
|
|
sprintf(buff, "%s/%s.weights", backup_directory, base); |
|
|
|
save_weights(net, buff); |
|
|
|
save_weights(net, buff); |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < nthreads; ++i){ |
|
|
|
|
|
|
|
pthread_join(load_threads[i], 0); |
|
|
|
|
|
|
|
free_data(buffers[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
free(buffers); |
|
|
|
|
|
|
|
free(trains); |
|
|
|
|
|
|
|
free(load_threads); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free_network(net); |
|
|
|
free_network(net); |
|
|
|
free_ptrs((void**)labels, classes); |
|
|
|
free_ptrs((void**)labels, classes); |
|
|
|
free_ptrs((void**)paths, plist->size); |
|
|
|
free_ptrs((void**)paths, plist->size); |
|
|
@ -934,7 +894,19 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i |
|
|
|
int w = x2 - x1 - 2*border; |
|
|
|
int w = x2 - x1 - 2*border; |
|
|
|
|
|
|
|
|
|
|
|
float *predictions = network_predict(net, in_s.data); |
|
|
|
float *predictions = network_predict(net, in_s.data); |
|
|
|
float curr_threat = predictions[0] * 0 + predictions[1] * .6 + predictions[2]; |
|
|
|
float curr_threat = 0; |
|
|
|
|
|
|
|
if(1){ |
|
|
|
|
|
|
|
curr_threat = predictions[0] * 0 +
|
|
|
|
|
|
|
|
predictions[1] * .6 +
|
|
|
|
|
|
|
|
predictions[2]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
curr_threat = predictions[218] + |
|
|
|
|
|
|
|
predictions[539] +
|
|
|
|
|
|
|
|
predictions[540] +
|
|
|
|
|
|
|
|
predictions[368] +
|
|
|
|
|
|
|
|
predictions[369] +
|
|
|
|
|
|
|
|
predictions[370]; |
|
|
|
|
|
|
|
} |
|
|
|
threat = roll * curr_threat + (1-roll) * threat; |
|
|
|
threat = roll * curr_threat + (1-roll) * threat; |
|
|
|
|
|
|
|
|
|
|
|
draw_box_width(out, x2 + border, y1 + .02*h, x2 + .5 * w, y1 + .02*h + border, border, 0,0,0); |
|
|
|
draw_box_width(out, x2 + border, y1 + .02*h, x2 + .5 * w, y1 + .02*h + border, border, 0,0,0); |
|
|
@ -970,7 +942,7 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i |
|
|
|
top_predictions(net, top, indexes); |
|
|
|
top_predictions(net, top, indexes); |
|
|
|
char buff[256]; |
|
|
|
char buff[256]; |
|
|
|
sprintf(buff, "/home/pjreddie/tmp/threat_%06d", count); |
|
|
|
sprintf(buff, "/home/pjreddie/tmp/threat_%06d", count); |
|
|
|
save_image(out, buff); |
|
|
|
//save_image(out, buff);
|
|
|
|
|
|
|
|
|
|
|
|
printf("\033[2J"); |
|
|
|
printf("\033[2J"); |
|
|
|
printf("\033[1;1H"); |
|
|
|
printf("\033[1;1H"); |
|
|
@ -981,7 +953,7 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i |
|
|
|
printf("%.1f%%: %s\n", predictions[index]*100, names[index]); |
|
|
|
printf("%.1f%%: %s\n", predictions[index]*100, names[index]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(0){ |
|
|
|
if(1){ |
|
|
|
show_image(out, "Threat"); |
|
|
|
show_image(out, "Threat"); |
|
|
|
cvWaitKey(10); |
|
|
|
cvWaitKey(10); |
|
|
|
} |
|
|
|
} |
|
|
@ -997,6 +969,85 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_index, const char *filename) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef OPENCV |
|
|
|
|
|
|
|
int bad_cats[] = {218, 539, 540, 1213, 1501, 1742, 1911, 2415, 4348, 19223, 368, 369, 370, 1133, 1200, 1306, 2122, 2301, 2537, 2823, 3179, 3596, 3639, 4489, 5107, 5140, 5289, 6240, 6631, 6762, 7048, 7171, 7969, 7984, 7989, 8824, 8927, 9915, 10270, 10448, 13401, 15205, 18358, 18894, 18895, 19249, 19697}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Classifier Demo\n"); |
|
|
|
|
|
|
|
network net = parse_network_cfg(cfgfile); |
|
|
|
|
|
|
|
if(weightfile){ |
|
|
|
|
|
|
|
load_weights(&net, weightfile); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
set_batch_network(&net, 1); |
|
|
|
|
|
|
|
list *options = read_data_cfg(datacfg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srand(2222222); |
|
|
|
|
|
|
|
CvCapture * cap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(filename){ |
|
|
|
|
|
|
|
cap = cvCaptureFromFile(filename); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
cap = cvCaptureFromCAM(cam_index); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int top = option_find_int(options, "top", 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *name_list = option_find_str(options, "names", 0); |
|
|
|
|
|
|
|
char **names = get_labels(name_list); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int *indexes = calloc(top, sizeof(int)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cap) error("Couldn't connect to webcam.\n"); |
|
|
|
|
|
|
|
cvNamedWindow("Threat Detection", CV_WINDOW_NORMAL);
|
|
|
|
|
|
|
|
cvResizeWindow("Threat Detection", 512, 512); |
|
|
|
|
|
|
|
float fps = 0; |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1){ |
|
|
|
|
|
|
|
struct timeval tval_before, tval_after, tval_result; |
|
|
|
|
|
|
|
gettimeofday(&tval_before, NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image in = get_image_from_stream(cap); |
|
|
|
|
|
|
|
image in_s = resize_image(in, net.w, net.h); |
|
|
|
|
|
|
|
show_image(in, "Threat Detection"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float *predictions = network_predict(net, in_s.data); |
|
|
|
|
|
|
|
top_predictions(net, top, indexes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\033[2J"); |
|
|
|
|
|
|
|
printf("\033[1;1H"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int threat = 0; |
|
|
|
|
|
|
|
for(i = 0; i < sizeof(bad_cats)/sizeof(bad_cats[0]); ++i){ |
|
|
|
|
|
|
|
int index = bad_cats[i]; |
|
|
|
|
|
|
|
if(predictions[index] > .01){ |
|
|
|
|
|
|
|
printf("Threat Detected!\n"); |
|
|
|
|
|
|
|
threat = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(!threat) printf("Scanning...\n"); |
|
|
|
|
|
|
|
for(i = 0; i < sizeof(bad_cats)/sizeof(bad_cats[0]); ++i){ |
|
|
|
|
|
|
|
int index = bad_cats[i]; |
|
|
|
|
|
|
|
if(predictions[index] > .01){ |
|
|
|
|
|
|
|
printf("%s\n", names[index]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free_image(in_s); |
|
|
|
|
|
|
|
free_image(in); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cvWaitKey(10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tval_after, NULL); |
|
|
|
|
|
|
|
timersub(&tval_after, &tval_before, &tval_result); |
|
|
|
|
|
|
|
float curr = 1000000.f/((long int)tval_result.tv_usec); |
|
|
|
|
|
|
|
fps = .9*fps + .1*curr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#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) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef OPENCV |
|
|
|
#ifdef OPENCV |
|
|
@ -1102,6 +1153,7 @@ void run_classifier(int argc, char **argv) |
|
|
|
else if(0==strcmp(argv[2], "train")) train_classifier(data, cfg, weights, clear); |
|
|
|
else if(0==strcmp(argv[2], "train")) train_classifier(data, cfg, weights, clear); |
|
|
|
else if(0==strcmp(argv[2], "trainm")) train_classifier_multi(data, cfg, weights, gpus, ngpus, clear); |
|
|
|
else if(0==strcmp(argv[2], "trainm")) train_classifier_multi(data, cfg, weights, gpus, ngpus, clear); |
|
|
|
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); |
|
|
|
|
|
|
|
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], "threat")) threat_classifier(data, cfg, weights, cam_index, filename); |
|
|
|
else if(0==strcmp(argv[2], "test")) test_classifier(data, cfg, weights, layer); |
|
|
|
else if(0==strcmp(argv[2], "test")) test_classifier(data, cfg, weights, layer); |
|
|
|
else if(0==strcmp(argv[2], "label")) label_classifier(data, cfg, weights); |
|
|
|
else if(0==strcmp(argv[2], "label")) label_classifier(data, cfg, weights); |
|
|
|