diff --git a/Makefile b/Makefile index b67ecacd..36a451cc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -GPU=1 -CUDNN=1 -OPENCV=1 +GPU=0 +CUDNN=0 +OPENCV=0 DEBUG=0 ARCH= -gencode arch=compute_20,code=[sm_20,sm_21] \ @@ -10,7 +10,7 @@ ARCH= -gencode arch=compute_20,code=[sm_20,sm_21] \ -gencode arch=compute_52,code=[sm_52,compute_52] # This is what I use, uncomment if you know your arch and want to specify -ARCH= -gencode arch=compute_52,code=compute_52 +# ARCH= -gencode arch=compute_52,code=compute_52 VPATH=./src/:./examples LIB=libdarknet.a @@ -23,7 +23,7 @@ AR=ar ARFLAGS=-rv OPTS=-Ofast LDFLAGS= -lm -pthread -COMMON= -Iinclude/ +COMMON= -Iinclude/ -Isrc/ CFLAGS=-Wall -Wfatal-errors ifeq ($(DEBUG), 1) @@ -60,7 +60,7 @@ endif EXECOBJ = $(addprefix $(OBJDIR), $(EXECOBJA)) OBJS = $(addprefix $(OBJDIR), $(OBJ)) -DEPS = $(wildcard include/darknet/*.h) Makefile +DEPS = $(wildcard src/*.h) Makefile include/darknet.h all: obj backup results $(LIB) $(EXEC) diff --git a/examples/art.c b/examples/art.c index 53fe60d0..3f03f79f 100644 --- a/examples/art.c +++ b/examples/art.c @@ -1,9 +1,5 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" -#include "darknet/classifier.h" +#include "darknet.h" + #include void demo_art(char *cfgfile, char *weightfile, int cam_index) diff --git a/examples/captcha.c b/examples/captcha.c index dce713ae..1de21fa3 100644 --- a/examples/captcha.c +++ b/examples/captcha.c @@ -1,6 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" void fix_data_captcha(data d, int mask) { diff --git a/examples/cifar.c b/examples/cifar.c index fbbea285..a05d0997 100644 --- a/examples/cifar.c +++ b/examples/cifar.c @@ -1,8 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" +#include "darknet.h" void train_cifar(char *cfgfile, char *weightfile) { diff --git a/examples/classifier.c b/examples/classifier.c index 440ab21a..112b913d 100644 --- a/examples/classifier.c +++ b/examples/classifier.c @@ -1,10 +1,5 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" -#include "darknet/classifier.h" -#include "darknet/cuda.h" +#include "darknet.h" + #include #include @@ -37,11 +32,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, #ifdef GPU cuda_set_device(gpus[i]); #endif - nets[i] = parse_network_cfg(cfgfile); - if(weightfile){ - load_weights(&nets[i], weightfile); - } - if(clear) *nets[i].seen = 0; + nets[i] = load_network(cfgfile, weightfile, clear); nets[i].learning_rate *= ngpus; } srand(time(0)); diff --git a/examples/coco.c b/examples/coco.c index 02e62455..bab507d9 100644 --- a/examples/coco.c +++ b/examples/coco.c @@ -1,12 +1,6 @@ -#include +#include "darknet.h" -#include "darknet/network.h" -#include "darknet/detection_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" -#include "darknet/demo.h" +#include char *coco_classes[] = {"person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","dining table","toilet","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"}; diff --git a/examples/darknet.c b/examples/darknet.c index 4592dc3e..31652b12 100644 --- a/examples/darknet.c +++ b/examples/darknet.c @@ -1,14 +1,9 @@ +#include "darknet.h" + #include #include #include -#include "darknet/parser.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/connected_layer.h" -#include "darknet/convolutional_layer.h" - extern void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top); extern void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh, float hier_thresh, char *outfile, int fullscreen); extern void run_voxel(int argc, char **argv); diff --git a/examples/detector.c b/examples/detector.c index 2c8234d8..0a31fc27 100644 --- a/examples/detector.c +++ b/examples/detector.c @@ -1,12 +1,4 @@ -#include "darknet/network.h" -#include "darknet/region_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" -#include "darknet/demo.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" +#include "darknet.h" static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90}; diff --git a/examples/dice.c b/examples/dice.c index 7a2a1949..6a810492 100644 --- a/examples/dice.c +++ b/examples/dice.c @@ -1,6 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" char *dice_labels[] = {"face1","face2","face3","face4","face5","face6"}; diff --git a/examples/go.c b/examples/go.c index 3e3d5f67..f4513574 100644 --- a/examples/go.c +++ b/examples/go.c @@ -1,9 +1,5 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" -#include "darknet/data.h" +#include "darknet.h" + #include int inverted = 1; diff --git a/examples/lsd.c b/examples/lsd.c index 61f8e8f2..85641ecd 100644 --- a/examples/lsd.c +++ b/examples/lsd.c @@ -1,8 +1,4 @@ -#include "darknet/network.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/blas.h" +#include "darknet.h" /* void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg, char *aweight, int clear) diff --git a/examples/nightmare.c b/examples/nightmare.c index 3eda5fb6..9538238d 100644 --- a/examples/nightmare.c +++ b/examples/nightmare.c @@ -1,8 +1,4 @@ -#include "darknet/network.h" -#include "darknet/parser.h" -#include "darknet/blas.h" -#include "darknet/utils.h" -#include "darknet/region_layer.h" +#include "darknet.h" // ./darknet nightmare cfg/extractor.recon.cfg ~/trained/yolo-coco.conv frame6.png -reconstruct -iters 500 -i 3 -lambda .1 -rate .01 -smooth 2 diff --git a/examples/regressor.c b/examples/regressor.c index 30021e7f..6dd2b4a2 100644 --- a/examples/regressor.c +++ b/examples/regressor.c @@ -1,9 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" -#include "darknet/cuda.h" +#include "darknet.h" #include #include diff --git a/examples/rnn.c b/examples/rnn.c index ded23975..0ea4daab 100644 --- a/examples/rnn.c +++ b/examples/rnn.c @@ -1,8 +1,4 @@ -#include "darknet/network.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/blas.h" -#include "darknet/parser.h" +#include "darknet.h" typedef struct { float *x; diff --git a/examples/rnn_vid.c b/examples/rnn_vid.c index a5e2a758..205f24c0 100644 --- a/examples/rnn_vid.c +++ b/examples/rnn_vid.c @@ -1,8 +1,4 @@ -#include "darknet/network.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/blas.h" +#include "darknet.h" #ifdef OPENCV image get_image_from_stream(CvCapture *cap); diff --git a/examples/segmenter.c b/examples/segmenter.c index 12eb5408..f24bbdaa 100644 --- a/examples/segmenter.c +++ b/examples/segmenter.c @@ -1,9 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/option_list.h" -#include "darknet/blas.h" -#include "darknet/cuda.h" +#include "darknet.h" #include #include @@ -153,7 +148,9 @@ void predict_segmenter(char *datafile, char *cfgfile, char *weightfile, char *fi image rgb = mask_to_rgb(m); show_image(sized, "orig"); show_image(rgb, "pred"); +#ifdef OPENCV cvWaitKey(0); +#endif printf("Predicted: %f\n", predictions[0]); printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); free_image(im); diff --git a/examples/super.c b/examples/super.c index d1f1bbf6..89521c94 100644 --- a/examples/super.c +++ b/examples/super.c @@ -1,7 +1,4 @@ -#include "darknet/network.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" void train_super(char *cfgfile, char *weightfile, int clear) { diff --git a/examples/swag.c b/examples/swag.c index 91a7beb7..c22d7855 100644 --- a/examples/swag.c +++ b/examples/swag.c @@ -1,9 +1,5 @@ -#include "darknet/network.h" -#include "darknet/detection_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" +#include "darknet.h" +#include void train_swag(char *cfgfile, char *weightfile) { diff --git a/examples/tag.c b/examples/tag.c index 32a1bd14..f10cea5f 100644 --- a/examples/tag.c +++ b/examples/tag.c @@ -1,6 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" void train_tag(char *cfgfile, char *weightfile, int clear) { diff --git a/examples/voxel.c b/examples/voxel.c index b9387bc4..01ea9bb9 100644 --- a/examples/voxel.c +++ b/examples/voxel.c @@ -1,7 +1,4 @@ -#include "darknet/network.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" void extract_voxel(char *lfile, char *rfile, char *prefix) { diff --git a/examples/writing.c b/examples/writing.c index 7136ff71..5d30ea90 100644 --- a/examples/writing.c +++ b/examples/writing.c @@ -1,6 +1,4 @@ -#include "darknet/network.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "darknet.h" void train_writing(char *cfgfile, char *weightfile) { diff --git a/examples/yolo.c b/examples/yolo.c index c1bef8bd..e6ac873e 100644 --- a/examples/yolo.c +++ b/examples/yolo.c @@ -1,10 +1,4 @@ -#include "darknet/network.h" -#include "darknet/detection_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" -#include "darknet/demo.h" +#include "darknet.h" char *voc_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"}; diff --git a/include/darknet.h b/include/darknet.h new file mode 100644 index 00000000..986d4309 --- /dev/null +++ b/include/darknet.h @@ -0,0 +1,538 @@ +#ifndef DARKNET_API +#define DARKNET_API +#include + +extern int gpu_index; + +#ifdef GPU + #define BLOCK 512 + + #include "cuda_runtime.h" + #include "curand.h" + #include "cublas_v2.h" + + #ifdef CUDNN + #include "cudnn.h" + #endif +#endif + +#ifndef __cplusplus + #ifdef OPENCV + #include "opencv2/highgui/highgui_c.h" + #include "opencv2/imgproc/imgproc_c.h" + #include "opencv2/core/version.hpp" + #if CV_MAJOR_VERSION == 3 + #include "opencv2/videoio/videoio_c.h" + #endif + #endif +#endif + +typedef struct{ + int *leaf; + int n; + int *parent; + int *child; + int *group; + char **name; + + int groups; + int *group_size; + int *group_offset; +} tree; + +typedef enum{ + LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN +}ACTIVATION; + +typedef enum { + CONVOLUTIONAL, + DECONVOLUTIONAL, + CONNECTED, + MAXPOOL, + SOFTMAX, + DETECTION, + DROPOUT, + CROP, + ROUTE, + COST, + NORMALIZATION, + AVGPOOL, + LOCAL, + SHORTCUT, + ACTIVE, + RNN, + GRU, + CRNN, + BATCHNORM, + NETWORK, + XNOR, + REGION, + REORG, + BLANK +} LAYER_TYPE; + +typedef enum{ + SSE, MASKED, L1, SMOOTH +} COST_TYPE; + +struct network; +typedef struct network network; + +struct layer; +typedef struct layer layer; + +struct 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, int, float, float, float); + void (*forward_gpu) (struct layer, struct network); + void (*backward_gpu) (struct layer, struct network); + void (*update_gpu) (struct layer, int, float, float, float); + int batch_normalize; + int shortcut; + int batch; + int forced; + int flipped; + int inputs; + int outputs; + int nweights; + int nbiases; + int extra; + int truths; + int h,w,c; + int out_h, out_w, out_c; + int n; + int max_boxes; + int groups; + int size; + int side; + int stride; + int reverse; + int flatten; + int spatial; + int pad; + int sqrt; + int flip; + int index; + int binary; + int xnor; + int steps; + int hidden; + int truth; + float smooth; + float dot; + float angle; + float jitter; + float saturation; + float exposure; + float shift; + float ratio; + float learning_rate_scale; + int softmax; + int classes; + int coords; + int background; + int rescore; + int objectness; + int does_cost; + int joint; + int noadjust; + int reorg; + int log; + + int adam; + float B1; + float B2; + float eps; + int t; + + float alpha; + float beta; + float kappa; + + float coord_scale; + float object_scale; + float noobject_scale; + float class_scale; + int bias_match; + int random; + float thresh; + int classfix; + int absolute; + + int onlyforward; + int stopbackward; + int dontload; + int dontloadscales; + + float temperature; + float probability; + float scale; + + char * cweights; + int * indexes; + int * input_layers; + int * input_sizes; + int * map; + float * rand; + float * cost; + float * state; + float * prev_state; + float * forgot_state; + float * forgot_delta; + float * state_delta; + + float * concat; + float * concat_delta; + + float * binary_weights; + + float * biases; + float * bias_updates; + + float * scales; + float * scale_updates; + + float * weights; + float * weight_updates; + + float * delta; + float * output; + float * squared; + float * norms; + + float * spatial_mean; + float * mean; + float * variance; + + float * mean_delta; + float * variance_delta; + + float * rolling_mean; + float * rolling_variance; + + float * x; + float * x_norm; + + float * m; + float * v; + + float * bias_m; + float * bias_v; + float * scale_m; + float * scale_v; + + float * z_cpu; + float * r_cpu; + float * h_cpu; + + float * binary_input; + + struct layer *input_layer; + struct layer *self_layer; + struct layer *output_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 layer *input_z_layer; + struct layer *state_z_layer; + + struct layer *input_r_layer; + struct layer *state_r_layer; + + struct layer *input_h_layer; + struct layer *state_h_layer; + + tree *softmax_tree; + + size_t workspace_size; + + #ifdef GPU + int *indexes_gpu; + + float *z_gpu; + float *r_gpu; + float *h_gpu; + + float *m_gpu; + float *v_gpu; + float *bias_m_gpu; + float *scale_m_gpu; + float *bias_v_gpu; + float *scale_v_gpu; + + float * prev_state_gpu; + float * forgot_state_gpu; + float * forgot_delta_gpu; + float * state_gpu; + float * state_delta_gpu; + float * gate_gpu; + float * gate_delta_gpu; + float * save_gpu; + float * save_delta_gpu; + float * concat_gpu; + float * concat_delta_gpu; + + float *binary_input_gpu; + float *binary_weights_gpu; + + float * mean_gpu; + float * variance_gpu; + + float * rolling_mean_gpu; + float * rolling_variance_gpu; + + float * variance_delta_gpu; + float * mean_delta_gpu; + + float * x_gpu; + float * x_norm_gpu; + float * weights_gpu; + float * weight_updates_gpu; + + float * biases_gpu; + float * bias_updates_gpu; + + float * scales_gpu; + float * scale_updates_gpu; + + float * output_gpu; + float * delta_gpu; + float * rand_gpu; + float * squared_gpu; + float * norms_gpu; + #ifdef CUDNN + cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc; + cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc; + cudnnTensorDescriptor_t normTensorDesc; + cudnnFilterDescriptor_t weightDesc; + cudnnFilterDescriptor_t dweightDesc; + cudnnConvolutionDescriptor_t convDesc; + cudnnConvolutionFwdAlgo_t fw_algo; + cudnnConvolutionBwdDataAlgo_t bd_algo; + cudnnConvolutionBwdFilterAlgo_t bf_algo; + #endif + #endif +}; + +void free_layer(layer); + +typedef enum { + CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM +} learning_rate_policy; + +typedef struct network{ + int n; + int batch; + int *seen; + float epoch; + int subdivisions; + float momentum; + float decay; + layer *layers; + float *output; + learning_rate_policy policy; + + float learning_rate; + float gamma; + float scale; + float power; + int time_steps; + int step; + int max_batches; + float *scales; + int *steps; + int num_steps; + int burn_in; + + int adam; + float B1; + float B2; + float eps; + + int inputs; + int outputs; + int truths; + int notruth; + int h, w, c; + int max_crop; + int min_crop; + int center; + float angle; + float aspect; + float exposure; + float saturation; + float hue; + + int gpu_index; + tree *hierarchy; + + float *input; + float *truth; + float *delta; + float *workspace; + int train; + int index; + float *cost; + + #ifdef GPU + float *input_gpu; + float *truth_gpu; + float *delta_gpu; + float *output_gpu; + #endif + +} network; + +typedef struct { + int w; + int h; + float scale; + float rad; + float dx; + float dy; + float aspect; +} augment_args; + +typedef struct { + int h; + int w; + int c; + float *data; +} image; + +typedef struct{ + float x, y, w, h; +} box; + +typedef struct matrix{ + int rows, cols; + float **vals; +} matrix; + + +typedef struct{ + int w, h; + matrix X; + matrix y; + int shallow; + int *num_boxes; + box **boxes; +} data; + +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 +} data_type; + +typedef struct load_args{ + int threads; + char **paths; + char *path; + int n; + int m; + char **labels; + int h; + int w; + int out_w; + int out_h; + int nh; + int nw; + int num_boxes; + int min, max, size; + int classes; + int background; + int scale; + int center; + float jitter; + float angle; + float aspect; + float saturation; + float exposure; + float hue; + data *d; + image *im; + image *resized; + data_type type; + tree *hierarchy; +} load_args; + +typedef struct{ + int id; + float x,y,w,h; + float left, right, top, bottom; +} box_label; + + +network load_network(char *cfg, char *weights, int clear); +load_args get_base_args(network net); + +void free_data(data d); + +typedef struct node{ + void *val; + struct node *next; + struct node *prev; +} node; + +typedef struct list{ + int size; + node *front; + node *back; +} list; + +pthread_t load_data(load_args args); +list *read_data_cfg(char *filename); +list *read_cfg(char *filename); + + +#include "activation_layer.h" +#include "activations.h" +#include "avgpool_layer.h" +#include "batchnorm_layer.h" +#include "blas.h" +#include "box.h" +#include "classifier.h" +#include "col2im.h" +#include "connected_layer.h" +#include "convolutional_layer.h" +#include "cost_layer.h" +#include "crnn_layer.h" +#include "crop_layer.h" +#include "cuda.h" +#include "data.h" +#include "deconvolutional_layer.h" +#include "demo.h" +#include "detection_layer.h" +#include "dropout_layer.h" +#include "gemm.h" +#include "gru_layer.h" +#include "im2col.h" +#include "image.h" +#include "layer.h" +#include "list.h" +#include "local_layer.h" +#include "matrix.h" +#include "maxpool_layer.h" +#include "network.h" +#include "normalization_layer.h" +#include "option_list.h" +#include "parser.h" +#include "region_layer.h" +#include "reorg_layer.h" +#include "rnn_layer.h" +#include "route_layer.h" +#include "shortcut_layer.h" +#include "softmax_layer.h" +#include "stb_image.h" +#include "stb_image_write.h" +#include "tree.h" +#include "utils.h" +#endif diff --git a/src/activation_kernels.cu b/src/activation_kernels.cu index f7882990..994e2068 100644 --- a/src/activation_kernels.cu +++ b/src/activation_kernels.cu @@ -3,8 +3,8 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/activations.h" -#include "darknet/cuda.h" +#include "activations.h" +#include "cuda.h" } diff --git a/src/activation_layer.c b/src/activation_layer.c index 00596f8c..de4e4b7d 100644 --- a/src/activation_layer.c +++ b/src/activation_layer.c @@ -1,8 +1,8 @@ -#include "darknet/activation_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "activation_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/activations.c b/src/activations.c index 38a89f2d..0cbb2f55 100644 --- a/src/activations.c +++ b/src/activations.c @@ -1,4 +1,4 @@ -#include "darknet/activations.h" +#include "activations.h" #include #include diff --git a/src/activations.h b/src/activations.h index 1c36ff52..54ab3c22 100644 --- a/src/activations.h +++ b/src/activations.h @@ -1,12 +1,9 @@ #ifndef ACTIVATIONS_H #define ACTIVATIONS_H +#include "darknet.h" #include "cuda.h" #include "math.h" -typedef enum{ - LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN -}ACTIVATION; - ACTIVATION get_activation(char *s); char *get_activation_string(ACTIVATION a); diff --git a/src/avgpool_layer.c b/src/avgpool_layer.c index e7158e80..83034dbe 100644 --- a/src/avgpool_layer.c +++ b/src/avgpool_layer.c @@ -1,5 +1,5 @@ -#include "darknet/avgpool_layer.h" -#include "darknet/cuda.h" +#include "avgpool_layer.h" +#include "cuda.h" #include avgpool_layer make_avgpool_layer(int batch, int w, int h, int c) diff --git a/src/avgpool_layer_kernels.cu b/src/avgpool_layer_kernels.cu index d8f70adc..a7eca3ae 100644 --- a/src/avgpool_layer_kernels.cu +++ b/src/avgpool_layer_kernels.cu @@ -3,8 +3,8 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/avgpool_layer.h" -#include "darknet/cuda.h" +#include "avgpool_layer.h" +#include "cuda.h" } __global__ void forward_avgpool_layer_kernel(int n, int w, int h, int c, float *input, float *output) diff --git a/src/batchnorm_layer.c b/src/batchnorm_layer.c index da8ac2fe..4862531d 100644 --- a/src/batchnorm_layer.c +++ b/src/batchnorm_layer.c @@ -1,6 +1,6 @@ -#include "darknet/convolutional_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/blas.h" +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "blas.h" #include layer make_batchnorm_layer(int batch, int w, int h, int c) diff --git a/src/blas.c b/src/blas.c index 751c9d7a..668b12c3 100644 --- a/src/blas.c +++ b/src/blas.c @@ -1,4 +1,4 @@ -#include "darknet/blas.h" +#include "blas.h" #include #include diff --git a/src/blas.h b/src/blas.h index a61b7d8c..49ff0875 100644 --- a/src/blas.h +++ b/src/blas.h @@ -18,7 +18,7 @@ void copy_cpu(int N, float *X, int INCX, float *Y, int INCY); void scal_cpu(int N, float ALPHA, float *X, int INCX); void fill_cpu(int N, float ALPHA, float * X, int INCX); float dot_cpu(int N, float *X, int INCX, float *Y, int INCY); -void test_gpu_blas(); +int test_gpu_blas(); void shortcut_cpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float *out); void mean_cpu(float *x, int batch, int filters, int spatial, float *mean); diff --git a/src/blas_kernels.cu b/src/blas_kernels.cu index b54603c9..9f1337ca 100644 --- a/src/blas_kernels.cu +++ b/src/blas_kernels.cu @@ -4,9 +4,9 @@ #include extern "C" { -#include "darknet/blas.h" -#include "darknet/cuda.h" -#include "darknet/utils.h" +#include "blas.h" +#include "cuda.h" +#include "utils.h" } __global__ void scale_bias_kernel(float *output, float *biases, int n, int size) diff --git a/src/box.c b/src/box.c index dbf432ee..88ca71ac 100644 --- a/src/box.c +++ b/src/box.c @@ -1,4 +1,4 @@ -#include "darknet/box.h" +#include "box.h" #include #include #include diff --git a/src/box.h b/src/box.h index 49585ed4..59b38a58 100644 --- a/src/box.h +++ b/src/box.h @@ -1,9 +1,6 @@ #ifndef BOX_H #define BOX_H - -typedef struct{ - float x, y, w, h; -} box; +#include "darknet.h" typedef struct{ float dx, dy, dw, dh; diff --git a/src/classifier.h b/src/classifier.h index 3c89f49c..8b137891 100644 --- a/src/classifier.h +++ b/src/classifier.h @@ -1,2 +1 @@ -list *read_data_cfg(char *filename); diff --git a/src/col2im_kernels.cu b/src/col2im_kernels.cu index d8a5e371..aed2df9b 100644 --- a/src/col2im_kernels.cu +++ b/src/col2im_kernels.cu @@ -3,8 +3,8 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/col2im.h" -#include "darknet/cuda.h" +#include "col2im.h" +#include "cuda.h" } // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu diff --git a/src/compare.c b/src/compare.c index f773bfbb..4fd266c7 100644 --- a/src/compare.c +++ b/src/compare.c @@ -1,11 +1,11 @@ #include -#include "darknet/network.h" -#include "darknet/detection_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" +#include "network.h" +#include "detection_layer.h" +#include "cost_layer.h" +#include "utils.h" +#include "parser.h" +#include "box.h" void train_compare(char *cfgfile, char *weightfile) { diff --git a/src/connected_layer.c b/src/connected_layer.c index 4300dbdc..f8c74235 100644 --- a/src/connected_layer.c +++ b/src/connected_layer.c @@ -1,9 +1,9 @@ -#include "darknet/connected_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "connected_layer.h" +#include "batchnorm_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/convolutional_kernels.cu b/src/convolutional_kernels.cu index 4146a3e5..b53dd16a 100644 --- a/src/convolutional_kernels.cu +++ b/src/convolutional_kernels.cu @@ -3,14 +3,14 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/convolutional_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/gemm.h" -#include "darknet/blas.h" -#include "darknet/im2col.h" -#include "darknet/col2im.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "gemm.h" +#include "blas.h" +#include "im2col.h" +#include "col2im.h" +#include "utils.h" +#include "cuda.h" } __global__ void binarize_kernel(float *x, int n, float *binary) diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c index 0dbc7b74..e5b5bb6f 100644 --- a/src/convolutional_layer.c +++ b/src/convolutional_layer.c @@ -1,10 +1,10 @@ -#include "darknet/convolutional_layer.h" -#include "darknet/utils.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/im2col.h" -#include "darknet/col2im.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "convolutional_layer.h" +#include "utils.h" +#include "batchnorm_layer.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/cost_layer.c b/src/cost_layer.c index 251ec5a9..76c001f0 100644 --- a/src/cost_layer.c +++ b/src/cost_layer.c @@ -1,7 +1,7 @@ -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" +#include "cost_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" #include #include #include diff --git a/src/crnn_layer.c b/src/crnn_layer.c index a8b040dd..2478fef5 100644 --- a/src/crnn_layer.c +++ b/src/crnn_layer.c @@ -1,9 +1,9 @@ -#include "darknet/crnn_layer.h" -#include "darknet/convolutional_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "crnn_layer.h" +#include "convolutional_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/crop_layer.c b/src/crop_layer.c index afac7ee0..3b918529 100644 --- a/src/crop_layer.c +++ b/src/crop_layer.c @@ -1,5 +1,5 @@ -#include "darknet/crop_layer.h" -#include "darknet/cuda.h" +#include "crop_layer.h" +#include "cuda.h" #include image get_crop_image(crop_layer l) diff --git a/src/crop_layer_kernels.cu b/src/crop_layer_kernels.cu index 41f6f456..b6568219 100644 --- a/src/crop_layer_kernels.cu +++ b/src/crop_layer_kernels.cu @@ -3,10 +3,10 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/crop_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/image.h" +#include "crop_layer.h" +#include "utils.h" +#include "cuda.h" +#include "image.h" } __device__ float get_pixel_kernel(float *image, int w, int h, int x, int y, int c) diff --git a/src/cuda.c b/src/cuda.c index 085a5764..e011b89d 100644 --- a/src/cuda.c +++ b/src/cuda.c @@ -2,9 +2,9 @@ int gpu_index = 0; #ifdef GPU -#include "darknet/cuda.h" -#include "darknet/utils.h" -#include "darknet/blas.h" +#include "cuda.h" +#include "utils.h" +#include "blas.h" #include #include #include diff --git a/src/cuda.h b/src/cuda.h index 52794fa4..cdaba208 100644 --- a/src/cuda.h +++ b/src/cuda.h @@ -1,20 +1,10 @@ #ifndef CUDA_H #define CUDA_H -extern int gpu_index; +#include "darknet.h" #ifdef GPU -#define BLOCK 512 - -#include "cuda_runtime.h" -#include "curand.h" -#include "cublas_v2.h" - -#ifdef CUDNN -#include "cudnn.h" -#endif - void check_error(cudaError_t status); cublasHandle_t blas_handle(); float *cuda_make_array(float *x, size_t n); diff --git a/src/data.c b/src/data.c index 1ea115a3..dcc5089b 100644 --- a/src/data.c +++ b/src/data.c @@ -1,7 +1,7 @@ -#include "darknet/data.h" -#include "darknet/utils.h" -#include "darknet/image.h" -#include "darknet/cuda.h" +#include "data.h" +#include "utils.h" +#include "image.h" +#include "cuda.h" #include #include diff --git a/src/data.h b/src/data.h index c366d66e..8f18d9f6 100644 --- a/src/data.h +++ b/src/data.h @@ -2,6 +2,7 @@ #define DATA_H #include +#include "darknet.h" #include "matrix.h" #include "list.h" #include "image.h" @@ -17,61 +18,6 @@ static inline float distance_from_edge(int x, int max) if (dist > 1) dist = 1; return dist; } - -typedef struct{ - int w, h; - matrix X; - matrix y; - int shallow; - int *num_boxes; - box **boxes; -} data; - -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 -} data_type; - -typedef struct load_args{ - int threads; - char **paths; - char *path; - int n; - int m; - char **labels; - int h; - int w; - int out_w; - int out_h; - int nh; - int nw; - int num_boxes; - int min, max, size; - int classes; - int background; - int scale; - int center; - float jitter; - float angle; - float aspect; - float saturation; - float exposure; - float hue; - data *d; - image *im; - image *resized; - data_type type; - tree *hierarchy; -} load_args; - -typedef struct{ - int id; - float x,y,w,h; - float left, right, top, bottom; -} box_label; - -void free_data(data d); - -pthread_t load_data(load_args args); void load_data_blocking(load_args args); pthread_t load_data_in_thread(load_args args); diff --git a/src/deconvolutional_kernels.cu b/src/deconvolutional_kernels.cu index 1d4bc7c9..16694634 100644 --- a/src/deconvolutional_kernels.cu +++ b/src/deconvolutional_kernels.cu @@ -3,15 +3,15 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/convolutional_layer.h" -#include "darknet/deconvolutional_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/gemm.h" -#include "darknet/blas.h" -#include "darknet/im2col.h" -#include "darknet/col2im.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" +#include "convolutional_layer.h" +#include "deconvolutional_layer.h" +#include "batchnorm_layer.h" +#include "gemm.h" +#include "blas.h" +#include "im2col.h" +#include "col2im.h" +#include "utils.h" +#include "cuda.h" } extern "C" void forward_deconvolutional_layer_gpu(layer l, network net) diff --git a/src/deconvolutional_layer.c b/src/deconvolutional_layer.c index 3ceff782..3778b418 100644 --- a/src/deconvolutional_layer.c +++ b/src/deconvolutional_layer.c @@ -1,11 +1,11 @@ -#include "darknet/deconvolutional_layer.h" -#include "darknet/convolutional_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/utils.h" -#include "darknet/im2col.h" -#include "darknet/col2im.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "deconvolutional_layer.h" +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "utils.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/demo.c b/src/demo.c index cf22273b..9dc4946a 100644 --- a/src/demo.c +++ b/src/demo.c @@ -1,12 +1,12 @@ -#include "darknet/network.h" -#include "darknet/detection_layer.h" -#include "darknet/region_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/utils.h" -#include "darknet/parser.h" -#include "darknet/box.h" -#include "darknet/image.h" -#include "darknet/demo.h" +#include "network.h" +#include "detection_layer.h" +#include "region_layer.h" +#include "cost_layer.h" +#include "utils.h" +#include "parser.h" +#include "box.h" +#include "image.h" +#include "demo.h" #include #define DEMO 1 @@ -31,7 +31,7 @@ static float demo_hier = .5; static int running = 0; static int demo_delay = 0; -static int demo_frame = 5; +static int demo_frame = 3; static int demo_detections = 0; static float **predictions; static int demo_index = 0; diff --git a/src/detection_layer.c b/src/detection_layer.c index 721d64c2..100694ba 100644 --- a/src/detection_layer.c +++ b/src/detection_layer.c @@ -1,10 +1,10 @@ -#include "darknet/detection_layer.h" -#include "darknet/activations.h" -#include "darknet/softmax_layer.h" -#include "darknet/blas.h" -#include "darknet/box.h" -#include "darknet/cuda.h" -#include "darknet/utils.h" +#include "detection_layer.h" +#include "activations.h" +#include "softmax_layer.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" #include #include diff --git a/src/dropout_layer.c b/src/dropout_layer.c index 1e344f45..780554fb 100644 --- a/src/dropout_layer.c +++ b/src/dropout_layer.c @@ -1,6 +1,6 @@ -#include "darknet/dropout_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" +#include "dropout_layer.h" +#include "utils.h" +#include "cuda.h" #include #include diff --git a/src/dropout_layer_kernels.cu b/src/dropout_layer_kernels.cu index 862e6f45..bd12b678 100644 --- a/src/dropout_layer_kernels.cu +++ b/src/dropout_layer_kernels.cu @@ -3,9 +3,9 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/dropout_layer.h" -#include "darknet/cuda.h" -#include "darknet/utils.h" +#include "dropout_layer.h" +#include "cuda.h" +#include "utils.h" } __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale) diff --git a/src/gemm.c b/src/gemm.c index 245ae641..3003be0e 100644 --- a/src/gemm.c +++ b/src/gemm.c @@ -1,6 +1,6 @@ -#include "darknet/gemm.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" +#include "gemm.h" +#include "utils.h" +#include "cuda.h" #include #include #include diff --git a/src/gru_layer.c b/src/gru_layer.c index 68ffed34..7139f798 100644 --- a/src/gru_layer.c +++ b/src/gru_layer.c @@ -1,9 +1,9 @@ -#include "darknet/gru_layer.h" -#include "darknet/connected_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "gru_layer.h" +#include "connected_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/im2col.c b/src/im2col.c index 67c078bc..69ec98a9 100644 --- a/src/im2col.c +++ b/src/im2col.c @@ -1,4 +1,4 @@ -#include "darknet/im2col.h" +#include "im2col.h" #include float im2col_get_pixel(float *im, int height, int width, int channels, int row, int col, int channel, int pad) diff --git a/src/im2col_kernels.cu b/src/im2col_kernels.cu index 02f0e070..d42d600b 100644 --- a/src/im2col_kernels.cu +++ b/src/im2col_kernels.cu @@ -3,8 +3,8 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/im2col.h" -#include "darknet/cuda.h" +#include "im2col.h" +#include "cuda.h" } // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu diff --git a/src/image.c b/src/image.c index b9f629ca..1a8c984a 100644 --- a/src/image.c +++ b/src/image.c @@ -1,14 +1,14 @@ -#include "darknet/image.h" -#include "darknet/utils.h" -#include "darknet/blas.h" -#include "darknet/cuda.h" +#include "image.h" +#include "utils.h" +#include "blas.h" +#include "cuda.h" #include #include #define STB_IMAGE_IMPLEMENTATION -#include "darknet/stb_image.h" +#include "stb_image.h" #define STB_IMAGE_WRITE_IMPLEMENTATION -#include "darknet/stb_image_write.h" +#include "stb_image_write.h" int windows = 0; diff --git a/src/image.h b/src/image.h index 7201515c..8b516c14 100644 --- a/src/image.h +++ b/src/image.h @@ -7,34 +7,7 @@ #include #include #include "box.h" - -#ifndef __cplusplus -#ifdef OPENCV -#include "opencv2/highgui/highgui_c.h" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/version.hpp" -#if CV_MAJOR_VERSION == 3 -#include "opencv2/videoio/videoio_c.h" -#endif -#endif -#endif - -typedef struct { - int w; - int h; - float scale; - float rad; - float dx; - float dy; - float aspect; -} augment_args; - -typedef struct { - int h; - int w; - int c; - float *data; -} image; +#include "darknet.h" #ifndef __cplusplus #ifdef OPENCV diff --git a/src/layer.c b/src/layer.c index bfa56e78..c27b4776 100644 --- a/src/layer.c +++ b/src/layer.c @@ -1,5 +1,5 @@ -#include "darknet/layer.h" -#include "darknet/cuda.h" +#include "layer.h" +#include "cuda.h" #include diff --git a/src/layer.h b/src/layer.h index 620d3674..af6cd2ab 100644 --- a/src/layer.h +++ b/src/layer.h @@ -1,289 +1 @@ -#ifndef BASE_LAYER_H -#define BASE_LAYER_H - -#include "activations.h" -#include "stddef.h" -#include "tree.h" - -struct network; -typedef struct network network; - -struct layer; -typedef struct layer layer; - -typedef enum { - CONVOLUTIONAL, - DECONVOLUTIONAL, - CONNECTED, - MAXPOOL, - SOFTMAX, - DETECTION, - DROPOUT, - CROP, - ROUTE, - COST, - NORMALIZATION, - AVGPOOL, - LOCAL, - SHORTCUT, - ACTIVE, - RNN, - GRU, - CRNN, - BATCHNORM, - NETWORK, - XNOR, - REGION, - REORG, - BLANK -} LAYER_TYPE; - -typedef enum{ - SSE, MASKED, L1, SMOOTH -} COST_TYPE; - -struct 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, int, float, float, float); - void (*forward_gpu) (struct layer, struct network); - void (*backward_gpu) (struct layer, struct network); - void (*update_gpu) (struct layer, int, float, float, float); - int batch_normalize; - int shortcut; - int batch; - int forced; - int flipped; - int inputs; - int outputs; - int nweights; - int nbiases; - int extra; - int truths; - int h,w,c; - int out_h, out_w, out_c; - int n; - int max_boxes; - int groups; - int size; - int side; - int stride; - int reverse; - int flatten; - int spatial; - int pad; - int sqrt; - int flip; - int index; - int binary; - int xnor; - int steps; - int hidden; - int truth; - float smooth; - float dot; - float angle; - float jitter; - float saturation; - float exposure; - float shift; - float ratio; - float learning_rate_scale; - int softmax; - int classes; - int coords; - int background; - int rescore; - int objectness; - int does_cost; - int joint; - int noadjust; - int reorg; - int log; - - int adam; - float B1; - float B2; - float eps; - int t; - - float alpha; - float beta; - float kappa; - - float coord_scale; - float object_scale; - float noobject_scale; - float class_scale; - int bias_match; - int random; - float thresh; - int classfix; - int absolute; - - int onlyforward; - int stopbackward; - int dontload; - int dontloadscales; - - float temperature; - float probability; - float scale; - - char * cweights; - int * indexes; - int * input_layers; - int * input_sizes; - int * map; - float * rand; - float * cost; - float * state; - float * prev_state; - float * forgot_state; - float * forgot_delta; - float * state_delta; - - float * concat; - float * concat_delta; - - float * binary_weights; - - float * biases; - float * bias_updates; - - float * scales; - float * scale_updates; - - float * weights; - float * weight_updates; - - float * delta; - float * output; - float * squared; - float * norms; - - float * spatial_mean; - float * mean; - float * variance; - - float * mean_delta; - float * variance_delta; - - float * rolling_mean; - float * rolling_variance; - - float * x; - float * x_norm; - - float * m; - float * v; - - float * bias_m; - float * bias_v; - float * scale_m; - float * scale_v; - - float * z_cpu; - float * r_cpu; - float * h_cpu; - - float * binary_input; - - struct layer *input_layer; - struct layer *self_layer; - struct layer *output_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 layer *input_z_layer; - struct layer *state_z_layer; - - struct layer *input_r_layer; - struct layer *state_r_layer; - - struct layer *input_h_layer; - struct layer *state_h_layer; - - tree *softmax_tree; - - size_t workspace_size; - - #ifdef GPU - int *indexes_gpu; - - float *z_gpu; - float *r_gpu; - float *h_gpu; - - float *m_gpu; - float *v_gpu; - float *bias_m_gpu; - float *scale_m_gpu; - float *bias_v_gpu; - float *scale_v_gpu; - - float * prev_state_gpu; - float * forgot_state_gpu; - float * forgot_delta_gpu; - float * state_gpu; - float * state_delta_gpu; - float * gate_gpu; - float * gate_delta_gpu; - float * save_gpu; - float * save_delta_gpu; - float * concat_gpu; - float * concat_delta_gpu; - - float *binary_input_gpu; - float *binary_weights_gpu; - - float * mean_gpu; - float * variance_gpu; - - float * rolling_mean_gpu; - float * rolling_variance_gpu; - - float * variance_delta_gpu; - float * mean_delta_gpu; - - float * x_gpu; - float * x_norm_gpu; - float * weights_gpu; - float * weight_updates_gpu; - - float * biases_gpu; - float * bias_updates_gpu; - - float * scales_gpu; - float * scale_updates_gpu; - - float * output_gpu; - float * delta_gpu; - float * rand_gpu; - float * squared_gpu; - float * norms_gpu; - #ifdef CUDNN - cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc; - cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc; - cudnnTensorDescriptor_t normTensorDesc; - cudnnFilterDescriptor_t weightDesc; - cudnnFilterDescriptor_t dweightDesc; - cudnnConvolutionDescriptor_t convDesc; - cudnnConvolutionFwdAlgo_t fw_algo; - cudnnConvolutionBwdDataAlgo_t bd_algo; - cudnnConvolutionBwdFilterAlgo_t bf_algo; - #endif - #endif -}; - -void free_layer(layer); - -#endif +#include "darknet.h" diff --git a/src/list.c b/src/list.c index 2be48d71..0e4165d3 100644 --- a/src/list.c +++ b/src/list.c @@ -1,6 +1,6 @@ #include #include -#include "darknet/list.h" +#include "list.h" list *make_list() { diff --git a/src/list.h b/src/list.h index fb818c2a..214b2805 100644 --- a/src/list.h +++ b/src/list.h @@ -1,17 +1,6 @@ #ifndef LIST_H #define LIST_H - -typedef struct node{ - void *val; - struct node *next; - struct node *prev; -} node; - -typedef struct list{ - int size; - node *front; - node *back; -} list; +#include "darknet.h" list *make_list(); int list_find(list *l, void *val); diff --git a/src/local_layer.c b/src/local_layer.c index 4fa934c5..aad036e0 100644 --- a/src/local_layer.c +++ b/src/local_layer.c @@ -1,9 +1,9 @@ -#include "darknet/local_layer.h" -#include "darknet/utils.h" -#include "darknet/im2col.h" -#include "darknet/col2im.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "local_layer.h" +#include "utils.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/matrix.c b/src/matrix.c index 6a0c4fd4..799916bf 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -1,6 +1,6 @@ -#include "darknet/matrix.h" -#include "darknet/utils.h" -#include "darknet/blas.h" +#include "matrix.h" +#include "utils.h" +#include "blas.h" #include #include #include diff --git a/src/matrix.h b/src/matrix.h index d6655eb4..14afcd75 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -1,9 +1,6 @@ #ifndef MATRIX_H #define MATRIX_H -typedef struct matrix{ - int rows, cols; - float **vals; -} matrix; +#include "darknet.h" matrix make_matrix(int rows, int cols); matrix copy_matrix(matrix m); diff --git a/src/maxpool_layer.c b/src/maxpool_layer.c index 520dda54..17dedf7a 100644 --- a/src/maxpool_layer.c +++ b/src/maxpool_layer.c @@ -1,5 +1,5 @@ -#include "darknet/maxpool_layer.h" -#include "darknet/cuda.h" +#include "maxpool_layer.h" +#include "cuda.h" #include image get_maxpool_image(maxpool_layer l) diff --git a/src/maxpool_layer_kernels.cu b/src/maxpool_layer_kernels.cu index 749c3880..3202e84b 100644 --- a/src/maxpool_layer_kernels.cu +++ b/src/maxpool_layer_kernels.cu @@ -3,8 +3,8 @@ #include "cublas_v2.h" extern "C" { -#include "darknet/maxpool_layer.h" -#include "darknet/cuda.h" +#include "maxpool_layer.h" +#include "cuda.h" } __global__ void forward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *input, float *output, int *indexes) diff --git a/src/network.c b/src/network.c index 7b753549..2b21338d 100644 --- a/src/network.c +++ b/src/network.c @@ -1,34 +1,34 @@ #include #include #include -#include "darknet/network.h" -#include "darknet/image.h" -#include "darknet/data.h" -#include "darknet/utils.h" -#include "darknet/blas.h" +#include "network.h" +#include "image.h" +#include "data.h" +#include "utils.h" +#include "blas.h" -#include "darknet/crop_layer.h" -#include "darknet/connected_layer.h" -#include "darknet/gru_layer.h" -#include "darknet/rnn_layer.h" -#include "darknet/crnn_layer.h" -#include "darknet/local_layer.h" -#include "darknet/convolutional_layer.h" -#include "darknet/activation_layer.h" -#include "darknet/detection_layer.h" -#include "darknet/region_layer.h" -#include "darknet/normalization_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/maxpool_layer.h" -#include "darknet/reorg_layer.h" -#include "darknet/avgpool_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/softmax_layer.h" -#include "darknet/dropout_layer.h" -#include "darknet/route_layer.h" -#include "darknet/shortcut_layer.h" -#include "darknet/parser.h" -#include "darknet/data.h" +#include "crop_layer.h" +#include "connected_layer.h" +#include "gru_layer.h" +#include "rnn_layer.h" +#include "crnn_layer.h" +#include "local_layer.h" +#include "convolutional_layer.h" +#include "activation_layer.h" +#include "detection_layer.h" +#include "region_layer.h" +#include "normalization_layer.h" +#include "batchnorm_layer.h" +#include "maxpool_layer.h" +#include "reorg_layer.h" +#include "avgpool_layer.h" +#include "cost_layer.h" +#include "softmax_layer.h" +#include "dropout_layer.h" +#include "route_layer.h" +#include "shortcut_layer.h" +#include "parser.h" +#include "data.h" load_args get_base_args(network net) { diff --git a/src/network.h b/src/network.h index 64d0b61c..15a644e5 100644 --- a/src/network.h +++ b/src/network.h @@ -1,81 +1,13 @@ // Oh boy, why am I about to do this.... #ifndef NETWORK_H #define NETWORK_H +#include "darknet.h" #include "image.h" #include "layer.h" #include "data.h" #include "tree.h" -typedef enum { - CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM -} learning_rate_policy; - -typedef struct network{ - int n; - int batch; - int *seen; - float epoch; - int subdivisions; - float momentum; - float decay; - layer *layers; - float *output; - learning_rate_policy policy; - - float learning_rate; - float gamma; - float scale; - float power; - int time_steps; - int step; - int max_batches; - float *scales; - int *steps; - int num_steps; - int burn_in; - - int adam; - float B1; - float B2; - float eps; - - int inputs; - int outputs; - int truths; - int notruth; - int h, w, c; - int max_crop; - int min_crop; - int center; - float angle; - float aspect; - float exposure; - float saturation; - float hue; - - int gpu_index; - tree *hierarchy; - - - - float *input; - float *truth; - float *delta; - float *workspace; - int train; - int index; - float *cost; - - #ifdef GPU - float *input_gpu; - float *truth_gpu; - float *delta_gpu; - float *output_gpu; - #endif - -} network; - #ifdef GPU float train_networks(network *nets, int n, data d, int interval); @@ -118,8 +50,6 @@ void print_network(network net); void visualize_network(network net); int resize_network(network *net, int w, int h); void set_batch_network(network *net, int b); -network load_network(char *cfg, char *weights, int clear); -load_args get_base_args(network net); void calc_network_cost(network net); #endif diff --git a/src/network_kernels.cu b/src/network_kernels.cu index 56ef50d7..2fbc2dd4 100644 --- a/src/network_kernels.cu +++ b/src/network_kernels.cu @@ -7,32 +7,32 @@ extern "C" { #include #include -#include "darknet/network.h" -#include "darknet/data.h" -#include "darknet/utils.h" -#include "darknet/parser.h" +#include "network.h" +#include "data.h" +#include "utils.h" +#include "parser.h" -#include "darknet/crop_layer.h" -#include "darknet/connected_layer.h" -#include "darknet/rnn_layer.h" -#include "darknet/gru_layer.h" -#include "darknet/crnn_layer.h" -#include "darknet/detection_layer.h" -#include "darknet/region_layer.h" -#include "darknet/convolutional_layer.h" -#include "darknet/activation_layer.h" -#include "darknet/maxpool_layer.h" -#include "darknet/reorg_layer.h" -#include "darknet/avgpool_layer.h" -#include "darknet/normalization_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/local_layer.h" -#include "darknet/softmax_layer.h" -#include "darknet/dropout_layer.h" -#include "darknet/route_layer.h" -#include "darknet/shortcut_layer.h" -#include "darknet/blas.h" +#include "crop_layer.h" +#include "connected_layer.h" +#include "rnn_layer.h" +#include "gru_layer.h" +#include "crnn_layer.h" +#include "detection_layer.h" +#include "region_layer.h" +#include "convolutional_layer.h" +#include "activation_layer.h" +#include "maxpool_layer.h" +#include "reorg_layer.h" +#include "avgpool_layer.h" +#include "normalization_layer.h" +#include "batchnorm_layer.h" +#include "cost_layer.h" +#include "local_layer.h" +#include "softmax_layer.h" +#include "dropout_layer.h" +#include "route_layer.h" +#include "shortcut_layer.h" +#include "blas.h" } void forward_network_gpu(network net) diff --git a/src/normalization_layer.c b/src/normalization_layer.c index ce62e26e..9f959a4f 100644 --- a/src/normalization_layer.c +++ b/src/normalization_layer.c @@ -1,5 +1,5 @@ -#include "darknet/normalization_layer.h" -#include "darknet/blas.h" +#include "normalization_layer.h" +#include "blas.h" #include diff --git a/src/option_list.c b/src/option_list.c index e3cae4d2..f935af30 100644 --- a/src/option_list.c +++ b/src/option_list.c @@ -1,8 +1,8 @@ #include #include #include -#include "darknet/option_list.h" -#include "darknet/utils.h" +#include "option_list.h" +#include "utils.h" list *read_data_cfg(char *filename) { diff --git a/src/option_list.h b/src/option_list.h index 054b3fdd..d0417aa9 100644 --- a/src/option_list.h +++ b/src/option_list.h @@ -9,7 +9,6 @@ typedef struct{ } kvp; -list *read_data_cfg(char *filename); int read_option(char *s, list *options); void option_insert(list *l, char *key, char *val); char *option_find(list *l, char *key); diff --git a/src/parser.c b/src/parser.c index 38b1ccce..b31e1cd0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3,33 +3,33 @@ #include #include -#include "darknet/activation_layer.h" -#include "darknet/activations.h" -#include "darknet/avgpool_layer.h" -#include "darknet/batchnorm_layer.h" -#include "darknet/blas.h" -#include "darknet/connected_layer.h" -#include "darknet/deconvolutional_layer.h" -#include "darknet/convolutional_layer.h" -#include "darknet/cost_layer.h" -#include "darknet/crnn_layer.h" -#include "darknet/crop_layer.h" -#include "darknet/detection_layer.h" -#include "darknet/dropout_layer.h" -#include "darknet/gru_layer.h" -#include "darknet/list.h" -#include "darknet/local_layer.h" -#include "darknet/maxpool_layer.h" -#include "darknet/normalization_layer.h" -#include "darknet/option_list.h" -#include "darknet/parser.h" -#include "darknet/region_layer.h" -#include "darknet/reorg_layer.h" -#include "darknet/rnn_layer.h" -#include "darknet/route_layer.h" -#include "darknet/shortcut_layer.h" -#include "darknet/softmax_layer.h" -#include "darknet/utils.h" +#include "activation_layer.h" +#include "activations.h" +#include "avgpool_layer.h" +#include "batchnorm_layer.h" +#include "blas.h" +#include "connected_layer.h" +#include "deconvolutional_layer.h" +#include "convolutional_layer.h" +#include "cost_layer.h" +#include "crnn_layer.h" +#include "crop_layer.h" +#include "detection_layer.h" +#include "dropout_layer.h" +#include "gru_layer.h" +#include "list.h" +#include "local_layer.h" +#include "maxpool_layer.h" +#include "normalization_layer.h" +#include "option_list.h" +#include "parser.h" +#include "region_layer.h" +#include "reorg_layer.h" +#include "rnn_layer.h" +#include "route_layer.h" +#include "shortcut_layer.h" +#include "softmax_layer.h" +#include "utils.h" typedef struct{ char *type; @@ -760,7 +760,7 @@ list *read_cfg(char *filename) if(file == 0) file_error(filename); char *line; int nu = 0; - list *sections = make_list(); + list *options = make_list(); section *current = 0; while((line=fgetl(file)) != 0){ ++ nu; @@ -768,7 +768,7 @@ list *read_cfg(char *filename) switch(line[0]){ case '[': current = malloc(sizeof(section)); - list_insert(sections, current); + list_insert(options, current); current->options = make_list(); current->type = line; break; @@ -786,7 +786,7 @@ list *read_cfg(char *filename) } } fclose(file); - return sections; + return options; } void save_convolutional_weights_binary(layer l, FILE *fp) diff --git a/src/region_layer.c b/src/region_layer.c index 49147e35..1f88bf77 100644 --- a/src/region_layer.c +++ b/src/region_layer.c @@ -1,9 +1,9 @@ -#include "darknet/region_layer.h" -#include "darknet/activations.h" -#include "darknet/blas.h" -#include "darknet/box.h" -#include "darknet/cuda.h" -#include "darknet/utils.h" +#include "region_layer.h" +#include "activations.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" #include #include @@ -448,15 +448,65 @@ void forward_region_layer_gpu(const layer l, network net) int index = entry_index(l, 0, 0, 5); softmax_tree(net.input_gpu + index, l.w*l.h, l.batch*l.n, l.inputs/l.n, 1, l.output_gpu + index, *l.softmax_tree); /* + // TIMING CODE + int zz; + int number = 1000; + int count = 0; int i; - int count = 5; for (i = 0; i < l.softmax_tree->groups; ++i) { int group_size = l.softmax_tree->group_size[i]; - int index = entry_index(l, 0, 0, count); - softmax_gpu(net.input_gpu + index, group_size, l.batch*l.n, l.inputs/l.n, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu + index); count += group_size; } + printf("%d %d\n", l.softmax_tree->groups, count); + { + double then = what_time_is_it_now(); + for(zz = 0; zz < number; ++zz){ + int index = entry_index(l, 0, 0, 5); + softmax_tree(net.input_gpu + index, l.w*l.h, l.batch*l.n, l.inputs/l.n, 1, l.output_gpu + index, *l.softmax_tree); + } + cudaDeviceSynchronize(); + printf("Good GPU Timing: %f\n", what_time_is_it_now() - then); + } + { + double then = what_time_is_it_now(); + for(zz = 0; zz < number; ++zz){ + int i; + int count = 5; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + int index = entry_index(l, 0, 0, count); + softmax_gpu(net.input_gpu + index, group_size, l.batch*l.n, l.inputs/l.n, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu + index); + count += group_size; + } + } + cudaDeviceSynchronize(); + printf("Bad GPU Timing: %f\n", what_time_is_it_now() - then); + } + { + double then = what_time_is_it_now(); + for(zz = 0; zz < number; ++zz){ + int i; + int count = 5; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + softmax_cpu(net.input + count, group_size, l.batch, l.inputs, l.n*l.w*l.h, 1, l.n*l.w*l.h, l.temperature, l.output + count); + count += group_size; + } + } + cudaDeviceSynchronize(); + printf("CPU Timing: %f\n", what_time_is_it_now() - then); + } */ + /* + int i; + int count = 5; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + int index = entry_index(l, 0, 0, count); + softmax_gpu(net.input_gpu + index, group_size, l.batch*l.n, l.inputs/l.n, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu + index); + count += group_size; + } + */ } else if (l.softmax) { int index = entry_index(l, 0, 0, l.coords + !l.background); //printf("%d\n", index); diff --git a/src/reorg_layer.c b/src/reorg_layer.c index d9f77154..d7fc0010 100644 --- a/src/reorg_layer.c +++ b/src/reorg_layer.c @@ -1,6 +1,6 @@ -#include "darknet/reorg_layer.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" +#include "reorg_layer.h" +#include "cuda.h" +#include "blas.h" #include diff --git a/src/rnn_layer.c b/src/rnn_layer.c index 998bbacf..fb4f1084 100644 --- a/src/rnn_layer.c +++ b/src/rnn_layer.c @@ -1,9 +1,9 @@ -#include "darknet/rnn_layer.h" -#include "darknet/connected_layer.h" -#include "darknet/utils.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" -#include "darknet/gemm.h" +#include "rnn_layer.h" +#include "connected_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" #include #include diff --git a/src/route_layer.c b/src/route_layer.c index 76f80f67..bce66fa4 100644 --- a/src/route_layer.c +++ b/src/route_layer.c @@ -1,6 +1,6 @@ -#include "darknet/route_layer.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" +#include "route_layer.h" +#include "cuda.h" +#include "blas.h" #include diff --git a/src/shortcut_layer.c b/src/shortcut_layer.c index bf60ddff..b39ba8e8 100644 --- a/src/shortcut_layer.c +++ b/src/shortcut_layer.c @@ -1,6 +1,7 @@ -#include "darknet/shortcut_layer.h" -#include "darknet/cuda.h" -#include "darknet/blas.h" +#include "shortcut_layer.h" +#include "cuda.h" +#include "blas.h" +#include "activations.h" #include #include diff --git a/src/softmax_layer.c b/src/softmax_layer.c index c0853f97..7f204802 100644 --- a/src/softmax_layer.c +++ b/src/softmax_layer.c @@ -1,6 +1,6 @@ -#include "darknet/softmax_layer.h" -#include "darknet/blas.h" -#include "darknet/cuda.h" +#include "softmax_layer.h" +#include "blas.h" +#include "cuda.h" #include #include diff --git a/src/tree.c b/src/tree.c index 89b5a8b4..f36ca3a1 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1,8 +1,8 @@ #include #include -#include "darknet/tree.h" -#include "darknet/utils.h" -#include "darknet/data.h" +#include "tree.h" +#include "utils.h" +#include "data.h" void change_leaves(tree *t, char *leaf_list) { diff --git a/src/tree.h b/src/tree.h index 2e9c8126..ec74057b 100644 --- a/src/tree.h +++ b/src/tree.h @@ -1,18 +1,6 @@ #ifndef TREE_H #define TREE_H - -typedef struct{ - int *leaf; - int n; - int *parent; - int *child; - int *group; - char **name; - - int groups; - int *group_size; - int *group_offset; -} tree; +#include "darknet.h" tree *read_tree(char *filename); void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves, int stride); diff --git a/src/utils.c b/src/utils.c index 822fd331..9c06e1a3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,8 +6,16 @@ #include #include #include +#include -#include "darknet/utils.h" +#include "utils.h" + +double what_time_is_it_now() +{ + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); + return now.tv_sec + now.tv_nsec*1e-9; +} int *read_intlist(char *gpu_list, int *ngpus, int d) { @@ -608,13 +616,13 @@ float rand_normal() size_t rand_size_t() { return ((size_t)(rand()&0xff) << 56) | - ((size_t)(rand()&0xff) << 48) | - ((size_t)(rand()&0xff) << 40) | - ((size_t)(rand()&0xff) << 32) | - ((size_t)(rand()&0xff) << 24) | - ((size_t)(rand()&0xff) << 16) | - ((size_t)(rand()&0xff) << 8) | - ((size_t)(rand()&0xff) << 0); + ((size_t)(rand()&0xff) << 48) | + ((size_t)(rand()&0xff) << 40) | + ((size_t)(rand()&0xff) << 32) | + ((size_t)(rand()&0xff) << 24) | + ((size_t)(rand()&0xff) << 16) | + ((size_t)(rand()&0xff) << 8) | + ((size_t)(rand()&0xff) << 0); } float rand_uniform(float min, float max) diff --git a/src/utils.h b/src/utils.h index ab4c6959..27206533 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,6 +7,7 @@ #define SECRET_NUM -1234 #define TWO_PI 6.2831853071795864769252866 +double what_time_is_it_now(); int *read_intlist(char *s, int *n, int d); int *read_map(char *filename); void shuffle(void *arr, size_t n, size_t size);