From 5cc7b181b5056df8d302530e56e2783aaab07166 Mon Sep 17 00:00:00 2001 From: Oscar Kramer Date: Tue, 19 Mar 2019 00:28:32 -0400 Subject: [PATCH 1/8] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 09fdeeeb5e7..661d7e058ed 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +This fork is to support YOLO implementation on FPGA +Contact: Oscar Kramer, oscar.kramer@radiantsolutions.com, 321-821-1150 + ![Darknet Logo](http://pjreddie.com/media/files/darknet-black-small.png) # Darknet # From 3a2a020c8b6c0ac364857d510703ca1acce279a9 Mon Sep 17 00:00:00 2001 From: Oscar Kramer Date: Tue, 19 Mar 2019 00:28:58 -0400 Subject: [PATCH 2/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 661d7e058ed..e47a09ae218 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ This fork is to support YOLO implementation on FPGA + Contact: Oscar Kramer, oscar.kramer@radiantsolutions.com, 321-821-1150 ![Darknet Logo](http://pjreddie.com/media/files/darknet-black-small.png) From 623a707be9aa8ec30a4bf1a7ee54829711bea489 Mon Sep 17 00:00:00 2001 From: oscarkramer Date: Tue, 19 Mar 2019 00:41:22 -0400 Subject: [PATCH 3/8] Initial fork and modified to use cmake --- .gitignore | 2 + .idea/codeStyles/Project.xml | 29 + .idea/darknet.iml | 2 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 759 ++++++++++++++++++++++ CMakeLists.txt | 55 ++ Makefile | 105 --- examples/CMakeLists.txt | 6 + examples/attention.c | 4 +- examples/{dice.c => dice.c.HIDE} | 0 examples/swag.c | 18 +- examples/voxel.c | 24 +- examples/writing.c | 34 +- src/CMakeLists.txt | 15 + src/{compare.c => compare.c.HIDE} | 0 src/convolutional_layer.c | 631 +++++++++--------- src/{ => cuda}/activation_kernels.cu | 0 src/{ => cuda}/avgpool_layer_kernels.cu | 0 src/{ => cuda}/blas_kernels.cu | 0 src/{ => cuda}/col2im_kernels.cu | 0 src/{ => cuda}/convolutional_kernels.cu | 0 src/{ => cuda}/crop_layer_kernels.cu | 0 src/{ => cuda}/deconvolutional_kernels.cu | 0 src/{ => cuda}/dropout_layer_kernels.cu | 0 src/{ => cuda}/im2col_kernels.cu | 0 src/{ => cuda}/maxpool_layer_kernels.cu | 0 src/parser.c | 2 +- 29 files changed, 1247 insertions(+), 460 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/darknet.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 examples/CMakeLists.txt rename examples/{dice.c => dice.c.HIDE} (100%) create mode 100644 src/CMakeLists.txt rename src/{compare.c => compare.c.HIDE} (100%) rename src/{ => cuda}/activation_kernels.cu (100%) rename src/{ => cuda}/avgpool_layer_kernels.cu (100%) rename src/{ => cuda}/blas_kernels.cu (100%) rename src/{ => cuda}/col2im_kernels.cu (100%) rename src/{ => cuda}/convolutional_kernels.cu (100%) rename src/{ => cuda}/crop_layer_kernels.cu (100%) rename src/{ => cuda}/deconvolutional_kernels.cu (100%) rename src/{ => cuda}/dropout_layer_kernels.cu (100%) rename src/{ => cuda}/im2col_kernels.cu (100%) rename src/{ => cuda}/maxpool_layer_kernels.cu (100%) diff --git a/.gitignore b/.gitignore index bea19ff44fc..eb15c1352cc 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ convnet/ decaf/ submission/ cfg/ +weights/ +build/ darknet .fuse* diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000000..30aa626c231 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/darknet.iml b/.idea/darknet.iml new file mode 100644 index 00000000000..f08604bb65b --- /dev/null +++ b/.idea/darknet.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000000..8822db8f1c2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000000..33597b7b3ce --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000000..94a25f7f4cb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000000..7aa27d789eb --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,759 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + gpu + main( + &net + net. + run_yolo + %d x %d / + conv %5d %2d + load + net + load_ + + + net-> + net + + + $PROJECT_DIR$/src + $PROJECT_DIR$ + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + @@ -430,17 +474,17 @@ - - + - + @@ -451,7 +495,7 @@ - + @@ -669,7 +713,7 @@ - + @@ -720,80 +764,80 @@ - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + diff --git a/examples/attention.c b/examples/attention.c index b79d1b26727..ee647942628 100644 --- a/examples/attention.c +++ b/examples/attention.c @@ -15,7 +15,7 @@ void extend_data_truth(dn_data *d, int n, float val) d->y.cols += n; } -dn_matrix network_loss_data(network *net, dn_data test) +dn_matrix network_loss_data(dn_network *net, dn_data test) { int i,b; int k = 1; @@ -29,7 +29,7 @@ dn_matrix network_loss_data(network *net, dn_data test) memcpy(y+b*test.y.cols, test.y.vals[i+b], test.y.cols*sizeof(float)); } - network orig = *net; + dn_network orig = *net; net->input = X; net->truth = y; net->train = 0; @@ -60,7 +60,7 @@ void train_attention(char *datacfg, char *cfgfile, char *weightfile, int *gpus, char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -73,7 +73,7 @@ void train_attention(char *datacfg, char *cfgfile, char *weightfile, int *gpus, nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; int imgs = net->batch * net->subdivisions * ngpus; @@ -233,7 +233,7 @@ void train_attention(char *datacfg, char *cfgfile, char *weightfile, int *gpus, void validate_attention_single(char *datacfg, char *filename, char *weightfile) { int i, j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -321,7 +321,7 @@ void validate_attention_single(char *datacfg, char *filename, char *weightfile) void validate_attention_multi(char *datacfg, char *filename, char *weightfile) { int i, j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -381,7 +381,7 @@ void validate_attention_multi(char *datacfg, char *filename, char *weightfile) void predict_attention(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/captcha.c b/examples/captcha.c index ed45933dc70..d046f580f70 100644 --- a/examples/captcha.c +++ b/examples/captcha.c @@ -30,7 +30,7 @@ void train_captcha(char *cfgfile, char *weightfile) float avg_loss = -1; char *base = basecfg(cfgfile); printf("%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); int imgs = 1024; int i = *net->seen/imgs; @@ -92,7 +92,7 @@ void train_captcha(char *cfgfile, char *weightfile) void test_captcha(char *cfgfile, char *weightfile, char *filename) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); int i = 0; @@ -130,7 +130,7 @@ void test_captcha(char *cfgfile, char *weightfile, char *filename) void valid_captcha(char *cfgfile, char *weightfile, char *filename) { char **labels = get_labels("/data/captcha/reimgs.labels.list"); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); dn_list *plist = get_paths("/data/captcha/reimgs.fg.list"); char **paths = (char **)list_to_array(plist); int N = plist->size; diff --git a/examples/cifar.c b/examples/cifar.c index 8704919f0db..e59511171b8 100644 --- a/examples/cifar.c +++ b/examples/cifar.c @@ -6,7 +6,7 @@ void train_cifar(char *cfgfile, char *weightfile) float avg_loss = -1; char *base = basecfg(cfgfile); printf("%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); char *backup_directory = "/home/pjreddie/backup/"; @@ -51,7 +51,7 @@ void train_cifar_distill(char *cfgfile, char *weightfile) float avg_loss = -1; char *base = basecfg(cfgfile); printf("%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); char *backup_directory = "/home/pjreddie/backup/"; @@ -100,7 +100,7 @@ void train_cifar_distill(char *cfgfile, char *weightfile) void test_cifar_multi(char *filename, char *weightfile) { - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -129,7 +129,7 @@ void test_cifar_multi(char *filename, char *weightfile) void test_cifar(char *filename, char *weightfile) { - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); srand(time(0)); clock_t time; @@ -170,7 +170,7 @@ char *labels[] = {"airplane","automobile","bird","cat","deer","dog","frog","hors void test_cifar_csv(char *filename, char *weightfile) { - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); srand(time(0)); dn_data test = load_cifar10_data("data/cifar/cifar-10-batches-bin/test_batch.bin"); @@ -194,7 +194,7 @@ void test_cifar_csv(char *filename, char *weightfile) void test_cifar_csvtrain(char *cfg, char *weights) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); srand(time(0)); dn_data test = load_all_cifar10(); diff --git a/examples/classifier.c b/examples/classifier.c index 6ef4034fe13..87b26a826b9 100644 --- a/examples/classifier.c +++ b/examples/classifier.c @@ -23,7 +23,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -36,7 +36,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; int imgs = net->batch * net->subdivisions * ngpus; @@ -170,7 +170,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, void validate_classifier_crop(char *datacfg, char *filename, char *weightfile) { int i = 0; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); srand(time(0)); dn_list *options = read_data_cfg(datacfg); @@ -234,7 +234,7 @@ void validate_classifier_crop(char *datacfg, char *filename, char *weightfile) void validate_classifier_10(char *datacfg, char *filename, char *weightfile) { int i, j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -303,7 +303,7 @@ void validate_classifier_10(char *datacfg, char *filename, char *weightfile) void validate_classifier_full(char *datacfg, char *filename, char *weightfile) { int i, j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -361,7 +361,7 @@ void validate_classifier_full(char *datacfg, char *filename, char *weightfile) void validate_classifier_single(char *datacfg, char *filename, char *weightfile) { int i, j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -420,7 +420,7 @@ void validate_classifier_single(char *datacfg, char *filename, char *weightfile) void validate_classifier_multi(char *datacfg, char *cfg, char *weights) { int i, j; - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); srand(time(0)); @@ -481,7 +481,7 @@ void validate_classifier_multi(char *datacfg, char *cfg, char *weights) void try_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int layer_num) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); @@ -523,7 +523,7 @@ void try_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filena time=clock(); float *predictions = network_predict(net, X); - layer l = net->layers[layer_num]; + dn_layer l = net->layers[layer_num]; for(i = 0; i < l.c; ++i){ if(l.rolling_mean) printf("%f %f %f\n", l.rolling_mean[i], l.rolling_variance[i], l.scales[i]); } @@ -559,7 +559,7 @@ void try_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filena void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); @@ -614,7 +614,7 @@ void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *fi void label_classifier(char *datacfg, char *filename, char *weightfile) { int i; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); @@ -649,7 +649,7 @@ 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); + dn_network *net = load_network(cfgfile, weightfile, 0); srand(time(0)); dn_list *options = read_data_cfg(datacfg); @@ -689,7 +689,7 @@ void csv_classifier(char *datacfg, char *cfgfile, char *weightfile) void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_layer) { int curr = 0; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); srand(time(0)); dn_list *options = read_data_cfg(datacfg); @@ -758,7 +758,7 @@ void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_ void file_output_classifier(char *datacfg, char *filename, char *weightfile, char *listfile) { int i,j; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); diff --git a/examples/coco.c b/examples/coco.c index ab3c17cf094..1f5ad80102f 100644 --- a/examples/coco.c +++ b/examples/coco.c @@ -17,14 +17,14 @@ void train_coco(char *cfgfile, char *weightfile) char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); int imgs = net->batch*net->subdivisions; int i = *net->seen/imgs; dn_data train, buffer; - layer l = net->layers[net->n - 1]; + dn_layer l = net->layers[net->n - 1]; int side = l.side; int classes = l.classes; @@ -127,7 +127,7 @@ int get_coco_image_id(char *filename) void validate_coco(char *cfg, char *weights) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -138,7 +138,7 @@ void validate_coco(char *cfg, char *weights) //list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt"); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; char buff[1024]; @@ -211,7 +211,7 @@ void validate_coco(char *cfg, char *weights) void validate_coco_recall(char *cfgfile, char *weightfile) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -220,7 +220,7 @@ void validate_coco_recall(char *cfgfile, char *weightfile) dn_list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt"); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; int side = l.side; @@ -294,8 +294,8 @@ void validate_coco_recall(char *cfgfile, char *weightfile) void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh) { dn_image **alphabet = load_alphabet(); - network *net = load_network(cfgfile, weightfile, 0); - layer l = net->layers[net->n-1]; + dn_network *net = load_network(cfgfile, weightfile, 0); + dn_layer l = net->layers[net->n-1]; set_batch_network(net, 1); srand(2222222); float nms = .4; diff --git a/examples/darknet.c b/examples/darknet.c index 34770b7c2bc..42b9888dddb 100644 --- a/examples/darknet.c +++ b/examples/darknet.c @@ -27,8 +27,8 @@ void average(int argc, char *argv[]) char *cfgfile = argv[2]; char *outfile = argv[3]; gpu_index = -1; - network *net = parse_network_cfg(cfgfile); - network *sum = parse_network_cfg(cfgfile); + dn_network *net = parse_network_cfg(cfgfile); + dn_network *sum = parse_network_cfg(cfgfile); char *weightfile = argv[4]; load_weights(sum, weightfile); @@ -39,8 +39,8 @@ void average(int argc, char *argv[]) weightfile = argv[i+5]; load_weights(net, weightfile); for(j = 0; j < net->n; ++j){ - layer l = net->layers[j]; - layer out = sum->layers[j]; + dn_layer l = net->layers[j]; + dn_layer out = sum->layers[j]; if(l.type == CONVOLUTIONAL){ int num = l.n*l.c*l.size*l.size; axpy_cpu(l.n, 1, l.biases, 1, out.biases, 1); @@ -59,7 +59,7 @@ void average(int argc, char *argv[]) } n = n+1; for(j = 0; j < net->n; ++j){ - layer l = sum->layers[j]; + dn_layer l = sum->layers[j]; if(l.type == CONVOLUTIONAL){ int num = l.n*l.c*l.size*l.size; scal_cpu(l.n, 1./n, l.biases, 1); @@ -78,12 +78,12 @@ void average(int argc, char *argv[]) save_weights(sum, outfile); } -long numops(network *net) +long numops(dn_network *net) { int i; long ops = 0; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL){ ops += 2l * l.n * l.size*l.size*l.c/l.groups * l.out_h*l.out_w; } else if(l.type == CONNECTED){ @@ -116,7 +116,7 @@ long numops(network *net) void speed(char *cfgfile, int tics) { if (tics == 0) tics = 1000; - network *net = parse_network_cfg(cfgfile); + dn_network *net = parse_network_cfg(cfgfile); set_batch_network(net, 1); int i; double time=what_time_is_it_now(); @@ -136,7 +136,7 @@ void speed(char *cfgfile, int tics) void operations(char *cfgfile) { gpu_index = -1; - network *net = parse_network_cfg(cfgfile); + dn_network *net = parse_network_cfg(cfgfile); long ops = numops(net); printf("Floating Point Operations: %ld\n", ops); printf("Floating Point Operations: %.2f Bn\n", (float)ops/1000000000.); @@ -145,7 +145,7 @@ void operations(char *cfgfile) void oneoff(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = parse_network_cfg(cfgfile); + dn_network *net = parse_network_cfg(cfgfile); int oldn = net->layers[net->n - 2].n; int c = net->layers[net->n - 2].c; scal_cpu(oldn*c, .1, net->layers[net->n - 2].weights, 1); @@ -160,7 +160,7 @@ void oneoff(char *cfgfile, char *weightfile, char *outfile) net->layers[net->n - 2].weights -= 5*c; net->layers[net->n - 2].n = oldn; printf("%d\n", oldn); - layer l = net->layers[net->n - 2]; + dn_layer l = net->layers[net->n - 2]; copy_cpu(l.n/3, l.biases, 1, l.biases + l.n/3, 1); copy_cpu(l.n/3, l.biases, 1, l.biases + 2*l.n/3, 1); copy_cpu(l.n/3*l.c, l.weights, 1, l.weights + l.n/3*l.c, 1); @@ -172,7 +172,7 @@ void oneoff(char *cfgfile, char *weightfile, char *outfile) void oneoff2(char *cfgfile, char *weightfile, char *outfile, int l) { gpu_index = -1; - network *net = parse_network_cfg(cfgfile); + dn_network *net = parse_network_cfg(cfgfile); if(weightfile){ load_weights_upto(net, weightfile, 0, net->n); load_weights_upto(net, weightfile, l, net->n); @@ -184,15 +184,15 @@ void oneoff2(char *cfgfile, char *weightfile, char *outfile, int l) void partial(char *cfgfile, char *weightfile, char *outfile, int max) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 1); + dn_network *net = load_network(cfgfile, weightfile, 1); save_weights_upto(net, outfile, max); } void print_weights(char *cfgfile, char *weightfile, int n) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 1); - layer l = net->layers[n]; + dn_network *net = load_network(cfgfile, weightfile, 1); + dn_layer l = net->layers[n]; int i, j; //printf("["); for(i = 0; i < l.n; ++i){ @@ -210,10 +210,10 @@ void print_weights(char *cfgfile, char *weightfile, int n) void rescale_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL){ rescale_weights(l, 2, -.5); break; @@ -225,10 +225,10 @@ void rescale_net(char *cfgfile, char *weightfile, char *outfile) void rgbgr_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL){ rgbgr_weights(l); break; @@ -240,10 +240,10 @@ void rgbgr_net(char *cfgfile, char *weightfile, char *outfile) void reset_normalize_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for (i = 0; i < net->n; ++i) { - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if (l.type == CONVOLUTIONAL && l.batch_normalize) { denormalize_convolutional_layer(l); } @@ -262,7 +262,7 @@ void reset_normalize_net(char *cfgfile, char *weightfile, char *outfile) save_weights(net, outfile); } -layer normalize_layer(layer l, int n) +dn_layer normalize_layer(dn_layer l, int n) { int j; l.batch_normalize=1; @@ -278,10 +278,10 @@ layer normalize_layer(layer l, int n) void normalize_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL && !l.batch_normalize){ net->layers[i] = normalize_layer(l, l.n); } @@ -304,10 +304,10 @@ void normalize_net(char *cfgfile, char *weightfile, char *outfile) void statistics_net(char *cfgfile, char *weightfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for (i = 0; i < net->n; ++i) { - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if (l.type == CONNECTED && l.batch_normalize) { printf("Connected Layer %d\n", i); statistics_connected_layer(l); @@ -334,10 +334,10 @@ void statistics_net(char *cfgfile, char *weightfile) void denormalize_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int i; for (i = 0; i < net->n; ++i) { - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if ((l.type == DECONVOLUTIONAL || l.type == CONVOLUTIONAL) && l.batch_normalize) { denormalize_convolutional_layer(l); net->layers[i].batch_normalize=0; @@ -367,7 +367,7 @@ void denormalize_net(char *cfgfile, char *weightfile, char *outfile) void mkimg(char *cfgfile, char *weightfile, int h, int w, int num, char *prefix) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); dn_image *ims = get_weights(net->layers[0]); int n = net->layers[0].n; int z; @@ -393,7 +393,7 @@ void mkimg(char *cfgfile, char *weightfile, int h, int w, int num, char *prefix) void visualize(char *cfgfile, char *weightfile) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); visualize_network(net); } diff --git a/examples/detector.c b/examples/detector.c index 5f9279825c4..fef03b04b2a 100644 --- a/examples/detector.c +++ b/examples/detector.c @@ -13,7 +13,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network **nets = calloc(ngpus, sizeof(network)); + dn_network **nets = calloc(ngpus, sizeof(dn_network)); srand(time(0)); int seed = rand(); @@ -27,13 +27,13 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; int imgs = net->batch * net->subdivisions * ngpus; printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); dn_data train, buffer; - layer l = net->layers[net->n - 1]; + dn_layer l = net->layers[net->n - 1]; int classes = l.classes; float jitter = l.jitter; @@ -243,7 +243,7 @@ void validate_detector_flip(char *datacfg, char *cfgfile, char *weightfile, char int *map = 0; if (mapf) map = read_map(mapf); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 2); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -251,7 +251,7 @@ void validate_detector_flip(char *datacfg, char *cfgfile, char *weightfile, char dn_list *plist = get_paths(valid_images); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; char buff[1024]; @@ -373,7 +373,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out int *map = 0; if (mapf) map = read_map(mapf); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -381,7 +381,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out dn_list *plist = get_paths(valid_images); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; char buff[1024]; @@ -488,7 +488,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out void validate_detector_recall(char *cfgfile, char *weightfile) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -496,7 +496,7 @@ void validate_detector_recall(char *cfgfile, char *weightfile) dn_list *plist = get_paths("data/coco_val_5k.list"); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int j, k; @@ -566,7 +566,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam char **names = get_labels(name_list); dn_image **alphabet = load_alphabet(); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); double time; @@ -589,7 +589,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam //image sized2 = resize_max(im, net->w); //image sized = crop_image(sized2, -((net->w - sized2.w)/2), -((net->h - sized2.h)/2), net->w, net->h); //resize_network(net, sized.w, sized.h); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; float *X = sized.data; diff --git a/examples/go.c b/examples/go.c index 1b8c6ab45d1..2d6cca0e908 100644 --- a/examples/go.c +++ b/examples/go.c @@ -138,7 +138,7 @@ void train_go(char *cfgfile, char *weightfile, char *filename, int *gpus, int ng char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -150,7 +150,7 @@ void train_go(char *cfgfile, char *weightfile, char *filename, int *gpus, int ng nets[i] = load_network(cfgfile, weightfile, clear); nets[i]->learning_rate *= ngpus; } - network *net = nets[0]; + dn_network *net = nets[0]; printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); char *backup_directory = "/home/pjreddie/backup/"; @@ -294,7 +294,7 @@ void flip_board(float *board) } } -float predict_move2(network *net, float *board, float *move, int multi) +float predict_move2(dn_network *net, float *board, float *move, int multi) { float *output = network_predict(net, board); copy_cpu(19*19+1, output, 1, move, 1); @@ -390,7 +390,7 @@ void free_mcts(mcts_tree *root) free(root); } -float *network_predict_rotations(network *net, float *next) +float *network_predict_rotations(dn_network *net, float *next) { int n = net->batch; float *in = calloc(19*19*3*n, sizeof(float)); @@ -421,7 +421,7 @@ float *network_predict_rotations(network *net, float *next) return pred; } -mcts_tree *expand(float *next, float *ko, network *net) +mcts_tree *expand(float *next, float *ko, dn_network *net) { mcts_tree *root = calloc(1, sizeof(mcts_tree)); root->board = next; @@ -458,7 +458,7 @@ float *copy_board(float *board) return next; } -float select_mcts(mcts_tree *root, network *net, float *prev, float cpuct) +float select_mcts(mcts_tree *root, dn_network *net, float *prev, float cpuct) { if(root->done) return -root->result; int i; @@ -507,7 +507,7 @@ float select_mcts(mcts_tree *root, network *net, float *prev, float cpuct) return -val; } -mcts_tree *run_mcts(mcts_tree *tree, network *net, float *board, float *ko, int player, int n, float cpuct, float secs) +mcts_tree *run_mcts(mcts_tree *tree, dn_network *net, float *board, float *ko, int player, int n, float cpuct, float secs) { int i; double t = what_time_is_it_now(); @@ -735,7 +735,7 @@ void valid_go(char *cfgfile, char *weightfile, int multi, char *filename) srand(time(0)); char *base = basecfg(cfgfile); printf("%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); @@ -797,7 +797,7 @@ int stdin_ready() return 0; } -mcts_tree *ponder(mcts_tree *tree, network *net, float *b, float *ko, int player, float cpuct) +mcts_tree *ponder(mcts_tree *tree, dn_network *net, float *b, float *ko, int player, float cpuct) { double t = what_time_is_it_now(); int count = 0; @@ -813,7 +813,7 @@ mcts_tree *ponder(mcts_tree *tree, network *net, float *b, float *ko, int player void engine_go(char *filename, char *weightfile, int mcts_iters, float secs, float temp, float cpuct, int anon, int resign) { mcts_tree *root = 0; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); set_batch_network(net, 1); srand(time(0)); float *board = calloc(19*19*3, sizeof(float)); @@ -1098,7 +1098,7 @@ void engine_go(char *filename, char *weightfile, int mcts_iters, float secs, flo void test_go(char *cfg, char *weights, int multi) { int i; - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); srand(time(0)); float *board = calloc(19*19*3, sizeof(float)); @@ -1214,17 +1214,17 @@ void self_go(char *filename, char *weightfile, char *f2, char *w2, int multi) { mcts_tree *tree1 = 0; mcts_tree *tree2 = 0; - network *net = load_network(filename, weightfile, 0); + dn_network *net = load_network(filename, weightfile, 0); //set_batch_network(net, 1); - network *net2; + dn_network *net2; if (f2) { net2 = parse_network_cfg(f2); if(w2){ load_weights(net2, w2); } } else { - net2 = calloc(1, sizeof(network)); + net2 = calloc(1, sizeof(dn_network)); *net2 = *net; } srand(time(0)); @@ -1282,7 +1282,7 @@ void self_go(char *filename, char *weightfile, char *f2, char *w2, int multi) //mcts_iters = 500; cpuct = 1; } - network *use = ((total%2==0) == (player==1)) ? net : net2; + dn_network *use = ((total%2==0) == (player==1)) ? net : net2; mcts_tree *t = ((total%2==0) == (player==1)) ? tree1 : tree2; t = run_mcts(t, use, board, two, player, mcts_iters, cpuct, 0); move m = pick_move(t, temp, player); diff --git a/examples/instance-segmenter.c b/examples/instance-segmenter.c index e7317260bf8..189ac1954af 100644 --- a/examples/instance-segmenter.c +++ b/examples/instance-segmenter.c @@ -11,7 +11,7 @@ void train_isegmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -24,7 +24,7 @@ void train_isegmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; dn_image pred = get_network_image(net); dn_image embed = pred; @@ -142,7 +142,7 @@ void train_isegmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, void predict_isegmenter(char *datafile, char *cfg, char *weights, char *filename) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/lsd.c b/examples/lsd.c index d8787286597..d55a2dce19d 100644 --- a/examples/lsd.c +++ b/examples/lsd.c @@ -410,7 +410,7 @@ dn_image random_unit_vector_image(int w, int h, int c) void inter_dcgan(char *cfgfile, char *weightfile) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); @@ -468,7 +468,7 @@ void inter_dcgan(char *cfgfile, char *weightfile) void test_dcgan(char *cfgfile, char *weightfile) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); @@ -502,7 +502,7 @@ void test_dcgan(char *cfgfile, char *weightfile) } } -void set_network_alpha_beta(network *net, float alpha, float beta) +void set_network_alpha_beta(dn_network *net, float alpha, float beta) { int i; for(i = 0; i < net->n; ++i){ @@ -1293,7 +1293,7 @@ save_weights(net, buff); void test_lsd(char *cfg, char *weights, char *filename, int gray) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/nightmare.c b/examples/nightmare.c index 4969a977f65..3c4e78c9f18 100644 --- a/examples/nightmare.c +++ b/examples/nightmare.c @@ -25,7 +25,7 @@ void calculate_loss(float *output, float *delta, int n, float thresh) } } -void optimize_picture(network *net, dn_image orig, int max_layer, float scale, float rate, float thresh, int norm) +void optimize_picture(dn_network *net, dn_image orig, int max_layer, float scale, float rate, float thresh, int norm) { //scale_image(orig, 2); //translate_image(orig, -1); @@ -40,7 +40,7 @@ void optimize_picture(network *net, dn_image orig, int max_layer, float scale, f if(flip) flip_image(im); resize_network(net, im.w, im.h); - layer last = net->layers[net->n-1]; + dn_layer last = net->layers[net->n-1]; //net->layers[net->n - 1].activation = LINEAR; dn_image delta = make_image(im.w, im.h, im.c); @@ -132,7 +132,7 @@ void smooth(dn_image recon, dn_image update, float lambda, int num) } } -void reconstruct_picture(network *net, float *features, dn_image recon, dn_image update, float rate, float momentum, float lambda, int smooth_size, int iters) +void reconstruct_picture(dn_network *net, float *features, dn_image recon, dn_image update, float rate, float momentum, float lambda, int smooth_size, int iters) { int iter = 0; for (iter = 0; iter < iters; ++iter) { @@ -313,7 +313,7 @@ void run_nightmare(int argc, char **argv) int reconstruct = find_arg(argc, argv, "-reconstruct"); int smooth_size = find_int_arg(argc, argv, "-smooth", 1); - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); char *cfgbase = basecfg(cfg); char *imbase = basecfg(input); diff --git a/examples/regressor.c b/examples/regressor.c index 92b3fb2bfbf..b09086f0ed0 100644 --- a/examples/regressor.c +++ b/examples/regressor.c @@ -10,7 +10,7 @@ void train_regressor(char *datacfg, char *cfgfile, char *weightfile, int *gpus, char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -23,7 +23,7 @@ void train_regressor(char *datacfg, char *cfgfile, char *weightfile, int *gpus, nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; int imgs = net->batch * net->subdivisions * ngpus; @@ -115,7 +115,7 @@ void train_regressor(char *datacfg, char *cfgfile, char *weightfile, int *gpus, void predict_regressor(char *cfgfile, char *weightfile, char *filename) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/rnn.c b/examples/rnn.c index d10dbc0c27f..f02bf890045 100644 --- a/examples/rnn.c +++ b/examples/rnn.c @@ -171,7 +171,7 @@ void train_char_rnn(char *cfgfile, char *weightfile, char *filename, int clear, char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); float avg_loss = -1; - network *net = load_network(cfgfile, weightfile, clear); + dn_network *net = load_network(cfgfile, weightfile, clear); int inputs = net->inputs; fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g, Inputs: %d %d %d\n", net->learning_rate, net->momentum, net->decay, inputs, net->batch, net->time_steps); @@ -254,7 +254,7 @@ void test_char_rnn(char *cfgfile, char *weightfile, int num, char *seed, float t char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int i, j; @@ -308,7 +308,7 @@ void test_tactic_rnn_multi(char *cfgfile, char *weightfile, int num, float temp, char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int i, j; @@ -353,7 +353,7 @@ void test_tactic_rnn(char *cfgfile, char *weightfile, int num, float temp, int r char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int i, j; @@ -388,7 +388,7 @@ void valid_tactic_rnn(char *cfgfile, char *weightfile, char *seed) char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int count = 0; @@ -437,7 +437,7 @@ void valid_char_rnn(char *cfgfile, char *weightfile, char *seed) char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int count = 0; @@ -475,7 +475,7 @@ void vec_char_rnn(char *cfgfile, char *weightfile, char *seed) char *base = basecfg(cfgfile); fprintf(stderr, "%s\n", base); - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); int inputs = net->inputs; int c; @@ -504,7 +504,7 @@ void vec_char_rnn(char *cfgfile, char *weightfile, char *seed) network_predict(net, input); input[(int)c] = 0; - layer l = net->layers[0]; + dn_layer l = net->layers[0]; #ifdef GPU cuda_pull_array(l.output_gpu, l.output, l.outputs); #endif diff --git a/examples/segmenter.c b/examples/segmenter.c index a9b8557c42b..b57bf968a6d 100644 --- a/examples/segmenter.c +++ b/examples/segmenter.c @@ -10,7 +10,7 @@ void train_segmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, char *base = basecfg(cfgfile); printf("%s\n", base); printf("%d\n", ngpus); - network **nets = calloc(ngpus, sizeof(network*)); + dn_network **nets = calloc(ngpus, sizeof(dn_network*)); srand(time(0)); int seed = rand(); @@ -23,7 +23,7 @@ void train_segmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, nets[i]->learning_rate *= ngpus; } srand(time(0)); - network *net = nets[0]; + dn_network *net = nets[0]; dn_image pred = get_network_image(net); int div = net->w/pred.w; @@ -130,7 +130,7 @@ void train_segmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, void predict_segmenter(char *datafile, char *cfg, char *weights, char *filename) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/super.c b/examples/super.c index 39f1e941020..9cf0b9d3456 100644 --- a/examples/super.c +++ b/examples/super.c @@ -8,7 +8,7 @@ void train_super(char *cfgfile, char *weightfile, int clear) char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network *net = load_network(cfgfile, weightfile, clear); + dn_network *net = load_network(cfgfile, weightfile, clear); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); int imgs = net->batch*net->subdivisions; int i = *net->seen/imgs; @@ -66,7 +66,7 @@ void train_super(char *cfgfile, char *weightfile, int clear) void test_super(char *cfgfile, char *weightfile, char *filename) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); diff --git a/examples/swag.c b/examples/swag.c index e1d7fbccb8d..9f6bab01826 100644 --- a/examples/swag.c +++ b/examples/swag.c @@ -9,7 +9,7 @@ void train_swag(char *cfgfile, char *weightfile) char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network* net = parse_network_cfg(cfgfile); + dn_network* net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(net, weightfile); } @@ -18,7 +18,7 @@ void train_swag(char *cfgfile, char *weightfile) int i = *net->seen/imgs; dn_data train, buffer; - layer l = net->layers[net->n - 1]; + dn_layer l = net->layers[net->n - 1]; int side = l.side; int classes = l.classes; diff --git a/examples/tag.c b/examples/tag.c index eb6e8a2113e..029f87240d1 100644 --- a/examples/tag.c +++ b/examples/tag.c @@ -7,7 +7,7 @@ void train_tag(char *cfgfile, char *weightfile, int clear) char *base = basecfg(cfgfile); char *backup_directory = "/home/pjreddie/backup/"; printf("%s\n", base); - network *net = load_network(cfgfile, weightfile, clear); + dn_network *net = load_network(cfgfile, weightfile, clear); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); int imgs = 1024; dn_list *plist = get_paths("/home/pjreddie/tag/train.list"); @@ -82,7 +82,7 @@ void train_tag(char *cfgfile, char *weightfile, int clear) void test_tag(char *cfgfile, char *weightfile, char *filename) { - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); set_batch_network(net, 1); srand(2222222); int i = 0; diff --git a/examples/voxel.c b/examples/voxel.c index fa4a4598d24..d84201fba2f 100644 --- a/examples/voxel.c +++ b/examples/voxel.c @@ -44,7 +44,7 @@ void train_voxel(char *cfgfile, char *weightfile) char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network* net = parse_network_cfg(cfgfile); + dn_network* net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(net, weightfile); } @@ -105,7 +105,7 @@ void train_voxel(char *cfgfile, char *weightfile) void test_voxel(char *cfgfile, char *weightfile, char *filename) { - network* net = parse_network_cfg(cfgfile); + dn_network* net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(net, weightfile); } diff --git a/examples/writing.c b/examples/writing.c index b0ac73bb7a7..5e2d029c987 100644 --- a/examples/writing.c +++ b/examples/writing.c @@ -7,7 +7,7 @@ void train_writing(char *cfgfile, char *weightfile) float avg_loss = -1; char *base = basecfg(cfgfile); printf("%s\n", base); - network* net = parse_network_cfg(cfgfile); + dn_network* net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(net, weightfile); } @@ -81,7 +81,7 @@ void train_writing(char *cfgfile, char *weightfile) void test_writing(char *cfgfile, char *weightfile, char *filename) { - network* net = parse_network_cfg(cfgfile); + dn_network* net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(net, weightfile); } diff --git a/examples/yolo.c b/examples/yolo.c index bd2050cbdb8..40f27f2f027 100644 --- a/examples/yolo.c +++ b/examples/yolo.c @@ -10,14 +10,14 @@ void train_yolo(char *cfgfile, char *weightfile) char *base = basecfg(cfgfile); printf("%s\n", base); float avg_loss = -1; - network *net = load_network(cfgfile, weightfile, 0); + dn_network *net = load_network(cfgfile, weightfile, 0); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); int imgs = net->batch*net->subdivisions; int i = *net->seen/imgs; dn_data train, buffer; - layer l = net->layers[net->n - 1]; + dn_layer l = net->layers[net->n - 1]; int side = l.side; int classes = l.classes; @@ -97,7 +97,7 @@ void print_yolo_detections(FILE **fps, char *id, int total, int classes, int w, void validate_yolo(char *cfg, char *weights) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -108,7 +108,7 @@ void validate_yolo(char *cfg, char *weights) //list *plist = get_paths("data/voc.2012.test"); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; int j; @@ -181,7 +181,7 @@ void validate_yolo(char *cfg, char *weights) void validate_yolo_recall(char *cfg, char *weights) { - network *net = load_network(cfg, weights, 0); + dn_network *net = load_network(cfg, weights, 0); set_batch_network(net, 1); fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay); srand(time(0)); @@ -190,7 +190,7 @@ void validate_yolo_recall(char *cfg, char *weights) dn_list *plist = get_paths("data/voc.2007.test"); char **paths = (char **)list_to_array(plist); - layer l = net->layers[net->n-1]; + dn_layer l = net->layers[net->n-1]; int classes = l.classes; int side = l.side; @@ -265,8 +265,8 @@ void validate_yolo_recall(char *cfg, char *weights) void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh) { dn_image **alphabet = load_alphabet(); - network *net = load_network(cfgfile, weightfile, 0); - layer l = net->layers[net->n-1]; + dn_network *net = load_network(cfgfile, weightfile, 0); + dn_layer l = net->layers[net->n-1]; set_batch_network(net, 1); srand(2222222); clock_t time; diff --git a/include/darknet.h b/include/darknet.h index a1b87b3f0a1..6947a904d97 100644 --- a/include/darknet.h +++ b/include/darknet.h @@ -106,22 +106,22 @@ typedef struct{ int t; } update_args; -struct network; -typedef struct network network; +struct dn_network; +typedef struct dn_network dn_network; -struct layer; -typedef struct layer layer; +struct dn_layer; +typedef struct dn_layer dn_layer; -struct layer{ +struct dn_layer{ LAYER_TYPE type; ACTIVATION activation; COST_TYPE cost_type; - void (*forward) (struct layer, struct network); - void (*backward) (struct layer, struct network); - void (*update) (struct layer, update_args); - void (*forward_gpu) (struct layer, struct network); - void (*backward_gpu) (struct layer, struct network); - void (*update_gpu) (struct layer, update_args); + void (*forward) (struct dn_layer, struct dn_network); + void (*backward) (struct dn_layer, struct dn_network); + void (*update) (struct dn_layer, update_args); + void (*forward_gpu) (struct dn_layer, struct dn_network); + void (*backward_gpu) (struct dn_layer, struct dn_network); + void (*update_gpu) (struct dn_layer, update_args); int batch_normalize; int shortcut; int batch; @@ -288,44 +288,44 @@ struct layer{ float * binary_input; - struct layer *input_layer; - struct layer *self_layer; - struct layer *output_layer; + struct dn_layer *input_layer; + struct dn_layer *self_layer; + struct dn_layer *output_layer; - struct layer *reset_layer; - struct layer *update_layer; - struct layer *state_layer; + struct dn_layer *reset_layer; + struct dn_layer *update_layer; + struct dn_layer *state_layer; - struct layer *input_gate_layer; - struct layer *state_gate_layer; - struct layer *input_save_layer; - struct layer *state_save_layer; - struct layer *input_state_layer; - struct layer *state_state_layer; + struct dn_layer *input_gate_layer; + struct dn_layer *state_gate_layer; + struct dn_layer *input_save_layer; + struct dn_layer *state_save_layer; + struct dn_layer *input_state_layer; + struct dn_layer *state_state_layer; - struct layer *input_z_layer; - struct layer *state_z_layer; + struct dn_layer *input_z_layer; + struct dn_layer *state_z_layer; - struct layer *input_r_layer; - struct layer *state_r_layer; + struct dn_layer *input_r_layer; + struct dn_layer *state_r_layer; - struct layer *input_h_layer; - struct layer *state_h_layer; + struct dn_layer *input_h_layer; + struct dn_layer *state_h_layer; - struct layer *wz; - struct layer *uz; - struct layer *wr; - struct layer *ur; - struct layer *wh; - struct layer *uh; - struct layer *uo; - struct layer *wo; - struct layer *uf; - struct layer *wf; - struct layer *ui; - struct layer *wi; - struct layer *ug; - struct layer *wg; + struct dn_layer *wz; + struct dn_layer *uz; + struct dn_layer *wr; + struct dn_layer *ur; + struct dn_layer *wh; + struct dn_layer *uh; + struct dn_layer *uo; + struct dn_layer *wo; + struct dn_layer *uf; + struct dn_layer *wf; + struct dn_layer *ui; + struct dn_layer *wi; + struct dn_layer *ug; + struct dn_layer *wg; dn_tree *softmax_tree; @@ -421,20 +421,20 @@ struct layer{ #endif }; -void free_layer(layer); +void free_layer(dn_layer); typedef enum { CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM } learning_rate_policy; -typedef struct network{ +typedef struct dn_network{ int n; int batch; size_t *seen; int *t; float epoch; int subdivisions; - layer *layers; + dn_layer *layers; float *output; learning_rate_policy policy; @@ -493,7 +493,7 @@ typedef struct network{ float *output_gpu; #endif -} network; +} dn_network; typedef struct { int w; @@ -584,8 +584,8 @@ typedef struct{ } box_label; -network *load_network(const char *cfg, const char *weights, int clear); -load_args get_base_args(network *net); +dn_network *load_network(const char *cfg, const char *weights, int clear); +load_args get_base_args(dn_network *net); void free_data(dn_data d); @@ -609,9 +609,9 @@ dn_data resize_data(dn_data orig, int w, int h); dn_data *tile_data(dn_data orig, int divs, int size); dn_data select_data(dn_data *orig, int *inds); -void forward_network(network *net); -void backward_network(network *net); -void update_network(network *net); +void forward_network(dn_network *net); +void backward_network(dn_network *net); +void update_network(dn_network *net); float dot_cpu(int N, float *X, int INCX, float *Y, int INCY); @@ -652,7 +652,7 @@ void get_next_batch(dn_data d, int n, int offset, float *X, float *y); void grayscale_image_3c(dn_image im); void normalize_image(dn_image p); void matrix_to_csv(dn_matrix m); -float train_network_sgd(network *net, dn_data d, int n); +float train_network_sgd(dn_network *net, dn_data d, int n); void rgbgr_image(dn_image im); dn_data copy_data(dn_data d); dn_data concat_data(dn_data d1, dn_data d2); @@ -661,36 +661,36 @@ float matrix_topk_accuracy(dn_matrix truth, dn_matrix guess, int k); void matrix_add_matrix(dn_matrix from, dn_matrix to); void scale_matrix(dn_matrix m, float scale); dn_matrix csv_to_matrix(const char *filename); -float *network_accuracies(network *net, dn_data d, int n); -float train_network_datum(network *net); +float *network_accuracies(dn_network *net, dn_data d, int n); +float train_network_datum(dn_network *net); dn_image make_random_image(int w, int h, int c); -void denormalize_connected_layer(layer l); -void denormalize_convolutional_layer(layer l); -void statistics_connected_layer(layer l); -void rescale_weights(layer l, float scale, float trans); -void rgbgr_weights(layer l); -dn_image *get_weights(layer l); +void denormalize_connected_layer(dn_layer l); +void denormalize_convolutional_layer(dn_layer l); +void statistics_connected_layer(dn_layer l); +void rescale_weights(dn_layer l, float scale, float trans); +void rgbgr_weights(dn_layer l); +dn_image *get_weights(dn_layer l); void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, int avg, float hier_thresh, int w, int h, int fps, int fullscreen); -void get_detection_detections(layer l, int w, int h, float thresh, detection *dets); +void get_detection_detections(dn_layer l, int w, int h, float thresh, detection *dets); char *option_find_str(dn_list *l, char *key, char *def); int option_find_int(dn_list *l, char *key, int def); int option_find_int_quiet(dn_list *l, char *key, int def); -network *parse_network_cfg(const char *filename); -void save_weights(network *net, const char *filename); -void load_weights(network *net, const char *filename); -void save_weights_upto(network *net, const char *filename, int cutoff); -void load_weights_upto(network *net, const char *filename, int start, int cutoff); - -void zero_objectness(layer l); -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); +dn_network *parse_network_cfg(const char *filename); +void save_weights(dn_network *net, const char *filename); +void load_weights(dn_network *net, const char *filename); +void save_weights_upto(dn_network *net, const char *filename, int cutoff); +void load_weights_upto(dn_network *net, const char *filename, int start, int cutoff); + +void zero_objectness(dn_layer l); +void get_region_detections(dn_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(dn_layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets); +void free_network(dn_network *net); +void set_batch_network(dn_network *net, int b); +void set_temp_network(dn_network *net, float t); dn_image load_image(const char *filename, int w, int h, int c); dn_image load_image_color(const char *filename, int w, int h); dn_image make_image(int w, int h, int c); @@ -703,50 +703,50 @@ dn_image resize_min(dn_image im, int min); dn_image resize_max(dn_image im, int max); dn_image threshold_image(dn_image im, float thresh); dn_image mask_to_rgb(dn_image mask); -int resize_network(network *net, int w, int h); +int resize_network(dn_network *net, int w, int h); void free_matrix(dn_matrix m); void test_resize(const char *filename); int show_image(dn_image p, const char *name, int ms); dn_image copy_image(dn_image p); void draw_box_width(dn_image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b); -float get_current_rate(network *net); +float get_current_rate(dn_network *net); void composite_3d(char *f1, char *f2, char *out, int delta); dn_data load_data_old(char **paths, int n, int m, char **labels, int k, int w, int h); -size_t get_current_batch(network *net); +size_t get_current_batch(dn_network *net); void constrain_image(dn_image im); -dn_image get_network_image_layer(network *net, int i); -layer get_network_output_layer(network *net); -void top_predictions(network *net, int n, int *index); +dn_image get_network_image_layer(dn_network *net, int i); +dn_layer get_network_output_layer(dn_network *net); +void top_predictions(dn_network *net, int n, int *index); void flip_image(dn_image a); dn_image float_to_image(int w, int h, int c, float *data); void ghost_image(dn_image source, dn_image dest, int dx, int dy); -float network_accuracy(network *net, dn_data d); +float network_accuracy(dn_network *net, dn_data d); void random_distort_image(dn_image im, float hue, float saturation, float exposure); void fill_image(dn_image m, float s); dn_image grayscale_image(dn_image im); void rotate_image_cw(dn_image im, int times); double what_time_is_it_now(); dn_image rotate_image(dn_image m, float rad); -void visualize_network(network *net); +void visualize_network(dn_network *net); float box_iou(dn_box a, dn_box b); dn_data load_all_cifar10(); box_label *read_boxes(const char *filename, int *n); dn_box float_to_box(float *f, int stride); void draw_detections(dn_image im, detection *dets, int num, float thresh, char **names, dn_image **alphabet, int classes); -dn_matrix network_predict_data(network *net, dn_data test); +dn_matrix network_predict_data(dn_network *net, dn_data test); dn_image **load_alphabet(); -dn_image get_network_image(network *net); -float *network_predict(network *net, float *input); - -int network_width(network *net); -int network_height(network *net); -float *network_predict_image(network *net, dn_image im); -void network_detect(network *net, dn_image im, float thresh, float hier_thresh, float nms, detection *dets); -detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num); +dn_image get_network_image(dn_network *net); +float *network_predict(dn_network *net, float *input); + +int network_width(dn_network *net); +int network_height(dn_network *net); +float *network_predict_image(dn_network *net, dn_image im); +void network_detect(dn_network *net, dn_image im, float thresh, float hier_thresh, float nms, detection *dets); +detection *get_network_boxes(dn_network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num); void free_detections(detection *dets, int n); -void reset_network_state(network *net, int b); +void reset_network_state(dn_network *net, int b); char **get_labels(const char *filename); void do_nms_obj(detection *dets, int total, int classes, float thresh); @@ -761,7 +761,7 @@ void make_window(char *name, int w, int h, int fullscreen); #endif void free_image(dn_image m); -float train_network(network *net, dn_data d); +float train_network(dn_network *net, dn_data d); pthread_t load_data_in_thread(load_args args); void load_data_blocking(load_args args); dn_list *get_paths(const char *filename); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 33124acd9af..b9e5653a2c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,5 +11,5 @@ if ( GPU ) endif() message("SOURCE_FILES = ${SOURCE_FILES}") -add_library(DarkNet ${HEADER_FILES} ${SOURCE_FILES} ${CUDA_FILES}) +add_library(DarkNet SHARED ${HEADER_FILES} ${SOURCE_FILES} ${CUDA_FILES}) SET_TARGET_PROPERTIES(DarkNet PROPERTIES LINKER_LANGUAGE C) diff --git a/src/activation_layer.c b/src/activation_layer.c index b4ba953967b..b9cb8a23bf1 100644 --- a/src/activation_layer.c +++ b/src/activation_layer.c @@ -9,9 +9,9 @@ #include #include -layer make_activation_layer(int batch, int inputs, ACTIVATION activation) +dn_layer make_activation_layer(int batch, int inputs, ACTIVATION activation) { - layer l = {0}; + dn_layer l = {0}; l.type = ACTIVE; l.inputs = inputs; @@ -35,13 +35,13 @@ layer make_activation_layer(int batch, int inputs, ACTIVATION activation) return l; } -void forward_activation_layer(layer l, network net) +void forward_activation_layer(dn_layer l, dn_network net) { copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); activate_array(l.output, l.outputs*l.batch, l.activation); } -void backward_activation_layer(layer l, network net) +void backward_activation_layer(dn_layer l, dn_network net) { gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); copy_cpu(l.outputs*l.batch, l.delta, 1, net.delta, 1); diff --git a/src/activation_layer.h b/src/activation_layer.h index 42118a84e83..076424bb2a1 100644 --- a/src/activation_layer.h +++ b/src/activation_layer.h @@ -5,10 +5,10 @@ #include "layer.h" #include "network.h" -layer make_activation_layer(int batch, int inputs, ACTIVATION activation); +dn_layer make_activation_layer(int batch, int inputs, ACTIVATION activation); -void forward_activation_layer(layer l, network net); -void backward_activation_layer(layer l, network net); +void forward_activation_layer(dn_layer l, dn_network net); +void backward_activation_layer(dn_layer l, dn_network net); #ifdef GPU void forward_activation_layer_gpu(layer l, network net); diff --git a/src/avgpool_layer.c b/src/avgpool_layer.c index 83034dbecf4..4b29d7632e0 100644 --- a/src/avgpool_layer.c +++ b/src/avgpool_layer.c @@ -37,7 +37,7 @@ void resize_avgpool_layer(avgpool_layer *l, int w, int h) l->inputs = h*w*l->c; } -void forward_avgpool_layer(const avgpool_layer l, network net) +void forward_avgpool_layer(const avgpool_layer l, dn_network net) { int b,i,k; @@ -54,7 +54,7 @@ void forward_avgpool_layer(const avgpool_layer l, network net) } } -void backward_avgpool_layer(const avgpool_layer l, network net) +void backward_avgpool_layer(const avgpool_layer l, dn_network net) { int b,i,k; diff --git a/src/avgpool_layer.h b/src/avgpool_layer.h index 23369dee7df..4d671453ac0 100644 --- a/src/avgpool_layer.h +++ b/src/avgpool_layer.h @@ -6,13 +6,13 @@ #include "layer.h" #include "network.h" -typedef layer avgpool_layer; +typedef dn_layer avgpool_layer; dn_image get_avgpool_image(avgpool_layer l); avgpool_layer make_avgpool_layer(int batch, int w, int h, int c); void resize_avgpool_layer(avgpool_layer *l, int w, int h); -void forward_avgpool_layer(const avgpool_layer l, network net); -void backward_avgpool_layer(const avgpool_layer l, network net); +void forward_avgpool_layer(const avgpool_layer l, dn_network net); +void backward_avgpool_layer(const avgpool_layer l, dn_network net); #ifdef GPU void forward_avgpool_layer_gpu(avgpool_layer l, network net); diff --git a/src/batchnorm_layer.c b/src/batchnorm_layer.c index ebff387cc4b..d548a7b90d0 100644 --- a/src/batchnorm_layer.c +++ b/src/batchnorm_layer.c @@ -3,10 +3,10 @@ #include "blas.h" #include -layer make_batchnorm_layer(int batch, int w, int h, int c) +dn_layer make_batchnorm_layer(int batch, int w, int h, int c) { fprintf(stderr, "Batch Normalization Layer: %d x %d x %d image\n", w,h,c); - layer l = {0}; + dn_layer l = {0}; l.type = BATCHNORM; l.batch = batch; l.h = l.out_h = h; @@ -127,12 +127,12 @@ void normalize_delta_cpu(float *x, float *mean, float *variance, float *mean_del } } -void resize_batchnorm_layer(layer *layer, int w, int h) +void resize_batchnorm_layer(dn_layer *layer, int w, int h) { fprintf(stderr, "Not implemented\n"); } -void forward_batchnorm_layer(layer l, network net) +void forward_batchnorm_layer(dn_layer l, dn_network net) { if(l.type == BATCHNORM) copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); copy_cpu(l.outputs*l.batch, l.output, 1, l.x, 1); @@ -154,7 +154,7 @@ void forward_batchnorm_layer(layer l, network net) add_bias(l.output, l.biases, l.batch, l.out_c, l.out_h*l.out_w); } -void backward_batchnorm_layer(layer l, network net) +void backward_batchnorm_layer(dn_layer l, dn_network net) { if(!net.train){ l.mean = l.rolling_mean; diff --git a/src/batchnorm_layer.h b/src/batchnorm_layer.h index 25a18a3c8f2..b6216d85c8f 100644 --- a/src/batchnorm_layer.h +++ b/src/batchnorm_layer.h @@ -5,9 +5,9 @@ #include "layer.h" #include "network.h" -layer make_batchnorm_layer(int batch, int w, int h, int c); -void forward_batchnorm_layer(layer l, network net); -void backward_batchnorm_layer(layer l, network net); +dn_layer make_batchnorm_layer(int batch, int w, int h, int c); +void forward_batchnorm_layer(dn_layer l, dn_network net); +void backward_batchnorm_layer(dn_layer l, dn_network net); #ifdef GPU void forward_batchnorm_layer_gpu(layer l, network net); diff --git a/src/connected_layer.c b/src/connected_layer.c index 353f4e5677b..d5b64b2f0b4 100644 --- a/src/connected_layer.c +++ b/src/connected_layer.c @@ -11,10 +11,10 @@ #include #include -layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam) +dn_layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam) { int i; - layer l = {0}; + dn_layer l = {0}; l.learning_rate_scale = 1; l.type = CONNECTED; @@ -129,7 +129,7 @@ layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activa return l; } -void update_connected_layer(layer l, update_args a) +void update_connected_layer(dn_layer l, update_args a) { float learning_rate = a.learning_rate*l.learning_rate_scale; float momentum = a.momentum; @@ -148,7 +148,7 @@ void update_connected_layer(layer l, update_args a) scal_cpu(l.inputs*l.outputs, momentum, l.weight_updates, 1); } -void forward_connected_layer(layer l, network net) +void forward_connected_layer(dn_layer l, dn_network net) { fill_cpu(l.outputs*l.batch, 0, l.output, 1); int m = l.batch; @@ -166,7 +166,7 @@ void forward_connected_layer(layer l, network net) activate_array(l.output, l.outputs*l.batch, l.activation); } -void backward_connected_layer(layer l, network net) +void backward_connected_layer(dn_layer l, dn_network net) { gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); @@ -196,7 +196,7 @@ void backward_connected_layer(layer l, network net) } -void denormalize_connected_layer(layer l) +void denormalize_connected_layer(dn_layer l) { int i, j; for(i = 0; i < l.outputs; ++i){ @@ -212,7 +212,7 @@ void denormalize_connected_layer(layer l) } -void statistics_connected_layer(layer l) +void statistics_connected_layer(dn_layer l) { if(l.batch_normalize){ printf("Scales "); diff --git a/src/connected_layer.h b/src/connected_layer.h index 6727a964eaa..df9cb53c892 100644 --- a/src/connected_layer.h +++ b/src/connected_layer.h @@ -5,11 +5,11 @@ #include "layer.h" #include "network.h" -layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam); +dn_layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam); -void forward_connected_layer(layer l, network net); -void backward_connected_layer(layer l, network net); -void update_connected_layer(layer l, update_args a); +void forward_connected_layer(dn_layer l, dn_network net); +void backward_connected_layer(dn_layer l, dn_network net); +void update_connected_layer(dn_layer l, update_args a); #ifdef GPU void forward_connected_layer_gpu(layer l, network net); diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c index 57a12cf8dbe..a8b13d568bb 100644 --- a/src/convolutional_layer.c +++ b/src/convolutional_layer.c @@ -83,7 +83,7 @@ dn_image get_convolutional_delta(convolutional_layer l) return float_to_image(l.out_w,l.out_h,l.out_c,l.delta); } -static size_t get_workspace_size(layer l){ +static size_t get_workspace_size(dn_layer l){ #ifdef CUDNN if(gpu_index >= 0){ size_t most = 0; @@ -445,7 +445,7 @@ void backward_bias(float *bias_updates, float *delta, int batch, int n, int size } } -void forward_convolutional_layer(convolutional_layer l, network net) +void forward_convolutional_layer(convolutional_layer l, dn_network net) { int i, j; @@ -487,7 +487,7 @@ void forward_convolutional_layer(convolutional_layer l, network net) if(l.binary || l.xnor) swap_binary(&l); } -void backward_convolutional_layer(convolutional_layer l, network net) +void backward_convolutional_layer(convolutional_layer l, dn_network net) { int i, j; int m = l.n/l.groups; diff --git a/src/convolutional_layer.h b/src/convolutional_layer.h index 1c252ef43e2..732af16b1da 100644 --- a/src/convolutional_layer.h +++ b/src/convolutional_layer.h @@ -7,7 +7,7 @@ #include "layer.h" #include "network.h" -typedef layer convolutional_layer; +typedef dn_layer convolutional_layer; #ifdef GPU void forward_convolutional_layer_gpu(convolutional_layer layer, network net); @@ -27,14 +27,14 @@ void cudnn_convolutional_setup(layer *l); convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam); void resize_convolutional_layer(convolutional_layer *layer, int w, int h); -void forward_convolutional_layer(const convolutional_layer layer, network net); +void forward_convolutional_layer(const convolutional_layer layer, dn_network net); void update_convolutional_layer(convolutional_layer layer, update_args a); dn_image *visualize_convolutional_layer(convolutional_layer layer, char *window, dn_image *prev_weights); void binarize_weights(float *weights, int n, int size, float *binary); void swap_binary(convolutional_layer *l); void binarize_weights2(float *weights, int n, int size, char *binary, float *scales); -void backward_convolutional_layer(convolutional_layer layer, network net); +void backward_convolutional_layer(convolutional_layer layer, dn_network net); void add_bias(float *output, float *biases, int batch, int n, int size); void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); diff --git a/src/cost_layer.c b/src/cost_layer.c index 2138ff2617a..9b37f9f10db 100644 --- a/src/cost_layer.c +++ b/src/cost_layer.c @@ -79,7 +79,7 @@ void resize_cost_layer(cost_layer *l, int inputs) #endif } -void forward_cost_layer(cost_layer l, network net) +void forward_cost_layer(cost_layer l, dn_network net) { if (!net.truth) return; if(l.cost_type == MASKED){ @@ -98,7 +98,7 @@ void forward_cost_layer(cost_layer l, network net) l.cost[0] = sum_array(l.output, l.batch*l.inputs); } -void backward_cost_layer(const cost_layer l, network net) +void backward_cost_layer(const cost_layer l, dn_network net) { axpy_cpu(l.batch*l.inputs, l.scale, l.delta, 1, net.delta, 1); } diff --git a/src/cost_layer.h b/src/cost_layer.h index ceb64de00bf..5396b0ce2d7 100644 --- a/src/cost_layer.h +++ b/src/cost_layer.h @@ -3,13 +3,13 @@ #include "layer.h" #include "network.h" -typedef layer cost_layer; +typedef dn_layer cost_layer; COST_TYPE get_cost_type(char *s); char *get_cost_string(COST_TYPE a); cost_layer make_cost_layer(int batch, int inputs, COST_TYPE type, float scale); -void forward_cost_layer(const cost_layer l, network net); -void backward_cost_layer(const cost_layer l, network net); +void forward_cost_layer(const cost_layer l, dn_network net); +void backward_cost_layer(const cost_layer l, dn_network net); void resize_cost_layer(cost_layer *l, int inputs); #ifdef GPU diff --git a/src/crnn_layer.c b/src/crnn_layer.c index 7dd29f62b7a..680ca5c93c3 100644 --- a/src/crnn_layer.c +++ b/src/crnn_layer.c @@ -10,7 +10,7 @@ #include #include -static void increment_layer(layer *l, int steps) +static void increment_layer(dn_layer *l, int steps) { int num = l->outputs*l->batch*steps; l->output += num; @@ -26,11 +26,11 @@ static void increment_layer(layer *l, int steps) #endif } -layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize) +dn_layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize) { fprintf(stderr, "CRNN Layer: %d x %d x %d image, %d filters\n", h,w,c,output_filters); batch = batch / steps; - layer l = {0}; + dn_layer l = {0}; l.batch = batch; l.type = CRNN; l.steps = steps; @@ -46,17 +46,17 @@ layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int ou l.state = calloc(l.hidden*batch*(steps+1), sizeof(float)); - l.input_layer = malloc(sizeof(layer)); + l.input_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.input_layer) = make_convolutional_layer(batch*steps, h, w, c, hidden_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); l.input_layer->batch = batch; - l.self_layer = malloc(sizeof(layer)); + l.self_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.self_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, hidden_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); l.self_layer->batch = batch; - l.output_layer = malloc(sizeof(layer)); + l.output_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.output_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, output_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); l.output_layer->batch = batch; @@ -81,21 +81,21 @@ layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int ou return l; } -void update_crnn_layer(layer l, update_args a) +void update_crnn_layer(dn_layer l, update_args a) { update_convolutional_layer(*(l.input_layer), a); update_convolutional_layer(*(l.self_layer), a); update_convolutional_layer(*(l.output_layer), a); } -void forward_crnn_layer(layer l, network net) +void forward_crnn_layer(dn_layer l, dn_network net) { - network s = net; + dn_network s = net; s.train = net.train; int i; - layer input_layer = *(l.input_layer); - layer self_layer = *(l.self_layer); - layer output_layer = *(l.output_layer); + dn_layer input_layer = *(l.input_layer); + dn_layer self_layer = *(l.self_layer); + dn_layer output_layer = *(l.output_layer); fill_cpu(l.outputs * l.batch * l.steps, 0, output_layer.delta, 1); fill_cpu(l.hidden * l.batch * l.steps, 0, self_layer.delta, 1); @@ -129,13 +129,13 @@ void forward_crnn_layer(layer l, network net) } } -void backward_crnn_layer(layer l, network net) +void backward_crnn_layer(dn_layer l, dn_network net) { - network s = net; + dn_network s = net; int i; - layer input_layer = *(l.input_layer); - layer self_layer = *(l.self_layer); - layer output_layer = *(l.output_layer); + dn_layer input_layer = *(l.input_layer); + dn_layer self_layer = *(l.self_layer); + dn_layer output_layer = *(l.output_layer); increment_layer(&input_layer, l.steps-1); increment_layer(&self_layer, l.steps-1); diff --git a/src/crnn_layer.h b/src/crnn_layer.h index 515f378354e..c1198298c55 100644 --- a/src/crnn_layer.h +++ b/src/crnn_layer.h @@ -6,11 +6,11 @@ #include "layer.h" #include "network.h" -layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize); +dn_layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize); -void forward_crnn_layer(layer l, network net); -void backward_crnn_layer(layer l, network net); -void update_crnn_layer(layer l, update_args a); +void forward_crnn_layer(dn_layer l, dn_network net); +void backward_crnn_layer(dn_layer l, dn_network net); +void update_crnn_layer(dn_layer l, update_args a); #ifdef GPU void forward_crnn_layer_gpu(layer l, network net); diff --git a/src/crop_layer.c b/src/crop_layer.c index 4efb442e969..fd446157f1f 100644 --- a/src/crop_layer.c +++ b/src/crop_layer.c @@ -10,8 +10,8 @@ dn_image get_crop_image(crop_layer l) return float_to_image(w,h,c,l.output); } -void backward_crop_layer(const crop_layer l, network net){} -void backward_crop_layer_gpu(const crop_layer l, network net){} +void backward_crop_layer(const crop_layer l, dn_network net){} +void backward_crop_layer_gpu(const crop_layer l, dn_network net){} crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure) { @@ -45,7 +45,7 @@ crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int return l; } -void resize_crop_layer(layer *l, int w, int h) +void resize_crop_layer(dn_layer *l, int w, int h) { l->w = w; l->h = h; @@ -64,7 +64,7 @@ void resize_crop_layer(layer *l, int w, int h) } -void forward_crop_layer(const crop_layer l, network net) +void forward_crop_layer(const crop_layer l, dn_network net) { int i,j,c,b,row,col; int index; diff --git a/src/crop_layer.h b/src/crop_layer.h index 51d10791ffd..501b4b2769d 100644 --- a/src/crop_layer.h +++ b/src/crop_layer.h @@ -5,12 +5,12 @@ #include "layer.h" #include "network.h" -typedef layer crop_layer; +typedef dn_layer crop_layer; dn_image get_crop_image(crop_layer l); crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure); -void forward_crop_layer(const crop_layer l, network net); -void resize_crop_layer(layer *l, int w, int h); +void forward_crop_layer(const crop_layer l, dn_network net); +void resize_crop_layer(dn_layer *l, int w, int h); #ifdef GPU void forward_crop_layer_gpu(crop_layer l, network net); diff --git a/src/cuda/avgpool_layer_kernels.cu b/src/cuda/avgpool_layer_kernels.cu index a7eca3aeae9..5795681d82b 100644 --- a/src/cuda/avgpool_layer_kernels.cu +++ b/src/cuda/avgpool_layer_kernels.cu @@ -43,7 +43,7 @@ __global__ void backward_avgpool_layer_kernel(int n, int w, int h, int c, float } } -extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, network net) +extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, dn_network net) { size_t n = layer.c*layer.batch; @@ -51,7 +51,7 @@ extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, network net) check_error(cudaPeekAtLastError()); } -extern "C" void backward_avgpool_layer_gpu(avgpool_layer layer, network net) +extern "C" void backward_avgpool_layer_gpu(avgpool_layer layer, dn_network net) { size_t n = layer.c*layer.batch; diff --git a/src/cuda/convolutional_kernels.cu b/src/cuda/convolutional_kernels.cu index 4a1047b8743..023fd41ab2c 100644 --- a/src/cuda/convolutional_kernels.cu +++ b/src/cuda/convolutional_kernels.cu @@ -70,7 +70,7 @@ void binarize_weights_gpu(float *weights, int n, int size, float *binary) check_error(cudaPeekAtLastError()); } -void forward_convolutional_layer_gpu(convolutional_layer l, network net) +void forward_convolutional_layer_gpu(convolutional_layer l, dn_network net) { fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1); if(l.binary){ @@ -164,7 +164,7 @@ __global__ void smooth_kernel(float *x, int n, int w, int h, int c, int size, fl } } -extern "C" void smooth_layer(layer l, int size, float rate) +extern "C" void smooth_layer(dn_layer l, int size, float rate) { int h = l.out_h; int w = l.out_w; @@ -176,7 +176,7 @@ extern "C" void smooth_layer(layer l, int size, float rate) check_error(cudaPeekAtLastError()); } -void backward_convolutional_layer_gpu(convolutional_layer l, network net) +void backward_convolutional_layer_gpu(convolutional_layer l, dn_network net) { if(l.smooth){ smooth_layer(l, 5, l.smooth); @@ -270,7 +270,7 @@ void backward_convolutional_layer_gpu(convolutional_layer l, network net) #endif } -void pull_convolutional_layer(layer l) +void pull_convolutional_layer(dn_layer l) { cuda_pull_array(l.weights_gpu, l.weights, l.nweights); cuda_pull_array(l.biases_gpu, l.biases, l.n); @@ -283,7 +283,7 @@ void pull_convolutional_layer(layer l) } } -void push_convolutional_layer(layer l) +void push_convolutional_layer(dn_layer l) { cuda_push_array(l.weights_gpu, l.weights, l.nweights); cuda_push_array(l.biases_gpu, l.biases, l.n); @@ -296,7 +296,7 @@ void push_convolutional_layer(layer l) } } -void update_convolutional_layer_gpu(layer l, update_args a) +void update_convolutional_layer_gpu(dn_layer l, update_args a) { float learning_rate = a.learning_rate*l.learning_rate_scale; float momentum = a.momentum; diff --git a/src/cuda/crop_layer_kernels.cu b/src/cuda/crop_layer_kernels.cu index b5b9f554627..345492c74be 100644 --- a/src/cuda/crop_layer_kernels.cu +++ b/src/cuda/crop_layer_kernels.cu @@ -180,7 +180,7 @@ __global__ void forward_crop_layer_kernel(float *input, float *rand, int size, i output[count] = bilinear_interpolate_kernel(input, w, h, rx, ry, k); } -extern "C" void forward_crop_layer_gpu(crop_layer layer, network net) +extern "C" void forward_crop_layer_gpu(crop_layer layer, dn_network net) { cuda_random(layer.rand_gpu, layer.batch*8); diff --git a/src/cuda/deconvolutional_kernels.cu b/src/cuda/deconvolutional_kernels.cu index 8267dcfa25b..8d0d3f30be6 100644 --- a/src/cuda/deconvolutional_kernels.cu +++ b/src/cuda/deconvolutional_kernels.cu @@ -14,7 +14,7 @@ extern "C" { #include "cuda.h" } -extern "C" void forward_deconvolutional_layer_gpu(layer l, network net) +extern "C" void forward_deconvolutional_layer_gpu(dn_layer l, dn_network net) { int i; @@ -41,7 +41,7 @@ extern "C" void forward_deconvolutional_layer_gpu(layer l, network net) activate_array_gpu(l.output_gpu, l.batch*l.n*l.out_w*l.out_h, l.activation); } -extern "C" void backward_deconvolutional_layer_gpu(layer l, network net) +extern "C" void backward_deconvolutional_layer_gpu(dn_layer l, dn_network net) { int i; @@ -83,7 +83,7 @@ extern "C" void backward_deconvolutional_layer_gpu(layer l, network net) } } -extern "C" void pull_deconvolutional_layer(layer l) +extern "C" void pull_deconvolutional_layer(dn_layer l) { cuda_pull_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size); cuda_pull_array(l.biases_gpu, l.biases, l.n); @@ -96,7 +96,7 @@ extern "C" void pull_deconvolutional_layer(layer l) } } -extern "C" void push_deconvolutional_layer(layer l) +extern "C" void push_deconvolutional_layer(dn_layer l) { cuda_push_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size); cuda_push_array(l.biases_gpu, l.biases, l.n); @@ -109,7 +109,7 @@ extern "C" void push_deconvolutional_layer(layer l) } } -void update_deconvolutional_layer_gpu(layer l, update_args a) +void update_deconvolutional_layer_gpu(dn_layer l, update_args a) { float learning_rate = a.learning_rate*l.learning_rate_scale; float momentum = a.momentum; diff --git a/src/cuda/dropout_layer_kernels.cu b/src/cuda/dropout_layer_kernels.cu index bd12b678758..05eb03a6758 100644 --- a/src/cuda/dropout_layer_kernels.cu +++ b/src/cuda/dropout_layer_kernels.cu @@ -14,7 +14,7 @@ __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale; } -void forward_dropout_layer_gpu(dropout_layer layer, network net) +void forward_dropout_layer_gpu(dropout_layer layer, dn_network net) { if (!net.train) return; int size = layer.inputs*layer.batch; @@ -31,7 +31,7 @@ void forward_dropout_layer_gpu(dropout_layer layer, network net) check_error(cudaPeekAtLastError()); } -void backward_dropout_layer_gpu(dropout_layer layer, network net) +void backward_dropout_layer_gpu(dropout_layer layer, dn_network net) { if(!net.delta_gpu) return; int size = layer.inputs*layer.batch; diff --git a/src/cuda/maxpool_layer_kernels.cu b/src/cuda/maxpool_layer_kernels.cu index 869ef466af5..28652c63949 100644 --- a/src/cuda/maxpool_layer_kernels.cu +++ b/src/cuda/maxpool_layer_kernels.cu @@ -84,7 +84,7 @@ __global__ void backward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_ prev_delta[index] += d; } -extern "C" void forward_maxpool_layer_gpu(maxpool_layer layer, network net) +extern "C" void forward_maxpool_layer_gpu(maxpool_layer layer, dn_network net) { int h = layer.out_h; int w = layer.out_w; @@ -96,7 +96,7 @@ extern "C" void forward_maxpool_layer_gpu(maxpool_layer layer, network net) check_error(cudaPeekAtLastError()); } -extern "C" void backward_maxpool_layer_gpu(maxpool_layer layer, network net) +extern "C" void backward_maxpool_layer_gpu(maxpool_layer layer, dn_network net) { size_t n = layer.h*layer.w*layer.c*layer.batch; diff --git a/src/deconvolutional_layer.c b/src/deconvolutional_layer.c index 00c0e85771d..c06ec359fb0 100644 --- a/src/deconvolutional_layer.c +++ b/src/deconvolutional_layer.c @@ -11,11 +11,11 @@ #include -static size_t get_workspace_size(layer l){ +static size_t get_workspace_size(dn_layer l){ return (size_t)l.h*l.w*l.size*l.size*l.n*sizeof(float); } -void bilinear_init(layer l) +void bilinear_init(dn_layer l) { int i,j,f; float center = (l.size-1) / 2.; @@ -32,10 +32,10 @@ void bilinear_init(layer l) } -layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam) +dn_layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam) { int i; - layer l = {0}; + dn_layer l = {0}; l.type = DECONVOLUTIONAL; l.h = h; @@ -165,7 +165,7 @@ layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size return l; } -void denormalize_deconvolutional_layer(layer l) +void denormalize_deconvolutional_layer(dn_layer l) { int i, j; for(i = 0; i < l.n; ++i){ @@ -180,7 +180,7 @@ void denormalize_deconvolutional_layer(layer l) } } -void resize_deconvolutional_layer(layer *l, int h, int w) +void resize_deconvolutional_layer(dn_layer *l, int h, int w) { l->h = h; l->w = w; @@ -219,7 +219,7 @@ void resize_deconvolutional_layer(layer *l, int h, int w) l->workspace_size = get_workspace_size(*l); } -void forward_deconvolutional_layer(const layer l, network net) +void forward_deconvolutional_layer(const dn_layer l, dn_network net) { int i; @@ -246,7 +246,7 @@ void forward_deconvolutional_layer(const layer l, network net) activate_array(l.output, l.batch*l.n*l.out_w*l.out_h, l.activation); } -void backward_deconvolutional_layer(layer l, network net) +void backward_deconvolutional_layer(dn_layer l, dn_network net) { int i; @@ -287,7 +287,7 @@ void backward_deconvolutional_layer(layer l, network net) } } -void update_deconvolutional_layer(layer l, update_args a) +void update_deconvolutional_layer(dn_layer l, update_args a) { float learning_rate = a.learning_rate*l.learning_rate_scale; float momentum = a.momentum; diff --git a/src/deconvolutional_layer.h b/src/deconvolutional_layer.h index b254fb91e69..a8b783b5cce 100644 --- a/src/deconvolutional_layer.h +++ b/src/deconvolutional_layer.h @@ -15,11 +15,11 @@ void push_deconvolutional_layer(layer l); void pull_deconvolutional_layer(layer l); #endif -layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam); -void resize_deconvolutional_layer(layer *l, int h, int w); -void forward_deconvolutional_layer(const layer l, network net); -void update_deconvolutional_layer(layer l, update_args a); -void backward_deconvolutional_layer(layer l, network net); +dn_layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam); +void resize_deconvolutional_layer(dn_layer *l, int h, int w); +void forward_deconvolutional_layer(const dn_layer l, dn_network net); +void update_deconvolutional_layer(dn_layer l, update_args a); +void backward_deconvolutional_layer(dn_layer l, dn_network net); #endif diff --git a/src/detection_layer.c b/src/detection_layer.c index f1c98fa9cbd..90e305e4ac3 100644 --- a/src/detection_layer.c +++ b/src/detection_layer.c @@ -47,7 +47,7 @@ detection_layer make_detection_layer(int batch, int inputs, int n, int side, int return l; } -void forward_detection_layer(const detection_layer l, network net) +void forward_detection_layer(const detection_layer l, dn_network net) { int locations = l.side*l.side; int i,j; @@ -217,12 +217,12 @@ void forward_detection_layer(const detection_layer l, network net) } } -void backward_detection_layer(const detection_layer l, network net) +void backward_detection_layer(const detection_layer l, dn_network net) { axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); } -void get_detection_detections(layer l, int w, int h, float thresh, detection *dets) +void get_detection_detections(dn_layer l, int w, int h, float thresh, detection *dets) { int i,j,n; float *predictions = l.output; diff --git a/src/detection_layer.h b/src/detection_layer.h index 1c818535700..356b36a3b85 100644 --- a/src/detection_layer.h +++ b/src/detection_layer.h @@ -4,11 +4,11 @@ #include "layer.h" #include "network.h" -typedef layer detection_layer; +typedef dn_layer detection_layer; detection_layer make_detection_layer(int batch, int inputs, int n, int size, int classes, int coords, int rescore); -void forward_detection_layer(const detection_layer l, network net); -void backward_detection_layer(const detection_layer l, network net); +void forward_detection_layer(const detection_layer l, dn_network net); +void backward_detection_layer(const detection_layer l, dn_network net); #ifdef GPU void forward_detection_layer_gpu(const detection_layer l, network net); diff --git a/src/dropout_layer.c b/src/dropout_layer.c index 780554fb371..12cc8df7c69 100644 --- a/src/dropout_layer.c +++ b/src/dropout_layer.c @@ -35,7 +35,7 @@ void resize_dropout_layer(dropout_layer *l, int inputs) #endif } -void forward_dropout_layer(dropout_layer l, network net) +void forward_dropout_layer(dropout_layer l, dn_network net) { int i; if (!net.train) return; @@ -47,7 +47,7 @@ void forward_dropout_layer(dropout_layer l, network net) } } -void backward_dropout_layer(dropout_layer l, network net) +void backward_dropout_layer(dropout_layer l, dn_network net) { int i; if(!net.delta) return; diff --git a/src/dropout_layer.h b/src/dropout_layer.h index 01f94d4d7d1..fff3ca01a4a 100644 --- a/src/dropout_layer.h +++ b/src/dropout_layer.h @@ -4,12 +4,12 @@ #include "layer.h" #include "network.h" -typedef layer dropout_layer; +typedef dn_layer dropout_layer; dropout_layer make_dropout_layer(int batch, int inputs, float probability); -void forward_dropout_layer(dropout_layer l, network net); -void backward_dropout_layer(dropout_layer l, network net); +void forward_dropout_layer(dropout_layer l, dn_network net); +void backward_dropout_layer(dropout_layer l, dn_network net); void resize_dropout_layer(dropout_layer *l, int inputs); #ifdef GPU diff --git a/src/gru_layer.c b/src/gru_layer.c index b6601d80e0b..dcd97caf888 100644 --- a/src/gru_layer.c +++ b/src/gru_layer.c @@ -10,7 +10,7 @@ #include #include -static void increment_layer(layer *l, int steps) +static void increment_layer(dn_layer *l, int steps) { int num = l->outputs*l->batch*steps; l->output += num; @@ -26,44 +26,44 @@ static void increment_layer(layer *l, int steps) #endif } -layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) +dn_layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) { fprintf(stderr, "GRU Layer: %d inputs, %d outputs\n", inputs, outputs); batch = batch / steps; - layer l = {0}; + dn_layer l = {0}; l.batch = batch; l.type = GRU; l.steps = steps; l.inputs = inputs; - l.uz = malloc(sizeof(layer)); + l.uz = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.uz) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.uz->batch = batch; - l.wz = malloc(sizeof(layer)); + l.wz = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wz) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wz->batch = batch; - l.ur = malloc(sizeof(layer)); + l.ur = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.ur) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.ur->batch = batch; - l.wr = malloc(sizeof(layer)); + l.wr = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wr) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wr->batch = batch; - l.uh = malloc(sizeof(layer)); + l.uh = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.uh) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.uh->batch = batch; - l.wh = malloc(sizeof(layer)); + l.wh = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wh) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wh->batch = batch; @@ -115,7 +115,7 @@ layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_no return l; } -void update_gru_layer(layer l, update_args a) +void update_gru_layer(dn_layer l, update_args a) { update_connected_layer(*(l.ur), a); update_connected_layer(*(l.uz), a); @@ -125,18 +125,18 @@ void update_gru_layer(layer l, update_args a) update_connected_layer(*(l.wh), a); } -void forward_gru_layer(layer l, network net) +void forward_gru_layer(dn_layer l, dn_network net) { - network s = net; + dn_network s = net; s.train = net.train; int i; - layer uz = *(l.uz); - layer ur = *(l.ur); - layer uh = *(l.uh); + dn_layer uz = *(l.uz); + dn_layer ur = *(l.ur); + dn_layer uh = *(l.uh); - layer wz = *(l.wz); - layer wr = *(l.wr); - layer wh = *(l.wh); + dn_layer wz = *(l.wz); + dn_layer wr = *(l.wr); + dn_layer wh = *(l.wh); fill_cpu(l.outputs * l.batch * l.steps, 0, uz.delta, 1); fill_cpu(l.outputs * l.batch * l.steps, 0, ur.delta, 1); @@ -201,7 +201,7 @@ void forward_gru_layer(layer l, network net) } } -void backward_gru_layer(layer l, network net) +void backward_gru_layer(dn_layer l, dn_network net) { } diff --git a/src/gru_layer.h b/src/gru_layer.h index 9067942e949..55bf25069f7 100644 --- a/src/gru_layer.h +++ b/src/gru_layer.h @@ -6,11 +6,11 @@ #include "layer.h" #include "network.h" -layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); +dn_layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); -void forward_gru_layer(layer l, network state); -void backward_gru_layer(layer l, network state); -void update_gru_layer(layer l, update_args a); +void forward_gru_layer(dn_layer l, dn_network state); +void backward_gru_layer(dn_layer l, dn_network state); +void update_gru_layer(dn_layer l, update_args a); #ifdef GPU void forward_gru_layer_gpu(layer l, network state); diff --git a/src/iseg_layer.c b/src/iseg_layer.c index 2bf03a8ac2f..0a49cb74646 100644 --- a/src/iseg_layer.c +++ b/src/iseg_layer.c @@ -10,9 +10,9 @@ #include #include -layer make_iseg_layer(int batch, int w, int h, int classes, int ids) +dn_layer make_iseg_layer(int batch, int w, int h, int classes, int ids) { - layer l = {0}; + dn_layer l = {0}; l.type = ISEG; l.h = h; @@ -55,7 +55,7 @@ layer make_iseg_layer(int batch, int w, int h, int classes, int ids) return l; } -void resize_iseg_layer(layer *l, int w, int h) +void resize_iseg_layer(dn_layer *l, int w, int h) { l->w = w; l->h = h; @@ -75,7 +75,7 @@ void resize_iseg_layer(layer *l, int w, int h) #endif } -void forward_iseg_layer(const layer l, network net) +void forward_iseg_layer(const dn_layer l, dn_network net) { double time = what_time_is_it_now(); @@ -192,7 +192,7 @@ void forward_iseg_layer(const layer l, network net) printf("took %lf sec\n", what_time_is_it_now() - time); } -void backward_iseg_layer(const layer l, network net) +void backward_iseg_layer(const dn_layer l, dn_network net) { axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); } diff --git a/src/iseg_layer.h b/src/iseg_layer.h index dd8e64e023c..b43bef4cf95 100644 --- a/src/iseg_layer.h +++ b/src/iseg_layer.h @@ -5,11 +5,11 @@ #include "layer.h" #include "network.h" -layer make_iseg_layer(int batch, int w, int h, int classes, int ids); -void forward_iseg_layer(const layer l, network net); -void backward_iseg_layer(const layer l, network net); -void resize_iseg_layer(layer *l, int w, int h); -int iseg_num_detections(layer l, float thresh); +dn_layer make_iseg_layer(int batch, int w, int h, int classes, int ids); +void forward_iseg_layer(const dn_layer l, dn_network net); +void backward_iseg_layer(const dn_layer l, dn_network net); +void resize_iseg_layer(dn_layer *l, int w, int h); +int iseg_num_detections(dn_layer l, float thresh); #ifdef GPU void forward_iseg_layer_gpu(const layer l, network net); diff --git a/src/l2norm_layer.c b/src/l2norm_layer.c index d099479b4c0..cdb13485a97 100644 --- a/src/l2norm_layer.c +++ b/src/l2norm_layer.c @@ -9,10 +9,10 @@ #include #include -layer make_l2norm_layer(int batch, int inputs) +dn_layer make_l2norm_layer(int batch, int inputs) { fprintf(stderr, "l2norm %4d\n", inputs); - layer l = {0}; + dn_layer l = {0}; l.type = L2NORM; l.batch = batch; l.inputs = inputs; @@ -34,13 +34,13 @@ layer make_l2norm_layer(int batch, int inputs) return l; } -void forward_l2norm_layer(const layer l, network net) +void forward_l2norm_layer(const dn_layer l, dn_network net) { copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); l2normalize_cpu(l.output, l.scales, l.batch, l.out_c, l.out_w*l.out_h); } -void backward_l2norm_layer(const layer l, network net) +void backward_l2norm_layer(const dn_layer l, dn_network net) { //axpy_cpu(l.inputs*l.batch, 1, l.scales, 1, l.delta, 1); axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); diff --git a/src/l2norm_layer.h b/src/l2norm_layer.h index 1ca6f710f01..02a9b768cfc 100644 --- a/src/l2norm_layer.h +++ b/src/l2norm_layer.h @@ -3,9 +3,9 @@ #include "layer.h" #include "network.h" -layer make_l2norm_layer(int batch, int inputs); -void forward_l2norm_layer(const layer l, network net); -void backward_l2norm_layer(const layer l, network net); +dn_layer make_l2norm_layer(int batch, int inputs); +void forward_l2norm_layer(const dn_layer l, dn_network net); +void backward_l2norm_layer(const dn_layer l, dn_network net); #ifdef GPU void forward_l2norm_layer_gpu(const layer l, network net); diff --git a/src/layer.c b/src/layer.c index c27b4776421..98bd2d8d9cc 100644 --- a/src/layer.c +++ b/src/layer.c @@ -3,7 +3,7 @@ #include -void free_layer(layer l) +void free_layer(dn_layer l) { if(l.type == DROPOUT){ if(l.rand) free(l.rand); diff --git a/src/local_layer.c b/src/local_layer.c index 74f6910a8fd..6b51047b606 100644 --- a/src/local_layer.c +++ b/src/local_layer.c @@ -88,7 +88,7 @@ local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, in return l; } -void forward_local_layer(const local_layer l, network net) +void forward_local_layer(const local_layer l, dn_network net) { int out_h = local_out_height(l); int out_w = local_out_width(l); @@ -119,7 +119,7 @@ void forward_local_layer(const local_layer l, network net) activate_array(l.output, l.outputs*l.batch, l.activation); } -void backward_local_layer(local_layer l, network net) +void backward_local_layer(local_layer l, dn_network net) { int i, j; int locations = l.out_w*l.out_h; diff --git a/src/local_layer.h b/src/local_layer.h index 776e572f420..88d17c24bd9 100644 --- a/src/local_layer.h +++ b/src/local_layer.h @@ -7,7 +7,7 @@ #include "layer.h" #include "network.h" -typedef layer local_layer; +typedef dn_layer local_layer; #ifdef GPU void forward_local_layer_gpu(local_layer layer, network net); @@ -20,8 +20,8 @@ void pull_local_layer(local_layer layer); local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation); -void forward_local_layer(const local_layer layer, network net); -void backward_local_layer(local_layer layer, network net); +void forward_local_layer(const local_layer layer, dn_network net); +void backward_local_layer(local_layer layer, dn_network net); void update_local_layer(local_layer layer, update_args a); void bias_output(float *output, float *biases, int batch, int n, int size); diff --git a/src/logistic_layer.c b/src/logistic_layer.c index b2b3d6b1ccf..b56a6d9c77b 100644 --- a/src/logistic_layer.c +++ b/src/logistic_layer.c @@ -9,10 +9,10 @@ #include #include -layer make_logistic_layer(int batch, int inputs) +dn_layer make_logistic_layer(int batch, int inputs) { fprintf(stderr, "logistic x entropy %4d\n", inputs); - layer l = {0}; + dn_layer l = {0}; l.type = LOGXENT; l.batch = batch; l.inputs = inputs; @@ -35,7 +35,7 @@ layer make_logistic_layer(int batch, int inputs) return l; } -void forward_logistic_layer(const layer l, network net) +void forward_logistic_layer(const dn_layer l, dn_network net) { copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); activate_array(l.output, l.outputs*l.batch, LOGISTIC); @@ -45,7 +45,7 @@ void forward_logistic_layer(const layer l, network net) } } -void backward_logistic_layer(const layer l, network net) +void backward_logistic_layer(const dn_layer l, dn_network net) { axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); } diff --git a/src/logistic_layer.h b/src/logistic_layer.h index 9c25bee3c2a..1d766886220 100644 --- a/src/logistic_layer.h +++ b/src/logistic_layer.h @@ -3,9 +3,9 @@ #include "layer.h" #include "network.h" -layer make_logistic_layer(int batch, int inputs); -void forward_logistic_layer(const layer l, network net); -void backward_logistic_layer(const layer l, network net); +dn_layer make_logistic_layer(int batch, int inputs); +void forward_logistic_layer(const dn_layer l, dn_network net); +void backward_logistic_layer(const dn_layer l, dn_network net); #ifdef GPU void forward_logistic_layer_gpu(const layer l, network net); diff --git a/src/lstm_layer.c b/src/lstm_layer.c index fb07de20228..76587e8b8af 100644 --- a/src/lstm_layer.c +++ b/src/lstm_layer.c @@ -10,7 +10,7 @@ #include #include -static void increment_layer(layer *l, int steps) +static void increment_layer(dn_layer *l, int steps) { int num = l->outputs*l->batch*steps; l->output += num; @@ -26,52 +26,52 @@ static void increment_layer(layer *l, int steps) #endif } -layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) +dn_layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) { fprintf(stderr, "LSTM Layer: %d inputs, %d outputs\n", inputs, outputs); batch = batch / steps; - layer l = { 0 }; + dn_layer l = { 0 }; l.batch = batch; l.type = LSTM; l.steps = steps; l.inputs = inputs; - l.uf = malloc(sizeof(layer)); + l.uf = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.uf) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.uf->batch = batch; - l.ui = malloc(sizeof(layer)); + l.ui = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.ui) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.ui->batch = batch; - l.ug = malloc(sizeof(layer)); + l.ug = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.ug) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.ug->batch = batch; - l.uo = malloc(sizeof(layer)); + l.uo = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.uo) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); l.uo->batch = batch; - l.wf = malloc(sizeof(layer)); + l.wf = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wf) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wf->batch = batch; - l.wi = malloc(sizeof(layer)); + l.wi = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wi) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wi->batch = batch; - l.wg = malloc(sizeof(layer)); + l.wg = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wg) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wg->batch = batch; - l.wo = malloc(sizeof(layer)); + l.wo = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.wo) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); l.wo->batch = batch; @@ -141,7 +141,7 @@ layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_n return l; } -void update_lstm_layer(layer l, update_args a) +void update_lstm_layer(dn_layer l, update_args a) { update_connected_layer(*(l.wf), a); update_connected_layer(*(l.wi), a); @@ -153,20 +153,20 @@ void update_lstm_layer(layer l, update_args a) update_connected_layer(*(l.uo), a); } -void forward_lstm_layer(layer l, network state) +void forward_lstm_layer(dn_layer l, dn_network state) { - network s = { 0 }; + dn_network s = { 0 }; s.train = state.train; int i; - layer wf = *(l.wf); - layer wi = *(l.wi); - layer wg = *(l.wg); - layer wo = *(l.wo); + dn_layer wf = *(l.wf); + dn_layer wi = *(l.wi); + dn_layer wg = *(l.wg); + dn_layer wo = *(l.wo); - layer uf = *(l.uf); - layer ui = *(l.ui); - layer ug = *(l.ug); - layer uo = *(l.uo); + dn_layer uf = *(l.uf); + dn_layer ui = *(l.ui); + dn_layer ug = *(l.ug); + dn_layer uo = *(l.uo); fill_cpu(l.outputs * l.batch * l.steps, 0, wf.delta, 1); fill_cpu(l.outputs * l.batch * l.steps, 0, wi.delta, 1); @@ -239,20 +239,20 @@ void forward_lstm_layer(layer l, network state) } } -void backward_lstm_layer(layer l, network state) +void backward_lstm_layer(dn_layer l, dn_network state) { - network s = { 0 }; + dn_network s = { 0 }; s.train = state.train; int i; - layer wf = *(l.wf); - layer wi = *(l.wi); - layer wg = *(l.wg); - layer wo = *(l.wo); - - layer uf = *(l.uf); - layer ui = *(l.ui); - layer ug = *(l.ug); - layer uo = *(l.uo); + dn_layer wf = *(l.wf); + dn_layer wi = *(l.wi); + dn_layer wg = *(l.wg); + dn_layer wo = *(l.wo); + + dn_layer uf = *(l.uf); + dn_layer ui = *(l.ui); + dn_layer ug = *(l.ug); + dn_layer uo = *(l.uo); increment_layer(&wf, l.steps - 1); increment_layer(&wi, l.steps - 1); diff --git a/src/lstm_layer.h b/src/lstm_layer.h index b9f07e6424b..b6372d2cb64 100644 --- a/src/lstm_layer.h +++ b/src/lstm_layer.h @@ -6,10 +6,10 @@ #include "network.h" #define USET -layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); +dn_layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); -void forward_lstm_layer(layer l, network net); -void update_lstm_layer(layer l, update_args a); +void forward_lstm_layer(dn_layer l, dn_network net); +void update_lstm_layer(dn_layer l, update_args a); #ifdef GPU void forward_lstm_layer_gpu(layer l, network net); diff --git a/src/maxpool_layer.c b/src/maxpool_layer.c index 18dd01f7b64..76cf5e7531b 100644 --- a/src/maxpool_layer.c +++ b/src/maxpool_layer.c @@ -76,7 +76,7 @@ void resize_maxpool_layer(maxpool_layer *l, int w, int h) #endif } -void forward_maxpool_layer(const maxpool_layer l, network net) +void forward_maxpool_layer(const maxpool_layer l, dn_network net) { int b,i,j,k,m,n; int w_offset = -l.pad/2; @@ -113,7 +113,7 @@ void forward_maxpool_layer(const maxpool_layer l, network net) } } -void backward_maxpool_layer(const maxpool_layer l, network net) +void backward_maxpool_layer(const maxpool_layer l, dn_network net) { int i; int h = l.out_h; diff --git a/src/maxpool_layer.h b/src/maxpool_layer.h index e6594afbb6c..7a7f5587738 100644 --- a/src/maxpool_layer.h +++ b/src/maxpool_layer.h @@ -6,13 +6,13 @@ #include "layer.h" #include "network.h" -typedef layer maxpool_layer; +typedef dn_layer maxpool_layer; dn_image get_maxpool_image(maxpool_layer l); maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding); void resize_maxpool_layer(maxpool_layer *l, int w, int h); -void forward_maxpool_layer(const maxpool_layer l, network net); -void backward_maxpool_layer(const maxpool_layer l, network net); +void forward_maxpool_layer(const maxpool_layer l, dn_network net); +void backward_maxpool_layer(const maxpool_layer l, dn_network net); #ifdef GPU void forward_maxpool_layer_gpu(maxpool_layer l, network net); diff --git a/src/network.c b/src/network.c index 37e21cd1684..e12b82a87fd 100644 --- a/src/network.c +++ b/src/network.c @@ -32,7 +32,7 @@ #include "parser.h" #include "data.h" -load_args get_base_args(network *net) +load_args get_base_args(dn_network *net) { load_args args = {0}; args.w = net->w; @@ -50,9 +50,9 @@ load_args get_base_args(network *net) return args; } -network *load_network(const char *cfg, const char *weights, int clear) +dn_network *load_network(const char *cfg, const char *weights, int clear) { - network *net = parse_network_cfg(cfg); + dn_network *net = parse_network_cfg(cfg); if(weights && weights[0] != 0){ load_weights(net, weights); } @@ -60,13 +60,13 @@ network *load_network(const char *cfg, const char *weights, int clear) return net; } -size_t get_current_batch(network *net) +size_t get_current_batch(dn_network *net) { size_t batch_num = (*net->seen)/(net->batch*net->subdivisions); return batch_num; } -void reset_network_state(network *net, int b) +void reset_network_state(dn_network *net, int b) { int i; for (i = 0; i < net->n; ++i) { @@ -82,12 +82,12 @@ void reset_network_state(network *net, int b) } } -void reset_rnn(network *net) +void reset_rnn(dn_network *net) { reset_network_state(net, 0); } -float get_current_rate(network *net) +float get_current_rate(dn_network *net) { size_t batch_num = get_current_batch(net); int i; @@ -174,18 +174,18 @@ char *get_layer_string(LAYER_TYPE a) return "none"; } -network *make_network(int n) +dn_network *make_network(int n) { - network *net = calloc(1, sizeof(network)); + dn_network *net = calloc(1, sizeof(dn_network)); net->n = n; - net->layers = calloc(net->n, sizeof(layer)); + net->layers = calloc(net->n, sizeof(dn_layer)); net->seen = calloc(1, sizeof(size_t)); net->t = calloc(1, sizeof(int)); net->cost = calloc(1, sizeof(float)); return net; } -void forward_network(network *netp) +void forward_network(dn_network *netp) { #ifdef GPU if(netp->gpu_index >= 0){ @@ -193,11 +193,11 @@ void forward_network(network *netp) return; } #endif - network net = *netp; + dn_network net = *netp; int i; for(i = 0; i < net.n; ++i){ net.index = i; - layer l = net.layers[i]; + dn_layer l = net.layers[i]; if(l.delta){ fill_cpu(l.outputs * l.batch, 0, l.delta, 1); } @@ -210,7 +210,7 @@ void forward_network(network *netp) calc_network_cost(netp); } -void update_network(network *netp) +void update_network(dn_network *netp) { #ifdef GPU if(netp->gpu_index >= 0){ @@ -218,7 +218,7 @@ void update_network(network *netp) return; } #endif - network net = *netp; + dn_network net = *netp; int i; update_args a = {0}; a.batch = net.batch*net.subdivisions; @@ -233,16 +233,16 @@ void update_network(network *netp) a.t = *net.t; for(i = 0; i < net.n; ++i){ - layer l = net.layers[i]; + dn_layer l = net.layers[i]; if(l.update){ l.update(l, a); } } } -void calc_network_cost(network *netp) +void calc_network_cost(dn_network *netp) { - network net = *netp; + dn_network net = *netp; int i; float sum = 0; int count = 0; @@ -255,12 +255,12 @@ void calc_network_cost(network *netp) *net.cost = sum/count; } -int get_predicted_class_network(network *net) +int get_predicted_class_network(dn_network *net) { return max_index(net->output, net->outputs); } -void backward_network(network *netp) +void backward_network(dn_network *netp) { #ifdef GPU if(netp->gpu_index >= 0){ @@ -268,16 +268,16 @@ void backward_network(network *netp) return; } #endif - network net = *netp; + dn_network net = *netp; int i; - network orig = net; + dn_network orig = net; for(i = net.n-1; i >= 0; --i){ - layer l = net.layers[i]; + dn_layer l = net.layers[i]; if(l.stopbackward) break; if(i == 0){ net = orig; }else{ - layer prev = net.layers[i-1]; + dn_layer prev = net.layers[i-1]; net.input = prev.output; net.delta = prev.delta; } @@ -286,7 +286,7 @@ void backward_network(network *netp) } } -float train_network_datum(network *net) +float train_network_datum(dn_network *net) { *net->seen += net->batch; net->train = 1; @@ -297,7 +297,7 @@ float train_network_datum(network *net) return error; } -float train_network_sgd(network *net, dn_data d, int n) +float train_network_sgd(dn_network *net, dn_data d, int n) { int batch = net->batch; @@ -311,7 +311,7 @@ float train_network_sgd(network *net, dn_data d, int n) return (float)sum/(n*batch); } -float train_network(network *net, dn_data d) +float train_network(dn_network *net, dn_data d) { assert(d.X.rows % net->batch == 0); int batch = net->batch; @@ -327,7 +327,7 @@ float train_network(network *net, dn_data d) return (float)sum/(n*batch); } -void set_temp_network(network *net, float t) +void set_temp_network(dn_network *net, float t) { int i; for(i = 0; i < net->n; ++i){ @@ -336,7 +336,7 @@ void set_temp_network(network *net, float t) } -void set_batch_network(network *net, int b) +void set_batch_network(dn_network *net, int b) { net->batch = b; int i; @@ -355,7 +355,7 @@ void set_batch_network(network *net, int b) } } -int resize_network(network *net, int w, int h) +int resize_network(dn_network *net, int w, int h) { #ifdef GPU cuda_set_device(net->gpu_index); @@ -370,7 +370,7 @@ int resize_network(network *net, int w, int h) //fprintf(stderr, "Resizing to %d x %d...\n", w, h); //fflush(stderr); for (i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL){ resize_convolutional_layer(&l, w, h); }else if(l.type == CROP){ @@ -406,7 +406,7 @@ int resize_network(network *net, int w, int h) h = l.out_h; if(l.type == AVGPOOL) break; } - layer out = get_network_output_layer(net); + dn_layer out = get_network_output_layer(net); net->inputs = net->layers[0].inputs; net->outputs = out.outputs; net->truths = out.outputs; @@ -437,7 +437,7 @@ int resize_network(network *net, int w, int h) return 0; } -layer get_network_detection_layer(network *net) +dn_layer get_network_detection_layer(dn_network *net) { int i; for(i = 0; i < net->n; ++i){ @@ -446,13 +446,13 @@ layer get_network_detection_layer(network *net) } } fprintf(stderr, "Detection layer not found!!\n"); - layer l = {0}; + dn_layer l = {0}; return l; } -dn_image get_network_image_layer(network *net, int i) +dn_image get_network_image_layer(dn_network *net, int i) { - layer l = net->layers[i]; + dn_layer l = net->layers[i]; #ifdef GPU //cuda_pull_array(l.output_gpu, l.output, l.outputs); #endif @@ -463,7 +463,7 @@ dn_image get_network_image_layer(network *net, int i) return def; } -dn_image get_network_image(network *net) +dn_image get_network_image(dn_network *net) { int i; for(i = net->n-1; i >= 0; --i){ @@ -474,29 +474,29 @@ dn_image get_network_image(network *net) return def; } -void visualize_network(network *net) +void visualize_network(dn_network *net) { dn_image *prev = 0; int i; char buff[256]; for(i = 0; i < net->n; ++i){ sprintf(buff, "Layer %d", i); - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == CONVOLUTIONAL){ prev = visualize_convolutional_layer(l, buff, prev); } } } -void top_predictions(network *net, int k, int *index) +void top_predictions(dn_network *net, int k, int *index) { top_k(net->output, net->outputs, k, index); } -float *network_predict(network *net, float *input) +float *network_predict(dn_network *net, float *input) { - network orig = *net; + dn_network orig = *net; net->input = input; net->truth = 0; net->train = 0; @@ -507,12 +507,12 @@ float *network_predict(network *net, float *input) return out; } -int num_detections(network *net, float thresh) +int num_detections(dn_network *net, float thresh) { int i; int s = 0; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if(l.type == YOLO){ s += yolo_num_detections(l, thresh); } @@ -523,9 +523,9 @@ int num_detections(network *net, float thresh) return s; } -detection *make_network_boxes(network *net, float thresh, int *num) +detection *make_network_boxes(dn_network *net, float thresh, int *num) { - layer l = net->layers[net->n - 1]; + dn_layer l = net->layers[net->n - 1]; int i; int nboxes = num_detections(net, thresh); if(num) *num = nboxes; @@ -539,11 +539,11 @@ detection *make_network_boxes(network *net, float thresh, int *num) return dets; } -void fill_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, detection *dets) +void fill_network_boxes(dn_network *net, int w, int h, float thresh, float hier, int *map, int relative, detection *dets) { int j; for(j = 0; j < net->n; ++j){ - layer l = net->layers[j]; + dn_layer l = net->layers[j]; if(l.type == YOLO){ int count = get_yolo_detections(l, w, h, net->w, net->h, thresh, map, relative, dets); dets += count; @@ -559,7 +559,7 @@ void fill_network_boxes(network *net, int w, int h, float thresh, float hier, in } } -detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num) +detection *get_network_boxes(dn_network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num) { detection *dets = make_network_boxes(net, thresh, num); fill_network_boxes(net, w, h, thresh, hier, map, relative, dets); @@ -576,7 +576,7 @@ void free_detections(detection *dets, int n) free(dets); } -float *network_predict_image(network *net, dn_image im) +float *network_predict_image(dn_network *net, dn_image im) { dn_image imr = letterbox_image(im, net->w, net->h); set_batch_network(net, 1); @@ -585,10 +585,10 @@ float *network_predict_image(network *net, dn_image im) return p; } -int network_width(network *net){return net->w;} -int network_height(network *net){return net->h;} +int network_width(dn_network *net){return net->w;} +int network_height(dn_network *net){return net->h;} -dn_matrix network_predict_data_multi(network *net, dn_data test, int n) +dn_matrix network_predict_data_multi(dn_network *net, dn_data test, int n) { int i,j,b,m; int k = net->outputs; @@ -613,7 +613,7 @@ dn_matrix network_predict_data_multi(network *net, dn_data test, int n) return pred; } -dn_matrix network_predict_data(network *net, dn_data test) +dn_matrix network_predict_data(dn_network *net, dn_data test) { int i,j,b; int k = net->outputs; @@ -636,11 +636,11 @@ dn_matrix network_predict_data(network *net, dn_data test) return pred; } -void print_network(network *net) +void print_network(dn_network *net) { int i,j; for(i = 0; i < net->n; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; float *output = l.output; int n = l.outputs; float mean = mean_array(output, n); @@ -653,7 +653,7 @@ void print_network(network *net) } } -void compare_networks(network *n1, network *n2, dn_data test) +void compare_networks(dn_network *n1, dn_network *n2, dn_data test) { dn_matrix g1 = network_predict_data(n1, test); dn_matrix g2 = network_predict_data(n2, test); @@ -678,7 +678,7 @@ void compare_networks(network *n1, network *n2, dn_data test) printf("%f\n", num/den); } -float network_accuracy(network *net, dn_data d) +float network_accuracy(dn_network *net, dn_data d) { dn_matrix guess = network_predict_data(net, d); float acc = matrix_topk_accuracy(d.y, guess,1); @@ -686,7 +686,7 @@ float network_accuracy(network *net, dn_data d) return acc; } -float *network_accuracies(network *net, dn_data d, int n) +float *network_accuracies(dn_network *net, dn_data d, int n) { static float acc[2]; dn_matrix guess = network_predict_data(net, d); @@ -696,7 +696,7 @@ float *network_accuracies(network *net, dn_data d, int n) return acc; } -layer get_network_output_layer(network *net) +dn_layer get_network_output_layer(dn_network *net) { int i; for(i = net->n - 1; i >= 0; --i){ @@ -705,7 +705,7 @@ layer get_network_output_layer(network *net) return net->layers[i]; } -float network_accuracy_multi(network *net, dn_data d, int n) +float network_accuracy_multi(dn_network *net, dn_data d, int n) { dn_matrix guess = network_predict_data_multi(net, d, n); float acc = matrix_topk_accuracy(d.y, guess,1); @@ -713,7 +713,7 @@ float network_accuracy_multi(network *net, dn_data d, int n) return acc; } -void free_network(network *net) +void free_network(dn_network *net) { int i; for(i = 0; i < net->n; ++i){ @@ -733,7 +733,7 @@ void free_network(network *net) // ^ What the hell is this comment for? -layer network_output_layer(network *net) +dn_layer network_output_layer(dn_network *net) { int i; for(i = net->n - 1; i >= 0; --i){ @@ -742,17 +742,17 @@ layer network_output_layer(network *net) return net->layers[i]; } -int network_inputs(network *net) +int network_inputs(dn_network *net) { return net->layers[0].inputs; } -int network_outputs(network *net) +int network_outputs(dn_network *net) { return network_output_layer(net).outputs; } -float *network_output(network *net) +float *network_output(dn_network *net) { return network_output_layer(net).output; } diff --git a/src/network.h b/src/network.h index aac639beac1..17fd1c4cb7f 100644 --- a/src/network.h +++ b/src/network.h @@ -13,17 +13,17 @@ void pull_network_output(network *net); #endif -void compare_networks(network *n1, network *n2, dn_data d); +void compare_networks(dn_network *n1, dn_network *n2, dn_data d); char *get_layer_string(LAYER_TYPE a); -network *make_network(int n); +dn_network *make_network(int n); -float network_accuracy_multi(network *net, dn_data d, int n); -int get_predicted_class_network(network *net); -void print_network(network *net); -int resize_network(network *net, int w, int h); -void calc_network_cost(network *net); +float network_accuracy_multi(dn_network *net, dn_data d, int n); +int get_predicted_class_network(dn_network *net); +void print_network(dn_network *net); +int resize_network(dn_network *net, int w, int h); +void calc_network_cost(dn_network *net); #endif diff --git a/src/normalization_layer.c b/src/normalization_layer.c index 424714fe865..492c866572b 100644 --- a/src/normalization_layer.c +++ b/src/normalization_layer.c @@ -3,10 +3,10 @@ #include -layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa) +dn_layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa) { fprintf(stderr, "Local Response Normalization Layer: %d x %d x %d image, %d size\n", w,h,c,size); - layer layer = {0}; + dn_layer layer = {0}; layer.type = NORMALIZATION; layer.batch = batch; layer.h = layer.out_h = h; @@ -37,7 +37,7 @@ layer make_normalization_layer(int batch, int w, int h, int c, int size, float a return layer; } -void resize_normalization_layer(layer *layer, int w, int h) +void resize_normalization_layer(dn_layer *layer, int w, int h) { int c = layer->c; int batch = layer->batch; @@ -63,7 +63,7 @@ void resize_normalization_layer(layer *layer, int w, int h) #endif } -void forward_normalization_layer(const layer layer, network net) +void forward_normalization_layer(const dn_layer layer, dn_network net) { int k,b; int w = layer.w; @@ -94,7 +94,7 @@ void forward_normalization_layer(const layer layer, network net) mul_cpu(w*h*c*layer.batch, net.input, 1, layer.output, 1); } -void backward_normalization_layer(const layer layer, network net) +void backward_normalization_layer(const dn_layer layer, dn_network net) { // TODO This is approximate ;-) // Also this should add in to delta instead of overwritting. diff --git a/src/normalization_layer.h b/src/normalization_layer.h index 665baa50662..87cc1e6bb90 100644 --- a/src/normalization_layer.h +++ b/src/normalization_layer.h @@ -5,11 +5,11 @@ #include "layer.h" #include "network.h" -layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa); -void resize_normalization_layer(layer *layer, int h, int w); -void forward_normalization_layer(const layer layer, network net); -void backward_normalization_layer(const layer layer, network net); -void visualize_normalization_layer(layer layer, char *window); +dn_layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa); +void resize_normalization_layer(dn_layer *layer, int h, int w); +void forward_normalization_layer(const dn_layer layer, dn_network net); +void backward_normalization_layer(const dn_layer layer, dn_network net); +void visualize_normalization_layer(dn_layer layer, char *window); #ifdef GPU void forward_normalization_layer_gpu(const layer layer, network net); diff --git a/src/parser.c b/src/parser.c index a26d60158d7..7228828a075 100644 --- a/src/parser.c +++ b/src/parser.c @@ -126,7 +126,7 @@ typedef struct size_params{ int c; int index; int time_steps; - network *net; + dn_network *net; } size_params; local_layer parse_local(dn_list *options, size_params params) @@ -150,7 +150,7 @@ local_layer parse_local(dn_list *options, size_params params) return layer; } -layer parse_deconvolutional(dn_list *options, size_params params) +dn_layer parse_deconvolutional(dn_list *options, size_params params) { int n = option_find_int(options, "filters",1); int size = option_find_int(options, "size",1); @@ -170,7 +170,7 @@ layer parse_deconvolutional(dn_list *options, size_params params) int padding = option_find_int_quiet(options, "padding",0); if(pad) padding = size/2; - layer l = make_deconvolutional_layer(batch,h,w,c,n,size,stride,padding, activation, batch_normalize, params.net->adam); + dn_layer l = make_deconvolutional_layer(batch,h,w,c,n,size,stride,padding, activation, batch_normalize, params.net->adam); return l; } @@ -206,7 +206,7 @@ convolutional_layer parse_convolutional(dn_list *options, size_params params) return layer; } -layer parse_crnn(dn_list *options, size_params params) +dn_layer parse_crnn(dn_list *options, size_params params) { int output_filters = option_find_int(options, "output_filters",1); int hidden_filters = option_find_int(options, "hidden_filters",1); @@ -214,63 +214,63 @@ layer parse_crnn(dn_list *options, size_params params) ACTIVATION activation = get_activation(activation_s); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); - layer l = make_crnn_layer(params.batch, params.w, params.h, params.c, hidden_filters, output_filters, params.time_steps, activation, batch_normalize); + dn_layer l = make_crnn_layer(params.batch, params.w, params.h, params.c, hidden_filters, output_filters, params.time_steps, activation, batch_normalize); l.shortcut = option_find_int_quiet(options, "shortcut", 0); return l; } -layer parse_rnn(dn_list *options, size_params params) +dn_layer parse_rnn(dn_list *options, size_params params) { int output = option_find_int(options, "output",1); char *activation_s = option_find_str(options, "activation", "logistic"); ACTIVATION activation = get_activation(activation_s); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); - layer l = make_rnn_layer(params.batch, params.inputs, output, params.time_steps, activation, batch_normalize, params.net->adam); + dn_layer l = make_rnn_layer(params.batch, params.inputs, output, params.time_steps, activation, batch_normalize, params.net->adam); l.shortcut = option_find_int_quiet(options, "shortcut", 0); return l; } -layer parse_gru(dn_list *options, size_params params) +dn_layer parse_gru(dn_list *options, size_params params) { int output = option_find_int(options, "output",1); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); - layer l = make_gru_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); + dn_layer l = make_gru_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); l.tanh = option_find_int_quiet(options, "tanh", 0); return l; } -layer parse_lstm(dn_list *options, size_params params) +dn_layer parse_lstm(dn_list *options, size_params params) { int output = option_find_int(options, "output", 1); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); - layer l = make_lstm_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); + dn_layer l = make_lstm_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); return l; } -layer parse_connected(dn_list *options, size_params params) +dn_layer parse_connected(dn_list *options, size_params params) { int output = option_find_int(options, "output",1); char *activation_s = option_find_str(options, "activation", "logistic"); ACTIVATION activation = get_activation(activation_s); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); - layer l = make_connected_layer(params.batch, params.inputs, output, activation, batch_normalize, params.net->adam); + dn_layer l = make_connected_layer(params.batch, params.inputs, output, activation, batch_normalize, params.net->adam); return l; } -layer parse_softmax(dn_list *options, size_params params) +dn_layer parse_softmax(dn_list *options, size_params params) { int groups = option_find_int_quiet(options, "groups",1); - layer l = make_softmax_layer(params.batch, params.inputs, groups); + dn_layer l = make_softmax_layer(params.batch, params.inputs, groups); l.temperature = option_find_float_quiet(options, "temperature", 1); char *tree_file = option_find_str(options, "tree", 0); if (tree_file) l.softmax_tree = read_tree(tree_file); @@ -303,7 +303,7 @@ int *parse_yolo_mask(char *a, int *num) return mask; } -layer parse_yolo(dn_list *options, size_params params) +dn_layer parse_yolo(dn_list *options, size_params params) { int classes = option_find_int(options, "classes", 20); int total = option_find_int(options, "num", 1); @@ -311,7 +311,7 @@ layer parse_yolo(dn_list *options, size_params params) char *a = option_find_str(options, "mask", 0); int *mask = parse_yolo_mask(a, &num); - layer l = make_yolo_layer(params.batch, params.w, params.h, num, total, mask, classes); + dn_layer l = make_yolo_layer(params.batch, params.w, params.h, num, total, mask, classes); assert(l.outputs == params.inputs); l.max_boxes = option_find_int_quiet(options, "max",90); @@ -341,22 +341,22 @@ layer parse_yolo(dn_list *options, size_params params) return l; } -layer parse_iseg(dn_list *options, size_params params) +dn_layer parse_iseg(dn_list *options, size_params params) { int classes = option_find_int(options, "classes", 20); int ids = option_find_int(options, "ids", 32); - layer l = make_iseg_layer(params.batch, params.w, params.h, classes, ids); + dn_layer l = make_iseg_layer(params.batch, params.w, params.h, classes, ids); assert(l.outputs == params.inputs); return l; } -layer parse_region(dn_list *options, size_params params) +dn_layer parse_region(dn_list *options, size_params params) { int coords = option_find_int(options, "coords", 4); int classes = option_find_int(options, "classes", 20); int num = option_find_int(options, "num", 1); - layer l = make_region_layer(params.batch, params.w, params.h, num, classes, coords); + dn_layer l = make_region_layer(params.batch, params.w, params.h, num, classes, coords); assert(l.outputs == params.inputs); l.log = option_find_int_quiet(options, "log", 0); @@ -462,7 +462,7 @@ crop_layer parse_crop(dn_list *options, size_params params) return l; } -layer parse_reorg(dn_list *options, size_params params) +dn_layer parse_reorg(dn_list *options, size_params params) { int stride = option_find_int(options, "stride",1); int reverse = option_find_int_quiet(options, "reverse",0); @@ -476,7 +476,7 @@ layer parse_reorg(dn_list *options, size_params params) batch=params.batch; if(!(h && w && c)) error("Layer before reorg layer must output image."); - layer layer = make_reorg_layer(batch,w,h,c,stride,reverse, flatten, extra); + dn_layer layer = make_reorg_layer(batch,w,h,c,stride,reverse, flatten, extra); return layer; } @@ -520,32 +520,32 @@ dropout_layer parse_dropout(dn_list *options, size_params params) return layer; } -layer parse_normalization(dn_list *options, size_params params) +dn_layer parse_normalization(dn_list *options, size_params params) { float alpha = option_find_float(options, "alpha", .0001); float beta = option_find_float(options, "beta" , .75); float kappa = option_find_float(options, "kappa", 1); int size = option_find_int(options, "size", 5); - layer l = make_normalization_layer(params.batch, params.w, params.h, params.c, size, alpha, beta, kappa); + dn_layer l = make_normalization_layer(params.batch, params.w, params.h, params.c, size, alpha, beta, kappa); return l; } -layer parse_batchnorm(dn_list *options, size_params params) +dn_layer parse_batchnorm(dn_list *options, size_params params) { - layer l = make_batchnorm_layer(params.batch, params.w, params.h, params.c); + dn_layer l = make_batchnorm_layer(params.batch, params.w, params.h, params.c); return l; } -layer parse_shortcut(dn_list *options, size_params params, network *net) +dn_layer parse_shortcut(dn_list *options, size_params params, dn_network *net) { char *l = option_find(options, "from"); int index = atoi(l); if(index < 0) index = params.index + index; int batch = params.batch; - layer from = net->layers[index]; + dn_layer from = net->layers[index]; - layer s = make_shortcut_layer(batch, index, params.w, params.h, params.c, from.out_w, from.out_h, from.out_c); + dn_layer s = make_shortcut_layer(batch, index, params.w, params.h, params.c, from.out_w, from.out_h, from.out_c); char *activation_s = option_find_str(options, "activation", "linear"); ACTIVATION activation = get_activation(activation_s); @@ -556,9 +556,9 @@ layer parse_shortcut(dn_list *options, size_params params, network *net) } -layer parse_l2norm(dn_list *options, size_params params) +dn_layer parse_l2norm(dn_list *options, size_params params) { - layer l = make_l2norm_layer(params.batch, params.inputs); + dn_layer l = make_l2norm_layer(params.batch, params.inputs); l.h = l.out_h = params.h; l.w = l.out_w = params.w; l.c = l.out_c = params.c; @@ -566,21 +566,21 @@ layer parse_l2norm(dn_list *options, size_params params) } -layer parse_logistic(dn_list *options, size_params params) +dn_layer parse_logistic(dn_list *options, size_params params) { - layer l = make_logistic_layer(params.batch, params.inputs); + dn_layer l = make_logistic_layer(params.batch, params.inputs); l.h = l.out_h = params.h; l.w = l.out_w = params.w; l.c = l.out_c = params.c; return l; } -layer parse_activation(dn_list *options, size_params params) +dn_layer parse_activation(dn_list *options, size_params params) { char *activation_s = option_find_str(options, "activation", "linear"); ACTIVATION activation = get_activation(activation_s); - layer l = make_activation_layer(params.batch, params.inputs, activation); + dn_layer l = make_activation_layer(params.batch, params.inputs, activation); l.h = l.out_h = params.h; l.w = l.out_w = params.w; @@ -589,16 +589,16 @@ layer parse_activation(dn_list *options, size_params params) return l; } -layer parse_upsample(dn_list *options, size_params params, network *net) +dn_layer parse_upsample(dn_list *options, size_params params, dn_network *net) { int stride = option_find_int(options, "stride",2); - layer l = make_upsample_layer(params.batch, params.w, params.h, params.c, stride); + dn_layer l = make_upsample_layer(params.batch, params.w, params.h, params.c, stride); l.scale = option_find_float_quiet(options, "scale", 1); return l; } -route_layer parse_route(dn_list *options, size_params params, network *net) +route_layer parse_route(dn_list *options, size_params params, dn_network *net) { char *l = option_find(options, "layers"); int len = strlen(l); @@ -652,7 +652,7 @@ learning_rate_policy get_policy(char *s) return CONSTANT; } -void parse_net_options(dn_list *options, network *net) +void parse_net_options(dn_list *options, dn_network *net) { net->batch = option_find_int(options, "batch",1); net->learning_rate = option_find_float(options, "learning_rate", .001); @@ -739,12 +739,12 @@ int is_network(section *s) || strcmp(s->type, "[network]")==0); } -network* parse_network_cfg(const char *filename) +dn_network* parse_network_cfg(const char *filename) { dn_list *sections = read_cfg(filename); dn_node *n = sections->front; if(!n) error("Config file has no sections"); - network *net = make_network(sections->size - 1); + dn_network *net = make_network(sections->size - 1); net->gpu_index = gpu_index; size_params params; @@ -771,7 +771,7 @@ network* parse_network_cfg(const char *filename) fprintf(stderr, "%5d ", count); s = (section *)n->val; options = s->options; - layer l = {0}; + dn_layer l = {0}; LAYER_TYPE lt = string_to_layer_type(s->type); if(lt == CONVOLUTIONAL){ l = parse_convolutional(options, params); @@ -861,7 +861,7 @@ network* parse_network_cfg(const char *filename) } } free_list(sections); - layer out = get_network_output_layer(net); + dn_layer out = get_network_output_layer(net); net->outputs = out.outputs; net->truths = out.outputs; if(net->layers[net->n-1].truths) net->truths = net->layers[net->n-1].truths; @@ -923,7 +923,7 @@ dn_list *read_cfg(const char *filename) return options; } -void save_convolutional_weights_binary(layer l, FILE *fp) +void save_convolutional_weights_binary(dn_layer l, FILE *fp) { #ifdef GPU if(gpu_index >= 0){ @@ -955,7 +955,7 @@ void save_convolutional_weights_binary(layer l, FILE *fp) } } -void save_convolutional_weights(layer l, FILE *fp) +void save_convolutional_weights(dn_layer l, FILE *fp) { if(l.binary){ //save_convolutional_weights_binary(l, fp); @@ -976,7 +976,7 @@ void save_convolutional_weights(layer l, FILE *fp) fwrite(l.weights, sizeof(float), num, fp); } -void save_batchnorm_weights(layer l, FILE *fp) +void save_batchnorm_weights(dn_layer l, FILE *fp) { #ifdef GPU if(gpu_index >= 0){ @@ -988,7 +988,7 @@ void save_batchnorm_weights(layer l, FILE *fp) fwrite(l.rolling_variance, sizeof(float), l.c, fp); } -void save_connected_weights(layer l, FILE *fp) +void save_connected_weights(dn_layer l, FILE *fp) { #ifdef GPU if(gpu_index >= 0){ @@ -1004,7 +1004,7 @@ void save_connected_weights(layer l, FILE *fp) } } -void save_weights_upto(network *net, const char *filename, int cutoff) +void save_weights_upto(dn_network *net, const char *filename, int cutoff) { #ifdef GPU if(net->gpu_index >= 0){ @@ -1025,7 +1025,7 @@ void save_weights_upto(network *net, const char *filename, int cutoff) int i; for(i = 0; i < net->n && i < cutoff; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if (l.dontsave) continue; if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ save_convolutional_weights(l, fp); @@ -1077,7 +1077,7 @@ void save_weights_upto(network *net, const char *filename, int cutoff) } fclose(fp); } -void save_weights(network *net, const char *filename) +void save_weights(dn_network *net, const char *filename) { save_weights_upto(net, filename, net->n); } @@ -1095,7 +1095,7 @@ void transpose_matrix(float *a, int rows, int cols) free(transpose); } -void load_connected_weights(layer l, FILE *fp, int transpose) +void load_connected_weights(dn_layer l, FILE *fp, int transpose) { fread(l.biases, sizeof(float), l.outputs, fp); fread(l.weights, sizeof(float), l.outputs*l.inputs, fp); @@ -1119,7 +1119,7 @@ void load_connected_weights(layer l, FILE *fp, int transpose) #endif } -void load_batchnorm_weights(layer l, FILE *fp) +void load_batchnorm_weights(dn_layer l, FILE *fp) { fread(l.scales, sizeof(float), l.c, fp); fread(l.rolling_mean, sizeof(float), l.c, fp); @@ -1131,7 +1131,7 @@ void load_batchnorm_weights(layer l, FILE *fp) #endif } -void load_convolutional_weights_binary(layer l, FILE *fp) +void load_convolutional_weights_binary(dn_layer l, FILE *fp) { fread(l.biases, sizeof(float), l.n, fp); if (l.batch_normalize && (!l.dontloadscales)){ @@ -1161,7 +1161,7 @@ void load_convolutional_weights_binary(layer l, FILE *fp) #endif } -void load_convolutional_weights(layer l, FILE *fp) +void load_convolutional_weights(dn_layer l, FILE *fp) { if(l.binary){ //load_convolutional_weights_binary(l, fp); @@ -1215,7 +1215,7 @@ void load_convolutional_weights(layer l, FILE *fp) } -void load_weights_upto(network *net, const char *filename, int start, int cutoff) +void load_weights_upto(dn_network *net, const char *filename, int start, int cutoff) { #ifdef GPU if(net->gpu_index >= 0){ @@ -1244,7 +1244,7 @@ void load_weights_upto(network *net, const char *filename, int start, int cutoff int i; for(i = start; i < net->n && i < cutoff; ++i){ - layer l = net->layers[i]; + dn_layer l = net->layers[i]; if (l.dontload) continue; if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ load_convolutional_weights(l, fp); @@ -1305,7 +1305,7 @@ void load_weights_upto(network *net, const char *filename, int start, int cutoff fclose(fp); } -void load_weights(network *net, const char *filename) +void load_weights(dn_network *net, const char *filename) { load_weights_upto(net, filename, 0, net->n); } diff --git a/src/parser.h b/src/parser.h index c4daaf0a681..ee393f7a0f0 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,7 +3,7 @@ #include "darknet.h" #include "network.h" -void save_network(network net, const char *filename); -void save_weights_double(network net, const char *filename); +void save_network(dn_network net, const char *filename); +void save_weights_double(dn_network net, const char *filename); #endif diff --git a/src/region_layer.c b/src/region_layer.c index 7f1a3ec8800..cc7e2fbb804 100644 --- a/src/region_layer.c +++ b/src/region_layer.c @@ -10,9 +10,9 @@ #include #include -layer make_region_layer(int batch, int w, int h, int n, int classes, int coords) +dn_layer make_region_layer(int batch, int w, int h, int n, int classes, int coords) { - layer l = {0}; + dn_layer l = {0}; l.type = REGION; l.n = n; @@ -53,7 +53,7 @@ layer make_region_layer(int batch, int w, int h, int n, int classes, int coords) return l; } -void resize_region_layer(layer *l, int w, int h) +void resize_region_layer(dn_layer *l, int w, int h) { l->w = w; l->h = h; @@ -148,14 +148,14 @@ float tisnan(float x) return (x != x); } -int entry_index(layer l, int batch, int location, int entry) +int entry_index(dn_layer l, int batch, int location, int entry) { int n = location / (l.w*l.h); int loc = location % (l.w*l.h); return batch*l.outputs + n*l.w*l.h*(l.coords+l.classes+1) + entry*l.w*l.h + loc; } -void forward_region_layer(const layer l, network net) +void forward_region_layer(const dn_layer l, dn_network net) { int i,j,b,t,n; memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); @@ -320,7 +320,7 @@ void forward_region_layer(const layer l, network net) printf("Region Avg IOU: %f, Class: %f, Obj: %f, No Obj: %f, Avg Recall: %f, count: %d\n", avg_iou/count, avg_cat/class_count, avg_obj/count, avg_anyobj/(l.w*l.h*l.n*l.batch), recall/count, count); } -void backward_region_layer(const layer l, network net) +void backward_region_layer(const dn_layer l, dn_network net) { /* int b; @@ -361,7 +361,7 @@ void correct_region_boxes(detection *dets, int n, int w, int h, int netw, int ne } } -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) +void get_region_detections(dn_layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets) { int i,j,n,z; float *predictions = l.output; @@ -494,7 +494,7 @@ void backward_region_layer_gpu(const layer l, network net) } #endif -void zero_objectness(layer l) +void zero_objectness(dn_layer l) { int i, n; for (i = 0; i < l.w*l.h; ++i){ diff --git a/src/region_layer.h b/src/region_layer.h index 9f12fd187fd..89ec5ca5da7 100644 --- a/src/region_layer.h +++ b/src/region_layer.h @@ -5,10 +5,10 @@ #include "layer.h" #include "network.h" -layer make_region_layer(int batch, int w, int h, int n, int classes, int coords); -void forward_region_layer(const layer l, network net); -void backward_region_layer(const layer l, network net); -void resize_region_layer(layer *l, int w, int h); +dn_layer make_region_layer(int batch, int w, int h, int n, int classes, int coords); +void forward_region_layer(const dn_layer l, dn_network net); +void backward_region_layer(const dn_layer l, dn_network net); +void resize_region_layer(dn_layer *l, int w, int h); #ifdef GPU void forward_region_layer_gpu(const layer l, network net); diff --git a/src/reorg_layer.c b/src/reorg_layer.c index 31d6b843676..5ec39286438 100644 --- a/src/reorg_layer.c +++ b/src/reorg_layer.c @@ -5,9 +5,9 @@ #include -layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra) +dn_layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra) { - layer l = {0}; + dn_layer l = {0}; l.type = REORG; l.batch = batch; l.stride = stride; @@ -55,7 +55,7 @@ layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, return l; } -void resize_reorg_layer(layer *l, int w, int h) +void resize_reorg_layer(dn_layer *l, int w, int h) { int stride = l->stride; int c = l->c; @@ -88,7 +88,7 @@ void resize_reorg_layer(layer *l, int w, int h) #endif } -void forward_reorg_layer(const layer l, network net) +void forward_reorg_layer(const dn_layer l, dn_network net) { int i; if(l.flatten){ @@ -109,7 +109,7 @@ void forward_reorg_layer(const layer l, network net) } } -void backward_reorg_layer(const layer l, network net) +void backward_reorg_layer(const dn_layer l, dn_network net) { int i; if(l.flatten){ diff --git a/src/reorg_layer.h b/src/reorg_layer.h index e6513a5f441..21a756adf46 100644 --- a/src/reorg_layer.h +++ b/src/reorg_layer.h @@ -6,10 +6,10 @@ #include "layer.h" #include "network.h" -layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra); -void resize_reorg_layer(layer *l, int w, int h); -void forward_reorg_layer(const layer l, network net); -void backward_reorg_layer(const layer l, network net); +dn_layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra); +void resize_reorg_layer(dn_layer *l, int w, int h); +void forward_reorg_layer(const dn_layer l, dn_network net); +void backward_reorg_layer(const dn_layer l, dn_network net); #ifdef GPU void forward_reorg_layer_gpu(layer l, network net); diff --git a/src/rnn_layer.c b/src/rnn_layer.c index 8c9b457e26e..f75c1eea2f9 100644 --- a/src/rnn_layer.c +++ b/src/rnn_layer.c @@ -10,7 +10,7 @@ #include #include -static void increment_layer(layer *l, int steps) +static void increment_layer(dn_layer *l, int steps) { int num = l->outputs*l->batch*steps; l->output += num; @@ -26,11 +26,11 @@ static void increment_layer(layer *l, int steps) #endif } -layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam) +dn_layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam) { fprintf(stderr, "RNN Layer: %d inputs, %d outputs\n", inputs, outputs); batch = batch / steps; - layer l = {0}; + dn_layer l = {0}; l.batch = batch; l.type = RNN; l.steps = steps; @@ -39,17 +39,17 @@ layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION a l.state = calloc(batch*outputs, sizeof(float)); l.prev_state = calloc(batch*outputs, sizeof(float)); - l.input_layer = malloc(sizeof(layer)); + l.input_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.input_layer) = make_connected_layer(batch*steps, inputs, outputs, activation, batch_normalize, adam); l.input_layer->batch = batch; - l.self_layer = malloc(sizeof(layer)); + l.self_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.self_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam); l.self_layer->batch = batch; - l.output_layer = malloc(sizeof(layer)); + l.output_layer = malloc(sizeof(dn_layer)); fprintf(stderr, "\t\t"); *(l.output_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam); l.output_layer->batch = batch; @@ -79,21 +79,21 @@ layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION a return l; } -void update_rnn_layer(layer l, update_args a) +void update_rnn_layer(dn_layer l, update_args a) { update_connected_layer(*(l.input_layer), a); update_connected_layer(*(l.self_layer), a); update_connected_layer(*(l.output_layer), a); } -void forward_rnn_layer(layer l, network net) +void forward_rnn_layer(dn_layer l, dn_network net) { - network s = net; + dn_network s = net; s.train = net.train; int i; - layer input_layer = *(l.input_layer); - layer self_layer = *(l.self_layer); - layer output_layer = *(l.output_layer); + dn_layer input_layer = *(l.input_layer); + dn_layer self_layer = *(l.self_layer); + dn_layer output_layer = *(l.output_layer); fill_cpu(l.outputs * l.batch * l.steps, 0, output_layer.delta, 1); fill_cpu(l.outputs * l.batch * l.steps, 0, self_layer.delta, 1); @@ -127,14 +127,14 @@ void forward_rnn_layer(layer l, network net) } } -void backward_rnn_layer(layer l, network net) +void backward_rnn_layer(dn_layer l, dn_network net) { - network s = net; + dn_network s = net; s.train = net.train; int i; - layer input_layer = *(l.input_layer); - layer self_layer = *(l.self_layer); - layer output_layer = *(l.output_layer); + dn_layer input_layer = *(l.input_layer); + dn_layer self_layer = *(l.self_layer); + dn_layer output_layer = *(l.output_layer); increment_layer(&input_layer, l.steps-1); increment_layer(&self_layer, l.steps-1); diff --git a/src/rnn_layer.h b/src/rnn_layer.h index 270a63ffafc..ce87e100954 100644 --- a/src/rnn_layer.h +++ b/src/rnn_layer.h @@ -7,11 +7,11 @@ #include "network.h" #define USET -layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam); +dn_layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam); -void forward_rnn_layer(layer l, network net); -void backward_rnn_layer(layer l, network net); -void update_rnn_layer(layer l, update_args a); +void forward_rnn_layer(dn_layer l, dn_network net); +void backward_rnn_layer(dn_layer l, dn_network net); +void update_rnn_layer(dn_layer l, update_args a); #ifdef GPU void forward_rnn_layer_gpu(layer l, network net); diff --git a/src/route_layer.c b/src/route_layer.c index a8970a46001..f89ea5a7a2d 100644 --- a/src/route_layer.c +++ b/src/route_layer.c @@ -37,10 +37,10 @@ route_layer make_route_layer(int batch, int n, int *input_layers, int *input_siz return l; } -void resize_route_layer(route_layer *l, network *net) +void resize_route_layer(route_layer *l, dn_network *net) { int i; - layer first = net->layers[l->input_layers[0]]; + dn_layer first = net->layers[l->input_layers[0]]; l->out_w = first.out_w; l->out_h = first.out_h; l->out_c = first.out_c; @@ -48,7 +48,7 @@ void resize_route_layer(route_layer *l, network *net) l->input_sizes[0] = first.outputs; for(i = 1; i < l->n; ++i){ int index = l->input_layers[i]; - layer next = net->layers[index]; + dn_layer next = net->layers[index]; l->outputs += next.outputs; l->input_sizes[i] = next.outputs; if(next.out_w == first.out_w && next.out_h == first.out_h){ @@ -71,7 +71,7 @@ void resize_route_layer(route_layer *l, network *net) } -void forward_route_layer(const route_layer l, network net) +void forward_route_layer(const route_layer l, dn_network net) { int i, j; int offset = 0; @@ -86,7 +86,7 @@ void forward_route_layer(const route_layer l, network net) } } -void backward_route_layer(const route_layer l, network net) +void backward_route_layer(const route_layer l, dn_network net) { int i, j; int offset = 0; diff --git a/src/route_layer.h b/src/route_layer.h index 1d40330ff30..07a94ed5c1e 100644 --- a/src/route_layer.h +++ b/src/route_layer.h @@ -3,12 +3,12 @@ #include "network.h" #include "layer.h" -typedef layer route_layer; +typedef dn_layer route_layer; route_layer make_route_layer(int batch, int n, int *input_layers, int *input_size); -void forward_route_layer(const route_layer l, network net); -void backward_route_layer(const route_layer l, network net); -void resize_route_layer(route_layer *l, network *net); +void forward_route_layer(const route_layer l, dn_network net); +void backward_route_layer(const route_layer l, dn_network net); +void resize_route_layer(route_layer *l, dn_network *net); #ifdef GPU void forward_route_layer_gpu(const route_layer l, network net); diff --git a/src/shortcut_layer.c b/src/shortcut_layer.c index 49d17f56f66..e6186776be9 100644 --- a/src/shortcut_layer.c +++ b/src/shortcut_layer.c @@ -6,10 +6,10 @@ #include #include -layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2) +dn_layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2) { fprintf(stderr, "res %3d %4d x%4d x%4d -> %4d x%4d x%4d\n",index, w2,h2,c2, w,h,c); - layer l = {0}; + dn_layer l = {0}; l.type = SHORTCUT; l.batch = batch; l.w = w2; @@ -38,7 +38,7 @@ layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int return l; } -void resize_shortcut_layer(layer *l, int w, int h) +void resize_shortcut_layer(dn_layer *l, int w, int h) { assert(l->w == l->out_w); assert(l->h == l->out_h); @@ -59,14 +59,14 @@ void resize_shortcut_layer(layer *l, int w, int h) } -void forward_shortcut_layer(const layer l, network net) +void forward_shortcut_layer(const dn_layer l, dn_network net) { copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); shortcut_cpu(l.batch, l.w, l.h, l.c, net.layers[l.index].output, l.out_w, l.out_h, l.out_c, l.alpha, l.beta, l.output); activate_array(l.output, l.outputs*l.batch, l.activation); } -void backward_shortcut_layer(const layer l, network net) +void backward_shortcut_layer(const dn_layer l, dn_network net) { gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); axpy_cpu(l.outputs*l.batch, l.alpha, l.delta, 1, net.delta, 1); diff --git a/src/shortcut_layer.h b/src/shortcut_layer.h index 5f684fc1ead..cf4054b0262 100644 --- a/src/shortcut_layer.h +++ b/src/shortcut_layer.h @@ -4,10 +4,10 @@ #include "layer.h" #include "network.h" -layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); -void forward_shortcut_layer(const layer l, network net); -void backward_shortcut_layer(const layer l, network net); -void resize_shortcut_layer(layer *l, int w, int h); +dn_layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); +void forward_shortcut_layer(const dn_layer l, dn_network net); +void backward_shortcut_layer(const dn_layer l, dn_network net); +void resize_shortcut_layer(dn_layer *l, int w, int h); #ifdef GPU void forward_shortcut_layer_gpu(const layer l, network net); diff --git a/src/softmax_layer.c b/src/softmax_layer.c index 9cbc6be120d..cb18e407238 100644 --- a/src/softmax_layer.c +++ b/src/softmax_layer.c @@ -36,7 +36,7 @@ softmax_layer make_softmax_layer(int batch, int inputs, int groups) return l; } -void forward_softmax_layer(const softmax_layer l, network net) +void forward_softmax_layer(const softmax_layer l, dn_network net) { if(l.softmax_tree){ int i; @@ -56,7 +56,7 @@ void forward_softmax_layer(const softmax_layer l, network net) } } -void backward_softmax_layer(const softmax_layer l, network net) +void backward_softmax_layer(const softmax_layer l, dn_network net) { axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); } diff --git a/src/softmax_layer.h b/src/softmax_layer.h index 2e3ffe01a6c..7e4a4a7f495 100644 --- a/src/softmax_layer.h +++ b/src/softmax_layer.h @@ -3,12 +3,12 @@ #include "layer.h" #include "network.h" -typedef layer softmax_layer; +typedef dn_layer softmax_layer; void softmax_array(float *input, int n, float temp, float *output); softmax_layer make_softmax_layer(int batch, int inputs, int groups); -void forward_softmax_layer(const softmax_layer l, network net); -void backward_softmax_layer(const softmax_layer l, network net); +void forward_softmax_layer(const softmax_layer l, dn_network net); +void backward_softmax_layer(const softmax_layer l, dn_network net); #ifdef GPU void pull_softmax_layer_output(const softmax_layer l); diff --git a/src/upsample_layer.c b/src/upsample_layer.c index 605f21f8ebd..a49fa7abf1a 100644 --- a/src/upsample_layer.c +++ b/src/upsample_layer.c @@ -4,9 +4,9 @@ #include -layer make_upsample_layer(int batch, int w, int h, int c, int stride) +dn_layer make_upsample_layer(int batch, int w, int h, int c, int stride) { - layer l = {0}; + dn_layer l = {0}; l.type = UPSAMPLE; l.batch = batch; l.w = w; @@ -41,7 +41,7 @@ layer make_upsample_layer(int batch, int w, int h, int c, int stride) return l; } -void resize_upsample_layer(layer *l, int w, int h) +void resize_upsample_layer(dn_layer *l, int w, int h) { l->w = w; l->h = h; @@ -65,7 +65,7 @@ void resize_upsample_layer(layer *l, int w, int h) } -void forward_upsample_layer(const layer l, network net) +void forward_upsample_layer(const dn_layer l, dn_network net) { fill_cpu(l.outputs*l.batch, 0, l.output, 1); if(l.reverse){ @@ -75,7 +75,7 @@ void forward_upsample_layer(const layer l, network net) } } -void backward_upsample_layer(const layer l, network net) +void backward_upsample_layer(const dn_layer l, dn_network net) { if(l.reverse){ upsample_cpu(l.delta, l.out_w, l.out_h, l.c, l.batch, l.stride, 1, l.scale, net.delta); diff --git a/src/upsample_layer.h b/src/upsample_layer.h index 86790d10883..16469d67acf 100644 --- a/src/upsample_layer.h +++ b/src/upsample_layer.h @@ -2,10 +2,10 @@ #define UPSAMPLE_LAYER_H #include "darknet.h" -layer make_upsample_layer(int batch, int w, int h, int c, int stride); -void forward_upsample_layer(const layer l, network net); -void backward_upsample_layer(const layer l, network net); -void resize_upsample_layer(layer *l, int w, int h); +dn_layer make_upsample_layer(int batch, int w, int h, int c, int stride); +void forward_upsample_layer(const dn_layer l, dn_network net); +void backward_upsample_layer(const dn_layer l, dn_network net); +void resize_upsample_layer(dn_layer *l, int w, int h); #ifdef GPU void forward_upsample_layer_gpu(const layer l, network net); diff --git a/src/yolo_layer.c b/src/yolo_layer.c index 714e7009c4a..331328a8d92 100644 --- a/src/yolo_layer.c +++ b/src/yolo_layer.c @@ -10,10 +10,10 @@ #include #include -layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes) +dn_layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes) { int i; - layer l = {0}; + dn_layer l = {0}; l.type = YOLO; l.n = n; @@ -60,7 +60,7 @@ layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int return l; } -void resize_yolo_layer(layer *l, int w, int h) +void resize_yolo_layer(dn_layer *l, int w, int h) { l->w = w; l->h = h; @@ -122,14 +122,14 @@ void delta_yolo_class(float *output, float *delta, int index, int class, int cla } } -static int entry_index(layer l, int batch, int location, int entry) +static int entry_index(dn_layer l, int batch, int location, int entry) { int n = location / (l.w*l.h); int loc = location % (l.w*l.h); return batch*l.outputs + n*l.w*l.h*(4+l.classes+1) + entry*l.w*l.h + loc; } -void forward_yolo_layer(const layer l, network net) +void forward_yolo_layer(const dn_layer l, dn_network net) { int i,j,b,t,n; memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); @@ -239,7 +239,7 @@ void forward_yolo_layer(const layer l, network net) printf("Region %d Avg IOU: %f, Class: %f, Obj: %f, No Obj: %f, .5R: %f, .75R: %f, count: %d\n", net.index, avg_iou/count, avg_cat/class_count, avg_obj/count, avg_anyobj/(l.w*l.h*l.n*l.batch), recall/count, recall75/count, count); } -void backward_yolo_layer(const layer l, network net) +void backward_yolo_layer(const dn_layer l, dn_network net) { axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); } @@ -272,7 +272,7 @@ void correct_yolo_boxes(detection *dets, int n, int w, int h, int netw, int neth } } -int yolo_num_detections(layer l, float thresh) +int yolo_num_detections(dn_layer l, float thresh) { int i, n; int count = 0; @@ -287,7 +287,7 @@ int yolo_num_detections(layer l, float thresh) return count; } -void avg_flipped_yolo(layer l) +void avg_flipped_yolo(dn_layer l) { int i,j,n,z; float *flip = l.output + l.outputs; @@ -313,7 +313,7 @@ void avg_flipped_yolo(layer l) } } -int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets) +int get_yolo_detections(dn_layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets) { int i,j,n; float *predictions = l.output; diff --git a/src/yolo_layer.h b/src/yolo_layer.h index d2a02432681..185f2033591 100644 --- a/src/yolo_layer.h +++ b/src/yolo_layer.h @@ -5,11 +5,11 @@ #include "layer.h" #include "network.h" -layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes); -void forward_yolo_layer(const layer l, network net); -void backward_yolo_layer(const layer l, network net); -void resize_yolo_layer(layer *l, int w, int h); -int yolo_num_detections(layer l, float thresh); +dn_layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes); +void forward_yolo_layer(const dn_layer l, dn_network net); +void backward_yolo_layer(const dn_layer l, dn_network net); +void resize_yolo_layer(dn_layer *l, int w, int h); +int yolo_num_detections(dn_layer l, float thresh); #ifdef GPU void forward_yolo_layer_gpu(const layer l, network net); From 75ff9c56ee8d5382075434c11ac78bb3a854faaa Mon Sep 17 00:00:00 2001 From: oscarkramer Date: Tue, 19 Mar 2019 14:41:18 -0400 Subject: [PATCH 6/8] Continued prefixing DN-specific types --- .idea/workspace.xml | 396 +++++++++++++++------------------- examples/attention.c | 2 +- examples/captcha.c | 2 +- examples/classifier.c | 6 +- examples/coco.c | 6 +- examples/detector.c | 8 +- examples/instance-segmenter.c | 2 +- examples/regressor.c | 2 +- examples/segmenter.c | 2 +- examples/super.c | 2 +- examples/swag.c | 2 +- examples/tag.c | 2 +- examples/voxel.c | 2 +- examples/writing.c | 2 +- examples/yolo.c | 6 +- include/darknet.h | 20 +- src/data.c | 34 +-- src/data.h | 2 +- src/network.c | 4 +- src/parser.c | 74 +++---- 20 files changed, 268 insertions(+), 308 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6ccbe28fbd5..5cbaf07ddef 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,17 +15,11 @@ - - - - - - @@ -34,72 +28,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - @@ -126,18 +58,18 @@ - + - - + + - - + + @@ -145,21 +77,23 @@ - - + + + - + - + - - + + + @@ -168,29 +102,27 @@ - + - - + + - + - - - + - - + + @@ -198,8 +130,8 @@ - - + + @@ -207,57 +139,66 @@ - - + + + + + + + + + + + - - - - - + - - + + - + - + - - + + + + + + - - + + - - + + - - + + - + - - + + @@ -290,14 +231,33 @@ - + - - + + + + + + + + + + + + + + + + + + + + + @@ -357,11 +317,12 @@ @@ -372,7 +333,7 @@ DEFINITION_ORDER - + - - + - + @@ -491,12 +447,12 @@ - + - - + + @@ -544,46 +500,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -637,13 +561,6 @@ - - - - - - - @@ -710,13 +627,6 @@ - - - - - - - @@ -740,13 +650,6 @@ - - - - - - - @@ -761,9 +664,6 @@ - - - @@ -771,73 +671,133 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - + - + - - + + - + + + + + + + - - + + - + - - + + - + + + + + + + + - - + + - + - - + + - + - - + + diff --git a/examples/attention.c b/examples/attention.c index ee647942628..e3c5eec5773 100644 --- a/examples/attention.c +++ b/examples/attention.c @@ -95,7 +95,7 @@ void train_attention(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int divs=3; int size=2; - load_args args = {0}; + dn_load_args args = {0}; args.w = divs*net->w/size; args.h = divs*net->h/size; args.size = divs*net->w/size; diff --git a/examples/captcha.c b/examples/captcha.c index d046f580f70..3d4be72480a 100644 --- a/examples/captcha.c +++ b/examples/captcha.c @@ -49,7 +49,7 @@ void train_captcha(char *cfgfile, char *weightfile) dn_data train; dn_data buffer; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.paths = paths; diff --git a/examples/classifier.c b/examples/classifier.c index 87b26a826b9..e495feb6103 100644 --- a/examples/classifier.c +++ b/examples/classifier.c @@ -61,7 +61,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int N = plist->size; double time; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.threads = 32; @@ -195,7 +195,7 @@ void validate_classifier_crop(char *datacfg, char *filename, char *weightfile) dn_data val, buffer; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; @@ -707,7 +707,7 @@ void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_ dn_data val, buffer; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.paths = paths; diff --git a/examples/coco.c b/examples/coco.c index 1f5ad80102f..b15ae280a70 100644 --- a/examples/coco.c +++ b/examples/coco.c @@ -34,7 +34,7 @@ void train_coco(char *cfgfile, char *weightfile) //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.paths = paths; @@ -161,7 +161,7 @@ void validate_coco(char *cfg, char *weights) dn_image *buf_resized = calloc(nthreads, sizeof(dn_image)); pthread_t *thr = calloc(nthreads, sizeof(pthread_t)); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.type = IMAGE_DATA; @@ -262,7 +262,7 @@ void validate_coco_recall(char *cfgfile, char *weightfile) find_replace(labelpath, ".JPEG", ".txt", labelpath); int num_labels = 0; - box_label *truth = read_boxes(labelpath, &num_labels); + dn_box_label *truth = read_boxes(labelpath, &num_labels); for(k = 0; k < side*side*l.n; ++k){ if(dets[k].objectness > thresh){ ++proposals; diff --git a/examples/detector.c b/examples/detector.c index fef03b04b2a..f6ddc3f6bf8 100644 --- a/examples/detector.c +++ b/examples/detector.c @@ -42,7 +42,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = get_base_args(net); + dn_load_args args = get_base_args(net); args.coords = l.coords; args.paths = paths; args.n = imgs; @@ -297,7 +297,7 @@ void validate_detector_flip(char *datacfg, char *cfgfile, char *weightfile, char dn_image input = make_image(net->w, net->h, net->c*2); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; //args.type = IMAGE_DATA; @@ -426,7 +426,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out dn_image *buf_resized = calloc(nthreads, sizeof(dn_image)); pthread_t *thr = calloc(nthreads, sizeof(pthread_t)); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; //args.type = IMAGE_DATA; @@ -529,7 +529,7 @@ void validate_detector_recall(char *cfgfile, char *weightfile) find_replace(labelpath, ".JPEG", ".txt", labelpath); int num_labels = 0; - box_label *truth = read_boxes(labelpath, &num_labels); + dn_box_label *truth = read_boxes(labelpath, &num_labels); for(k = 0; k < nboxes; ++k){ if(dets[k].objectness > thresh){ ++proposals; diff --git a/examples/instance-segmenter.c b/examples/instance-segmenter.c index 189ac1954af..4639c7f1cd2 100644 --- a/examples/instance-segmenter.c +++ b/examples/instance-segmenter.c @@ -48,7 +48,7 @@ void train_isegmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, printf("%d\n", plist->size); int N = plist->size; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.threads = 32; diff --git a/examples/regressor.c b/examples/regressor.c index b09086f0ed0..a4f4eb55d55 100644 --- a/examples/regressor.c +++ b/examples/regressor.c @@ -40,7 +40,7 @@ void train_regressor(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int N = plist->size; clock_t time; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.threads = 32; diff --git a/examples/segmenter.c b/examples/segmenter.c index b57bf968a6d..5e4530a76bd 100644 --- a/examples/segmenter.c +++ b/examples/segmenter.c @@ -43,7 +43,7 @@ void train_segmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, printf("%d\n", plist->size); int N = plist->size; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.threads = 32; diff --git a/examples/super.c b/examples/super.c index 9cf0b9d3456..5b083c47228 100644 --- a/examples/super.c +++ b/examples/super.c @@ -19,7 +19,7 @@ void train_super(char *cfgfile, char *weightfile, int clear) //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.scale = 4; diff --git a/examples/swag.c b/examples/swag.c index 9f6bab01826..e877b71145e 100644 --- a/examples/swag.c +++ b/examples/swag.c @@ -28,7 +28,7 @@ void train_swag(char *cfgfile, char *weightfile) //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.paths = paths; diff --git a/examples/tag.c b/examples/tag.c index 029f87240d1..d307e25d5d4 100644 --- a/examples/tag.c +++ b/examples/tag.c @@ -19,7 +19,7 @@ void train_tag(char *cfgfile, char *weightfile, int clear) dn_data train; dn_data buffer; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; diff --git a/examples/voxel.c b/examples/voxel.c index d84201fba2f..80a652018e5 100644 --- a/examples/voxel.c +++ b/examples/voxel.c @@ -58,7 +58,7 @@ void train_voxel(char *cfgfile, char *weightfile) //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.scale = 4; diff --git a/examples/writing.c b/examples/writing.c index 5e2d029c987..419f45ab725 100644 --- a/examples/writing.c +++ b/examples/writing.c @@ -22,7 +22,7 @@ void train_writing(char *cfgfile, char *weightfile) dn_data train, buffer; - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.out_w = out.w; diff --git a/examples/yolo.c b/examples/yolo.c index 40f27f2f027..a7efbc4efbf 100644 --- a/examples/yolo.c +++ b/examples/yolo.c @@ -27,7 +27,7 @@ void train_yolo(char *cfgfile, char *weightfile) //int N = plist->size; char **paths = (char **)list_to_array(plist); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.paths = paths; @@ -134,7 +134,7 @@ void validate_yolo(char *cfg, char *weights) dn_image *buf_resized = calloc(nthreads, sizeof(dn_image)); pthread_t *thr = calloc(nthreads, sizeof(pthread_t)); - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.type = IMAGE_DATA; @@ -232,7 +232,7 @@ void validate_yolo_recall(char *cfg, char *weights) find_replace(labelpath, ".JPEG", ".txt", labelpath); int num_labels = 0; - box_label *truth = read_boxes(labelpath, &num_labels); + dn_box_label *truth = read_boxes(labelpath, &num_labels); for(k = 0; k < side*side*l.n; ++k){ if(dets[k].objectness > thresh){ ++proposals; diff --git a/include/darknet.h b/include/darknet.h index 6947a904d97..b7989415646 100644 --- a/include/darknet.h +++ b/include/darknet.h @@ -542,9 +542,9 @@ typedef struct{ typedef enum { CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA, SWAG_DATA, TAG_DATA, OLD_CLASSIFICATION_DATA, STUDY_DATA, DET_DATA, SUPER_DATA, LETTERBOX_DATA, REGRESSION_DATA, SEGMENTATION_DATA, INSTANCE_DATA, ISEG_DATA -} data_type; +} dn_data_type; -typedef struct load_args{ +typedef struct dn_load_args{ int threads; char **paths; char *path; @@ -573,19 +573,19 @@ typedef struct load_args{ dn_data *d; dn_image *im; dn_image *resized; - data_type type; + dn_data_type type; dn_tree *hierarchy; -} load_args; +} dn_load_args; typedef struct{ int id; float x,y,w,h; float left, right, top, bottom; -} box_label; +} dn_box_label; dn_network *load_network(const char *cfg, const char *weights, int clear); -load_args get_base_args(dn_network *net); +dn_load_args get_base_args(dn_network *net); void free_data(dn_data d); @@ -601,7 +601,7 @@ typedef struct dn_list{ dn_node *back; } dn_list; -pthread_t load_data(load_args args); +pthread_t load_data(dn_load_args args); dn_list *read_data_cfg(const char *filename); dn_list *read_cfg(const char *filename); unsigned char *read_file(const char *filename); @@ -730,7 +730,7 @@ dn_image rotate_image(dn_image m, float rad); void visualize_network(dn_network *net); float box_iou(dn_box a, dn_box b); dn_data load_all_cifar10(); -box_label *read_boxes(const char *filename, int *n); +dn_box_label *read_boxes(const char *filename, int *n); dn_box float_to_box(float *f, int stride); void draw_detections(dn_image im, detection *dets, int num, float thresh, char **names, dn_image **alphabet, int classes); @@ -762,8 +762,8 @@ void make_window(char *name, int w, int h, int fullscreen); void free_image(dn_image m); float train_network(dn_network *net, dn_data d); -pthread_t load_data_in_thread(load_args args); -void load_data_blocking(load_args args); +pthread_t load_data_in_thread(dn_load_args args); +void load_data_blocking(dn_load_args args); dn_list *get_paths(const char *filename); void hierarchy_predictions(float *predictions, int n, dn_tree *hier, int only_leaves, int stride); void change_leaves(dn_tree *t, char *leaf_list); diff --git a/src/data.c b/src/data.c index a38c61e1e61..3097f049e10 100644 --- a/src/data.c +++ b/src/data.c @@ -136,7 +136,7 @@ dn_matrix load_image_augment_paths(char **paths, int n, int min, int max, int si } -box_label *read_boxes(const char *filename, int *n) +dn_box_label *read_boxes(const char *filename, int *n) { FILE *file = fopen(filename, "r"); if(!file) file_error(filename); @@ -144,11 +144,11 @@ box_label *read_boxes(const char *filename, int *n) int id; int count = 0; int size = 64; - box_label *boxes = calloc(size, sizeof(box_label)); + dn_box_label *boxes = calloc(size, sizeof(dn_box_label)); while(fscanf(file, "%d %f %f %f %f", &id, &x, &y, &w, &h) == 5){ if(count == size) { size = size * 2; - boxes = realloc(boxes, size*sizeof(box_label)); + boxes = realloc(boxes, size*sizeof(dn_box_label)); } boxes[count].id = id; boxes[count].x = x; @@ -166,18 +166,18 @@ box_label *read_boxes(const char *filename, int *n) return boxes; } -void randomize_boxes(box_label *b, int n) +void randomize_boxes(dn_box_label *b, int n) { int i; for(i = 0; i < n; ++i){ - box_label swap = b[i]; + dn_box_label swap = b[i]; int index = rand()%n; b[i] = b[index]; b[index] = swap; } } -void correct_boxes(box_label *boxes, int n, float dx, float dy, float sx, float sy, int flip) +void correct_boxes(dn_box_label *boxes, int n, float dx, float dy, float sx, float sy, int flip) { int i; for(i = 0; i < n; ++i){ @@ -224,7 +224,7 @@ void fill_truth_swag(char *path, float *truth, int classes, int flip, float dx, find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; - box_label *boxes = read_boxes(labelpath, &count); + dn_box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); float x,y,w,h; @@ -263,7 +263,7 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; - box_label *boxes = read_boxes(labelpath, &count); + dn_box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); float x,y,w,h; @@ -456,7 +456,7 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; - box_label *boxes = read_boxes(labelpath, &count); + dn_box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); if(count > num_boxes) count = num_boxes; @@ -1090,7 +1090,7 @@ dn_data load_data_detection(int n, char **paths, int m, int w, int h, int boxes, void *load_thread(void *ptr) { //printf("Loading data: %d\n", rand()); - load_args a = *(struct load_args*)ptr; + dn_load_args a = *(struct dn_load_args*)ptr; if(a.exposure == 0) a.exposure = 1; if(a.saturation == 0) a.saturation = 1; if(a.aspect == 0) a.aspect = 1; @@ -1132,10 +1132,10 @@ void *load_thread(void *ptr) return 0; } -pthread_t load_data_in_thread(load_args args) +pthread_t load_data_in_thread(dn_load_args args) { pthread_t thread; - struct load_args *ptr = calloc(1, sizeof(struct load_args)); + struct dn_load_args *ptr = calloc(1, sizeof(struct dn_load_args)); *ptr = args; if(pthread_create(&thread, 0, load_thread, ptr)) error("Thread creation failed"); return thread; @@ -1144,7 +1144,7 @@ pthread_t load_data_in_thread(load_args args) void *load_threads(void *ptr) { int i; - load_args args = *(load_args *)ptr; + dn_load_args args = *(dn_load_args *)ptr; if (args.threads == 0) args.threads = 1; dn_data *out = args.d; int total = args.n; @@ -1170,17 +1170,17 @@ void *load_threads(void *ptr) return 0; } -void load_data_blocking(load_args args) +void load_data_blocking(dn_load_args args) { - struct load_args *ptr = calloc(1, sizeof(struct load_args)); + struct dn_load_args *ptr = calloc(1, sizeof(struct dn_load_args)); *ptr = args; load_thread(ptr); } -pthread_t load_data(load_args args) +pthread_t load_data(dn_load_args args) { pthread_t thread; - struct load_args *ptr = calloc(1, sizeof(struct load_args)); + struct dn_load_args *ptr = calloc(1, sizeof(struct dn_load_args)); *ptr = args; if(pthread_create(&thread, 0, load_threads, ptr)) error("Thread creation failed"); return thread; diff --git a/src/data.h b/src/data.h index 3faaf633082..5213fbe9824 100644 --- a/src/data.h +++ b/src/data.h @@ -18,7 +18,7 @@ static inline float distance_from_edge(int x, int max) if (dist > 1) dist = 1; return dist; } -void load_data_blocking(load_args args); +void load_data_blocking(dn_load_args args); void print_letters(float *pred, int n); diff --git a/src/network.c b/src/network.c index e12b82a87fd..76d5dd04cd0 100644 --- a/src/network.c +++ b/src/network.c @@ -32,9 +32,9 @@ #include "parser.h" #include "data.h" -load_args get_base_args(dn_network *net) +dn_load_args get_base_args(dn_network *net) { - load_args args = {0}; + dn_load_args args = {0}; args.w = net->w; args.h = net->h; args.size = net->w; diff --git a/src/parser.c b/src/parser.c index 7228828a075..b7f0704c15a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -40,7 +40,7 @@ typedef struct{ char *type; dn_list *options; -}section; +}dn_section; dn_list *read_cfg(const char *filename); @@ -86,7 +86,7 @@ LAYER_TYPE string_to_layer_type(char * type) return BLANK; } -void free_section(section *s) +void free_section(dn_section *s) { free(s->type); dn_node *n = s->options->front; @@ -118,7 +118,7 @@ void parse_data(char *data, float *a, int n) } } -typedef struct size_params{ +typedef struct dn_size_params{ int batch; int inputs; int h; @@ -127,9 +127,9 @@ typedef struct size_params{ int index; int time_steps; dn_network *net; -} size_params; +} dn_size_params; -local_layer parse_local(dn_list *options, size_params params) +local_layer parse_local(dn_list *options, dn_size_params params) { int n = option_find_int(options, "filters",1); int size = option_find_int(options, "size",1); @@ -150,7 +150,7 @@ local_layer parse_local(dn_list *options, size_params params) return layer; } -dn_layer parse_deconvolutional(dn_list *options, size_params params) +dn_layer parse_deconvolutional(dn_list *options, dn_size_params params) { int n = option_find_int(options, "filters",1); int size = option_find_int(options, "size",1); @@ -176,7 +176,7 @@ dn_layer parse_deconvolutional(dn_list *options, size_params params) } -convolutional_layer parse_convolutional(dn_list *options, size_params params) +convolutional_layer parse_convolutional(dn_list *options, dn_size_params params) { int n = option_find_int(options, "filters",1); int size = option_find_int(options, "size",1); @@ -206,7 +206,7 @@ convolutional_layer parse_convolutional(dn_list *options, size_params params) return layer; } -dn_layer parse_crnn(dn_list *options, size_params params) +dn_layer parse_crnn(dn_list *options, dn_size_params params) { int output_filters = option_find_int(options, "output_filters",1); int hidden_filters = option_find_int(options, "hidden_filters",1); @@ -221,7 +221,7 @@ dn_layer parse_crnn(dn_list *options, size_params params) return l; } -dn_layer parse_rnn(dn_list *options, size_params params) +dn_layer parse_rnn(dn_list *options, dn_size_params params) { int output = option_find_int(options, "output",1); char *activation_s = option_find_str(options, "activation", "logistic"); @@ -235,7 +235,7 @@ dn_layer parse_rnn(dn_list *options, size_params params) return l; } -dn_layer parse_gru(dn_list *options, size_params params) +dn_layer parse_gru(dn_list *options, dn_size_params params) { int output = option_find_int(options, "output",1); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); @@ -246,7 +246,7 @@ dn_layer parse_gru(dn_list *options, size_params params) return l; } -dn_layer parse_lstm(dn_list *options, size_params params) +dn_layer parse_lstm(dn_list *options, dn_size_params params) { int output = option_find_int(options, "output", 1); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); @@ -256,7 +256,7 @@ dn_layer parse_lstm(dn_list *options, size_params params) return l; } -dn_layer parse_connected(dn_list *options, size_params params) +dn_layer parse_connected(dn_list *options, dn_size_params params) { int output = option_find_int(options, "output",1); char *activation_s = option_find_str(options, "activation", "logistic"); @@ -267,7 +267,7 @@ dn_layer parse_connected(dn_list *options, size_params params) return l; } -dn_layer parse_softmax(dn_list *options, size_params params) +dn_layer parse_softmax(dn_list *options, dn_size_params params) { int groups = option_find_int_quiet(options, "groups",1); dn_layer l = make_softmax_layer(params.batch, params.inputs, groups); @@ -303,7 +303,7 @@ int *parse_yolo_mask(char *a, int *num) return mask; } -dn_layer parse_yolo(dn_list *options, size_params params) +dn_layer parse_yolo(dn_list *options, dn_size_params params) { int classes = option_find_int(options, "classes", 20); int total = option_find_int(options, "num", 1); @@ -341,7 +341,7 @@ dn_layer parse_yolo(dn_list *options, size_params params) return l; } -dn_layer parse_iseg(dn_list *options, size_params params) +dn_layer parse_iseg(dn_list *options, dn_size_params params) { int classes = option_find_int(options, "classes", 20); int ids = option_find_int(options, "ids", 32); @@ -350,7 +350,7 @@ dn_layer parse_iseg(dn_list *options, size_params params) return l; } -dn_layer parse_region(dn_list *options, size_params params) +dn_layer parse_region(dn_list *options, dn_size_params params) { int coords = option_find_int(options, "coords", 4); int classes = option_find_int(options, "classes", 20); @@ -402,7 +402,7 @@ dn_layer parse_region(dn_list *options, size_params params) return l; } -detection_layer parse_detection(dn_list *options, size_params params) +detection_layer parse_detection(dn_list *options, dn_size_params params) { int coords = option_find_int(options, "coords", 1); int classes = option_find_int(options, "classes", 1); @@ -426,7 +426,7 @@ detection_layer parse_detection(dn_list *options, size_params params) return layer; } -cost_layer parse_cost(dn_list *options, size_params params) +cost_layer parse_cost(dn_list *options, dn_size_params params) { char *type_s = option_find_str(options, "type", "sse"); COST_TYPE type = get_cost_type(type_s); @@ -438,7 +438,7 @@ cost_layer parse_cost(dn_list *options, size_params params) return layer; } -crop_layer parse_crop(dn_list *options, size_params params) +crop_layer parse_crop(dn_list *options, dn_size_params params) { int crop_height = option_find_int(options, "crop_height",1); int crop_width = option_find_int(options, "crop_width",1); @@ -462,7 +462,7 @@ crop_layer parse_crop(dn_list *options, size_params params) return l; } -dn_layer parse_reorg(dn_list *options, size_params params) +dn_layer parse_reorg(dn_list *options, dn_size_params params) { int stride = option_find_int(options, "stride",1); int reverse = option_find_int_quiet(options, "reverse",0); @@ -480,7 +480,7 @@ dn_layer parse_reorg(dn_list *options, size_params params) return layer; } -maxpool_layer parse_maxpool(dn_list *options, size_params params) +maxpool_layer parse_maxpool(dn_list *options, dn_size_params params) { int stride = option_find_int(options, "stride",1); int size = option_find_int(options, "size",stride); @@ -497,7 +497,7 @@ maxpool_layer parse_maxpool(dn_list *options, size_params params) return layer; } -avgpool_layer parse_avgpool(dn_list *options, size_params params) +avgpool_layer parse_avgpool(dn_list *options, dn_size_params params) { int batch,w,h,c; w = params.w; @@ -510,7 +510,7 @@ avgpool_layer parse_avgpool(dn_list *options, size_params params) return layer; } -dropout_layer parse_dropout(dn_list *options, size_params params) +dropout_layer parse_dropout(dn_list *options, dn_size_params params) { float probability = option_find_float(options, "probability", .5); dropout_layer layer = make_dropout_layer(params.batch, params.inputs, probability); @@ -520,7 +520,7 @@ dropout_layer parse_dropout(dn_list *options, size_params params) return layer; } -dn_layer parse_normalization(dn_list *options, size_params params) +dn_layer parse_normalization(dn_list *options, dn_size_params params) { float alpha = option_find_float(options, "alpha", .0001); float beta = option_find_float(options, "beta" , .75); @@ -530,13 +530,13 @@ dn_layer parse_normalization(dn_list *options, size_params params) return l; } -dn_layer parse_batchnorm(dn_list *options, size_params params) +dn_layer parse_batchnorm(dn_list *options, dn_size_params params) { dn_layer l = make_batchnorm_layer(params.batch, params.w, params.h, params.c); return l; } -dn_layer parse_shortcut(dn_list *options, size_params params, dn_network *net) +dn_layer parse_shortcut(dn_list *options, dn_size_params params, dn_network *net) { char *l = option_find(options, "from"); int index = atoi(l); @@ -556,7 +556,7 @@ dn_layer parse_shortcut(dn_list *options, size_params params, dn_network *net) } -dn_layer parse_l2norm(dn_list *options, size_params params) +dn_layer parse_l2norm(dn_list *options, dn_size_params params) { dn_layer l = make_l2norm_layer(params.batch, params.inputs); l.h = l.out_h = params.h; @@ -566,7 +566,7 @@ dn_layer parse_l2norm(dn_list *options, size_params params) } -dn_layer parse_logistic(dn_list *options, size_params params) +dn_layer parse_logistic(dn_list *options, dn_size_params params) { dn_layer l = make_logistic_layer(params.batch, params.inputs); l.h = l.out_h = params.h; @@ -575,7 +575,7 @@ dn_layer parse_logistic(dn_list *options, size_params params) return l; } -dn_layer parse_activation(dn_list *options, size_params params) +dn_layer parse_activation(dn_list *options, dn_size_params params) { char *activation_s = option_find_str(options, "activation", "linear"); ACTIVATION activation = get_activation(activation_s); @@ -589,7 +589,7 @@ dn_layer parse_activation(dn_list *options, size_params params) return l; } -dn_layer parse_upsample(dn_list *options, size_params params, dn_network *net) +dn_layer parse_upsample(dn_list *options, dn_size_params params, dn_network *net) { int stride = option_find_int(options, "stride",2); @@ -598,7 +598,7 @@ dn_layer parse_upsample(dn_list *options, size_params params, dn_network *net) return l; } -route_layer parse_route(dn_list *options, size_params params, dn_network *net) +route_layer parse_route(dn_list *options, dn_size_params params, dn_network *net) { char *l = option_find(options, "layers"); int len = strlen(l); @@ -733,7 +733,7 @@ void parse_net_options(dn_list *options, dn_network *net) net->max_batches = option_find_int(options, "max_batches", 0); } -int is_network(section *s) +int is_network(dn_section *s) { return (strcmp(s->type, "[net]")==0 || strcmp(s->type, "[network]")==0); @@ -746,9 +746,9 @@ dn_network* parse_network_cfg(const char *filename) if(!n) error("Config file has no sections"); dn_network *net = make_network(sections->size - 1); net->gpu_index = gpu_index; - size_params params; + dn_size_params params; - section *s = (section *)n->val; + dn_section *s = (dn_section *)n->val; dn_list *options = s->options; if(!is_network(s)) error("First section must be [net] or [network]"); parse_net_options(options, net); @@ -769,7 +769,7 @@ dn_network* parse_network_cfg(const char *filename) while(n){ params.index = count; fprintf(stderr, "%5d ", count); - s = (section *)n->val; + s = (dn_section *)n->val; options = s->options; dn_layer l = {0}; LAYER_TYPE lt = string_to_layer_type(s->type); @@ -895,13 +895,13 @@ dn_list *read_cfg(const char *filename) char *line; int nu = 0; dn_list *options = make_list(); - section *current = 0; + dn_section *current = 0; while((line=fgetl(file)) != 0){ ++ nu; strip(line); switch(line[0]){ case '[': - current = malloc(sizeof(section)); + current = malloc(sizeof(dn_section)); list_insert(options, current); current->options = make_list(); current->type = line; From ba05a4a4444380bc827d4c013db8cdc05270853d Mon Sep 17 00:00:00 2001 From: oscarkramer Date: Tue, 4 Jun 2019 13:47:46 -0400 Subject: [PATCH 7/8] Dunno but just in case --- .idea/codeStyles/Project.xml | 29 - .idea/workspace.xml | 459 +++----- src/gemm.c | 259 ++--- src/image.c | 2091 +++++++++++++++++----------------- 4 files changed, 1331 insertions(+), 1507 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626c231..00000000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5cbaf07ddef..27c0090c8e6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,6 +1,6 @@ - + @@ -13,25 +13,10 @@ - - - - - - - - - - - - - - - - - - - + + + + @@ -41,133 +26,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - + - - + + - + - - + + - - + + - - + + @@ -179,85 +77,35 @@ - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - + - - + + - - + + - - - - - @@ -280,10 +128,12 @@ conv %5d %2d load net - load_ load_network char *filename load_networ + is_1 + load_ + bias net-> @@ -304,7 +154,6 @@ - - - - true - DEFINITION_ORDER - - @@ -351,17 +196,7 @@ - - - - - - - - - - - +