Skip to content

Commit

Permalink
CLEAN UP CLEAN UP EVERYBODY DO YOUR oh wait it's just me
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed Mar 25, 2018
1 parent e31c501 commit 777b098
Show file tree
Hide file tree
Showing 16 changed files with 602 additions and 319 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GPU=1
CUDNN=1
OPENCV=0
OPENCV=1
OPENMP=1
DEBUG=0

Expand All @@ -26,7 +26,7 @@ ARFLAGS=rcs
OPTS=-Ofast
LDFLAGS= -lm -pthread
COMMON= -Iinclude/ -Isrc/
CFLAGS=-Wall -Wno-unknown-pragmas -Wfatal-errors -fPIC
CFLAGS=-Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC

ifeq ($(OPENMP), 1)
CFLAGS+= -fopenmp
Expand Down Expand Up @@ -57,7 +57,7 @@ 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
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
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
Expand Down
4 changes: 2 additions & 2 deletions examples/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
if (tree) net->hierarchy = read_tree(tree);
int classes = option_find_int(options, "classes", 2);

char **labels;
char **labels = 0;
if(!tag){
labels = get_labels(label_list);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
pthread_join(load_thread, 0);

free_network(net);
free_ptrs((void**)labels, classes);
if(labels) free_ptrs((void**)labels, classes);
free_ptrs((void**)paths, plist->size);
free_list(plist);
free(base);
Expand Down
17 changes: 9 additions & 8 deletions examples/coco.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ void validate_coco(char *cfg, char *weights)
FILE *fp = fopen(buff, "w");
fprintf(fp, "[\n");

detection *dets = make_network_boxes(net, 0);

int m = plist->size;
int i=0;
int t;
Expand Down Expand Up @@ -195,9 +193,11 @@ void validate_coco(char *cfg, char *weights)
network_predict(net, X);
int w = val[t].w;
int h = val[t].h;
fill_network_boxes(net, w, h, thresh, 0, 0, 0, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, w, h, thresh, 0, 0, 0, &nboxes);
if (nms) do_nms_sort(dets, l.side*l.side*l.n, classes, iou_thresh);
print_cocos(fp, image_id, dets, l.side*l.side*l.n, classes, w, h);
free_detections(dets, nboxes);
free_image(val[t]);
free_image(val_resized[t]);
}
Expand Down Expand Up @@ -231,7 +231,6 @@ void validate_coco_recall(char *cfgfile, char *weightfile)
snprintf(buff, 1024, "%s%s.txt", base, coco_classes[j]);
fps[j] = fopen(buff, "w");
}
detection *dets = make_network_boxes(net, 0);

int m = plist->size;
int i=0;
Expand All @@ -252,7 +251,8 @@ void validate_coco_recall(char *cfgfile, char *weightfile)
char *id = basecfg(path);
network_predict(net, sized.data);

fill_network_boxes(net, orig.w, orig.h, thresh, 0, 0, 1, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, orig.w, orig.h, thresh, 0, 0, 1, &nboxes);
if (nms) do_nms_obj(dets, side*side*l.n, 1, nms);

char labelpath[4096];
Expand Down Expand Up @@ -283,7 +283,7 @@ void validate_coco_recall(char *cfgfile, char *weightfile)
++correct;
}
}

free_detections(dets, nboxes);
fprintf(stderr, "%5d %5d %5d\tRPs/Img: %.2f\tIOU: %.2f%%\tRecall:%.2f%%\n", i, correct, total, (float)proposals/(i+1), avg_iou*100/total, 100.*correct/total);
free(id);
free_image(orig);
Expand All @@ -302,7 +302,6 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
clock_t time;
char buff[256];
char *input = buff;
detection *dets = make_network_boxes(net, 0);
while(1){
if(filename){
strncpy(input, filename, 256);
Expand All @@ -320,12 +319,14 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));

