Skip to content

Commit

Permalink
this'll teach me to mess with maxpooling
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed Aug 3, 2018
1 parent e209b3b commit b13f67b
Show file tree
Hide file tree
Showing 23 changed files with 737 additions and 130 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ CFLAGS+= -DCUDNN
LDFLAGS+= -lcudnn
endif

OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o
EXECOBJA=captcha.o lsd.o super.o art.o tag.o cifar.o go.o rnn.o segmenter.o regressor.o classifier.o coco.o yolo.o detector.o nightmare.o darknet.o
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o iseg_layer.o
EXECOBJA=captcha.o lsd.o super.o art.o tag.o cifar.o go.o rnn.o segmenter.o regressor.o classifier.o coco.o yolo.o detector.o nightmare.o instance-segmenter.o darknet.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
OBJ+=convolutional_kernels.o deconvolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o avgpool_layer_kernels.o
Expand Down
4 changes: 1 addition & 3 deletions examples/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index)
while(1){
image in = get_image_from_stream(cap);
image in_s = resize_image(in, net->w, net->h);
show_image(in, window);

float *p = network_predict(net, in_s.data);

Expand All @@ -45,10 +44,9 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index)
}
printf("]\n");

show_image(in, window, 1);
free_image(in_s);
free_image(in);

cvWaitKey(1);
}
#endif
}
Expand Down
51 changes: 43 additions & 8 deletions examples/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,45 @@ void label_classifier(char *datacfg, char *filename, char *weightfile)
}
}

void csv_classifier(char *datacfg, char *cfgfile, char *weightfile)
{
int i,j;
network *net = load_network(cfgfile, weightfile, 0);
srand(time(0));

list *options = read_data_cfg(datacfg);

char *test_list = option_find_str(options, "test", "data/test.list");
int top = option_find_int(options, "top", 1);

list *plist = get_paths(test_list);

char **paths = (char **)list_to_array(plist);
int m = plist->size;
free_list(plist);
int *indexes = calloc(top, sizeof(int));

for(i = 0; i < m; ++i){
double time = what_time_is_it_now();
char *path = paths[i];
image im = load_image_color(path, 0, 0);
image r = letterbox_image(im, net->w, net->h);
float *predictions = network_predict(net, r.data);
if(net->hierarchy) hierarchy_predictions(predictions, net->outputs, net->hierarchy, 1, 1);
top_k(predictions, net->outputs, top, indexes);

printf("%s", path);
for(j = 0; j < top; ++j){
printf("\t%d", indexes[j]);
}
printf("\n");

free_image(im);
free_image(r);

fprintf(stderr, "%lf seconds, %d images, %d total\n", what_time_is_it_now() - time, i+1, m);
}
}

void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_layer)
{
Expand Down Expand Up @@ -869,8 +908,7 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i
}

if(1){
show_image(out, "Threat");
cvWaitKey(10);
show_image(out, "Threat", 10);
}
free_image(in_s);
free_image(in);
Expand Down Expand Up @@ -922,7 +960,6 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde

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);
Expand All @@ -947,11 +984,10 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
}
}

show_image(in, "Threat Detection", 10);
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);
Expand Down Expand Up @@ -1036,12 +1072,10 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
free_image(label);
}

show_image(in, base);
show_image(in, base, 10);
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);
Expand Down Expand Up @@ -1080,6 +1114,7 @@ void run_classifier(int argc, char **argv)
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);
else if(0==strcmp(argv[2], "csv")) csv_classifier(data, cfg, weights);
else if(0==strcmp(argv[2], "label")) label_classifier(data, cfg, weights);
else if(0==strcmp(argv[2], "valid")) validate_classifier_single(data, cfg, weights);
else if(0==strcmp(argv[2], "validmulti")) validate_classifier_multi(data, cfg, weights);
Expand Down
6 changes: 1 addition & 5 deletions examples/coco.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)

draw_detections(im, dets, l.side*l.side*l.n, thresh, coco_classes, alphabet, 80);
save_image(im, "prediction");
show_image(im, "predictions");
show_image(im, "predictions", 0);
free_detections(dets, nboxes);
free_image(im);
free_image(sized);
#ifdef OPENCV
cvWaitKey(0);
cvDestroyAllWindows();
#endif
if (filename) break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/darknet.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern void run_nightmare(int argc, char **argv);
extern void run_classifier(int argc, char **argv);
extern void run_regressor(int argc, char **argv);
extern void run_segmenter(int argc, char **argv);
extern void run_isegmenter(int argc, char **argv);
extern void run_char_rnn(int argc, char **argv);
extern void run_tag(int argc, char **argv);
extern void run_cifar(int argc, char **argv);
Expand Down Expand Up @@ -452,6 +453,8 @@ int main(int argc, char **argv)
run_classifier(argc, argv);
} else if (0 == strcmp(argv[1], "regressor")){
run_regressor(argc, argv);
} else if (0 == strcmp(argv[1], "isegmenter")){
run_isegmenter(argc, argv);
} else if (0 == strcmp(argv[1], "segmenter")){
run_segmenter(argc, argv);
} else if (0 == strcmp(argv[1], "art")){
Expand Down
4 changes: 1 addition & 3 deletions examples/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
if(fullscreen){
cvSetWindowProperty("predictions", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
}
show_image(im, "predictions");
cvWaitKey(0);
cvDestroyAllWindows();
show_image(im, "predictions", 0);
#endif
}

Expand Down
Loading

0 comments on commit b13f67b

Please sign in to comment.