fill_network_boxes(net, 1, 1, thresh, 0, 0, 0, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, im.w, im.h, thresh, 0, 0, 0, &nboxes);
if (nms) do_nms_sort(dets, l.side*l.side*l.n, l.classes, nms);

draw_detections(im, dets, l.side*l.side*l.n, thresh, coco_classes, alphabet, 80);
save_image(im, "prediction");
show_image(im, "predictions");
free_detections(dets, nboxes);
free_image(im);
free_image(sized);
#ifdef OPENCV
Expand Down
34 changes: 9 additions & 25 deletions examples/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i

static int get_coco_image_id(char *filename)
{
char *p = strrchr(filename, '_');
char *p = strrchr(filename, '/');
char *c = strrchr(filename, '_');
if(c) p = c;
return atoi(p+1);
}

Expand Down Expand Up @@ -467,6 +469,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out
} else {
print_detector_detections(fps, id, dets, nboxes, classes, w, h);
}
free_detections(dets, nboxes);
free(id);
free_image(val[t]);
free_image(val_resized[t]);
Expand Down Expand Up @@ -622,14 +625,13 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
}
}

/*
void censor_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_index, const char *filename, int class, float thresh, int skip)
{
#ifdef OPENCV
image **alphabet = load_alphabet();
char *base = basecfg(cfgfile);
network *net = load_network(cfgfile, weightfile, 0);
set_batch_network(net, 1);
list *options = read_data_cfg(datacfg);
srand(2222222);
CvCapture * cap;
Expand All @@ -650,20 +652,11 @@ void censor_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, h);
}
int top = option_find_int(options, "top", 1);

char *label_list = option_find_str(options, "labels", 0);
char *name_list = option_find_str(options, "names", label_list);
char **names = get_labels(name_list);

int *indexes = calloc(top, sizeof(int));

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow(base, CV_WINDOW_NORMAL);
cvResizeWindow(base, 512, 512);
float fps = 0;
int i;
int count = 0;
float nms = .45;
while(1){
Expand Down Expand Up @@ -709,11 +702,9 @@ void censor_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
void extract_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_index, const char *filename, int class, float thresh, int skip)
{
#ifdef OPENCV
image **alphabet = load_alphabet();
char *base = basecfg(cfgfile);
network *net = load_network(cfgfile, weightfile, 0);
set_batch_network(net, 1);
list *options = read_data_cfg(datacfg);
srand(2222222);
CvCapture * cap;
Expand All @@ -734,14 +725,6 @@ void extract_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_in
cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, h);
}
int top = option_find_int(options, "top", 1);

char *label_list = option_find_str(options, "labels", 0);
char *name_list = option_find_str(options, "names", label_list);
char **names = get_labels(name_list);

int *indexes = calloc(top, sizeof(int));

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow(base, CV_WINDOW_NORMAL);
cvResizeWindow(base, 512, 512);
Expand Down Expand Up @@ -795,6 +778,7 @@ void extract_detector(char *datacfg, char *cfgfile, char *weightfile, int cam_in
}
#endif
}
*/

/*
void network_detect(network *net, image im, float thresh, float hier_thresh, float nms, detection *dets)
Expand Down Expand Up @@ -848,15 +832,13 @@ void run_detector(int argc, char **argv)
int width = find_int_arg(argc, argv, "-w", 0);
int height = find_int_arg(argc, argv, "-h", 0);
int fps = find_int_arg(argc, argv, "-fps", 0);
int class = find_int_arg(argc, argv, "-class", 0);
//int class = find_int_arg(argc, argv, "-class", 0);

char *datacfg = argv[3];
char *cfg = argv[4];
char *weights = (argc > 5) ? argv[5] : 0;
char *filename = (argc > 6) ? argv[6]: 0;
if(0==strcmp(argv[2], "test")) test_detector(datacfg, cfg, weights, filename, thresh, hier_thresh, outfile, fullscreen);
else if(0==strcmp(argv[2], "extract")) extract_detector(datacfg, cfg, weights, cam_index, filename, class, thresh, frame_skip);
else if(0==strcmp(argv[2], "censor")) censor_detector(datacfg, cfg, weights, cam_index, filename, class, thresh, frame_skip);
else if(0==strcmp(argv[2], "train")) train_detector(datacfg, cfg, weights, gpus, ngpus, clear);
else if(0==strcmp(argv[2], "valid")) validate_detector(datacfg, cfg, weights, outfile);
else if(0==strcmp(argv[2], "valid2")) validate_detector_flip(datacfg, cfg, weights, outfile);
Expand All @@ -868,4 +850,6 @@ void run_detector(int argc, char **argv)
char **names = get_labels(name_list);
demo(cfg, weights, thresh, cam_index, filename, names, classes, frame_skip, prefix, avg, hier_thresh, width, height, fps, fullscreen);
}
//else if(0==strcmp(argv[2], "extract")) extract_detector(datacfg, cfg, weights, cam_index, filename, class, thresh, frame_skip);
//else if(0==strcmp(argv[2], "censor")) censor_detector(datacfg, cfg, weights, cam_index, filename, class, thresh, frame_skip);
}
7 changes: 4 additions & 3 deletions examples/lsd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <math.h>
#include "darknet.h"

/*
Expand Down Expand Up @@ -478,7 +479,7 @@ void test_dcgan(char *cfgfile, char *weightfile)
clock_t time;
char buff[256];
char *input = buff;
int i, imlayer = 0;
int imlayer = 0;

imlayer = net->n-1;

Expand Down Expand Up @@ -615,7 +616,7 @@ void train_prog(char *cfg, char *weight, char *acfg, char *aweight, int clear, i
forward_network(anet);
backward_network(anet);

float genaloss = *anet->cost / anet->batch;
//float genaloss = *anet->cost / anet->batch;

scal_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1);
scal_gpu(imlayer.outputs*imlayer.batch, 0, gnet->layers[gnet->n-1].delta_gpu, 1);
Expand Down Expand Up @@ -785,7 +786,7 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
forward_network(anet);
backward_network(anet);

float genaloss = *anet->cost / anet->batch;
//float genaloss = *anet->cost / anet->batch;
//printf("%f\n", genaloss);

scal_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1);
Expand Down
4 changes: 2 additions & 2 deletions examples/rnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ float_pair get_seq2seq_data(char **source, char **dest, int n, int characters, s
float *y = calloc(batch * steps * characters, sizeof(float));
for(i = 0; i < batch; ++i){
int index = rand()%n;
int slen = strlen(source[index]);
int dlen = strlen(dest[index]);
//int slen = strlen(source[index]);
//int dlen = strlen(dest[index]);
for(j = 0; j < steps; ++j){
unsigned char curr = source[index][j];
unsigned char next = dest[index][j];
Expand Down
16 changes: 9 additions & 7 deletions examples/yolo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ void validate_yolo(char *cfg, char *weights)
image *buf = calloc(nthreads, sizeof(image));
image *buf_resized = calloc(nthreads, sizeof(image));
pthread_t *thr = calloc(nthreads, sizeof(pthread_t));
detection *dets = make_network_boxes(net, 0);

load_args args = {0};
args.w = net->w;
Expand Down Expand Up @@ -167,9 +166,11 @@ void validate_yolo(char *cfg, char *weights)
network_predict(net, X);
int w = val[t].w;
int h = val[t].h;
fill_network_boxes(net, w, h, thresh, 0, 0, 0, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, w, h, thresh, 0, 0, 0, &nboxes);
if (nms) do_nms_sort(dets, l.side*l.side*l.n, classes, iou_thresh);
print_yolo_detections(fps, id, l.side*l.side*l.n, classes, w, h, dets);
free_detections(dets, nboxes);
free(id);
free_image(val[t]);
free_image(val_resized[t]);
Expand Down Expand Up @@ -200,7 +201,6 @@ void validate_yolo_recall(char *cfg, char *weights)
snprintf(buff, 1024, "%s%s.txt", base, voc_names[j]);
fps[j] = fopen(buff, "w");
}
detection *dets = make_network_boxes(net, 0);

int m = plist->size;
int i=0;
Expand All @@ -221,7 +221,8 @@ void validate_yolo_recall(char *cfg, char *weights)
char *id = basecfg(path);
network_predict(net, sized.data);

fill_network_boxes(net, orig.w, orig.h, thresh, 0, 0, 1, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, orig.w, orig.h, thresh, 0, 0, 1, &nboxes);
if (nms) do_nms_obj(dets, side*side*l.n, 1, nms);

char labelpath[4096];
Expand Down Expand Up @@ -254,6 +255,7 @@ void validate_yolo_recall(char *cfg, char *weights)
}

fprintf(stderr, "%5d %5d %5d\tRPs/Img: %.2f\tIOU: %.2f%%\tRecall:%.2f%%\n", i, correct, total, (float)proposals/(i+1), avg_iou*100/total, 100.*correct/total);
free_detections(dets, nboxes);
free(id);
free_image(orig);
free_image(sized);
Expand All @@ -271,7 +273,6 @@ void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh)
char buff[256];
char *input = buff;
float nms=.4;
detection *dets = make_network_boxes(net, 0);
while(1){
if(filename){
strncpy(input, filename, 256);
Expand All @@ -289,13 +290,14 @@ void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh)
network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));

fill_network_boxes(net, 1, 1, thresh, 0, 0, 0, dets);
int nboxes = 0;
detection *dets = get_network_boxes(net, im.w, im.h, thresh, 0, 0, 0, &nboxes);
if (nms) do_nms_sort(dets, l.side*l.side*l.n, l.classes, nms);

draw_detections(im, dets, l.side*l.side*l.n, thresh, voc_names, alphabet, 20);
save_image(im, "predictions");
show_image(im, "predictions");

free_detections(dets, nboxes);
free_image(im);
free_image(sized);
#ifdef OPENCV
Expand Down
5 changes: 4 additions & 1 deletion include/darknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef enum {
NETWORK,
XNOR,
REGION,
YOLO,
REORG,
UPSAMPLE,
LOGXENT,
Expand Down Expand Up @@ -674,6 +675,7 @@ void get_detection_detections(layer l, int w, int h, float thresh, detection *de

char *option_find_str(list *l, char *key, char *def);
int option_find_int(list *l, char *key, int def);
int option_find_int_quiet(list *l, char *key, int def);

network *parse_network_cfg(char *filename);
void save_weights(network *net, char *filename);
Expand All @@ -682,7 +684,8 @@ void save_weights_upto(network *net, char *filename, int cutoff);
void load_weights_upto(network *net, char *filename, int start, int cutoff);

void zero_objectness(layer l);
int get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets);
void get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets);
int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets);
void free_network(network *net);
void set_batch_network(network *net, int b);
void set_temp_network(network *net, float t);
Expand Down
4 changes: 1 addition & 3 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void *detect_in_thread(void *ptr)
if(l.type == DETECTION){
get_detection_boxes(l, 1, 1, demo_thresh, probs, boxes, 0);
} else */
detection *dets;
detection *dets = 0;
int nboxes = 0;
if (l.type == REGION){
dets = get_network_boxes(net, buff[0].w, buff[0].h, demo_thresh, demo_hier, 0, 1, &nboxes);
Expand Down Expand Up @@ -174,8 +174,6 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch

if(!cap) error("Couldn't connect to webcam.\n");

int i;

buff[0] = get_image_from_stream(cap);
buff[1] = copy_image(buff[0]);
buff[2] = copy_image(buff[0]);
Expand Down
Loading

0 comments on commit 777b098

Please sign in to comment.