| | |
| | | GPU=0 |
| | | CUDNN=0 |
| | | OPENCV=0 |
| | | GPU=1 |
| | | CUDNN=1 |
| | | OPENCV=1 |
| | | DEBUG=0 |
| | | |
| | | ARCH= --gpu-architecture=compute_52 --gpu-code=compute_52 |
| | |
| | | LDFLAGS+= -lcudnn |
| | | endif |
| | | |
| | | OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o |
| | | OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o |
| | | ifeq ($(GPU), 1) |
| | | LDFLAGS+= -lstdc++ |
| | | OBJ+=convolutional_kernels.o deconvolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o softmax_layer_kernels.o network_kernels.o avgpool_layer_kernels.o |
| | |
| | | convert_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0); |
| | | if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms); |
| | | draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, coco_classes, coco_labels, 80); |
| | | save_image(im, "prediction"); |
| | | show_image(im, "predictions"); |
| | | |
| | | show_image(sized, "resized"); |
| | | free_image(im); |
| | | free_image(sized); |
| | | #ifdef OPENCV |
| | |
| | | l.weights[i*l.inputs + j] *= scale; |
| | | } |
| | | l.biases[i] -= l.rolling_mean[i] * scale; |
| | | l.scales[i] = 1; |
| | | l.rolling_mean[i] = 0; |
| | | l.rolling_variance[i] = 1; |
| | | } |
| | | } |
| | | |
| | |
| | | axpy_ongpu(l.outputs, 1, l.biases_gpu, 1, l.output_gpu + i*l.outputs, 1); |
| | | } |
| | | activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation); |
| | | |
| | | } |
| | | |
| | | void backward_connected_layer_gpu(connected_layer l, network_state state) |
| | |
| | | l.filters[i*l.c*l.size*l.size + j] *= scale; |
| | | } |
| | | l.biases[i] -= l.rolling_mean[i] * scale; |
| | | l.scales[i] = 1; |
| | | l.rolling_mean[i] = 0; |
| | | l.rolling_variance[i] = 1; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | */ |
| | | |
| | | if(l.xnor ){ |
| | | if(l.xnor){ |
| | | binarize_filters(l.filters, l.n, l.c*l.size*l.size, l.binary_filters); |
| | | swap_binary(&l); |
| | | binarize_cpu(state.input, l.c*l.h*l.w*l.batch, l.binary_input); |
| | |
| | | |
| | | extern void run_imagenet(int argc, char **argv); |
| | | extern void run_yolo(int argc, char **argv); |
| | | extern void run_detector(int argc, char **argv); |
| | | extern void run_coco(int argc, char **argv); |
| | | extern void run_writing(int argc, char **argv); |
| | | extern void run_captcha(int argc, char **argv); |
| | |
| | | for(i = 0; i < net.n; ++i){ |
| | | layer l = net.layers[i]; |
| | | if(l.type == CONVOLUTIONAL){ |
| | | ops += 2 * l.n * l.size*l.size*l.c * l.out_h*l.out_w; |
| | | ops += 2l * l.n * l.size*l.size*l.c * l.out_h*l.out_w; |
| | | } else if(l.type == CONNECTED){ |
| | | ops += 2 * l.inputs * l.outputs; |
| | | ops += 2l * l.inputs * l.outputs; |
| | | } |
| | | } |
| | | printf("Floating Point Operations: %ld\n", ops); |
| | | printf("Floating Point Operations: %.2f Bn\n", (float)ops/1000000000.); |
| | | } |
| | | |
| | | void partial(char *cfgfile, char *weightfile, char *outfile, int max) |
| | |
| | | save_weights(net, outfile); |
| | | } |
| | | |
| | | void reset_normalize_net(char *cfgfile, char *weightfile, char *outfile) |
| | | { |
| | | gpu_index = -1; |
| | | network net = parse_network_cfg(cfgfile); |
| | | if (weightfile) { |
| | | load_weights(&net, weightfile); |
| | | } |
| | | int i; |
| | | for (i = 0; i < net.n; ++i) { |
| | | layer l = net.layers[i]; |
| | | if (l.type == CONVOLUTIONAL && l.batch_normalize) { |
| | | denormalize_convolutional_layer(l); |
| | | } |
| | | if (l.type == CONNECTED && l.batch_normalize) { |
| | | denormalize_connected_layer(l); |
| | | } |
| | | if (l.type == GRU && l.batch_normalize) { |
| | | denormalize_connected_layer(*l.input_z_layer); |
| | | denormalize_connected_layer(*l.input_r_layer); |
| | | denormalize_connected_layer(*l.input_h_layer); |
| | | denormalize_connected_layer(*l.state_z_layer); |
| | | denormalize_connected_layer(*l.state_r_layer); |
| | | denormalize_connected_layer(*l.state_h_layer); |
| | | } |
| | | } |
| | | save_weights(net, outfile); |
| | | } |
| | | |
| | | layer normalize_layer(layer l, int n) |
| | | { |
| | | int j; |
| | | l.batch_normalize=1; |
| | | l.scales = calloc(n, sizeof(float)); |
| | | for(j = 0; j < n; ++j){ |
| | | l.scales[j] = 1; |
| | | } |
| | | l.rolling_mean = calloc(n, sizeof(float)); |
| | | l.rolling_variance = calloc(n, sizeof(float)); |
| | | return l; |
| | | } |
| | | |
| | | void normalize_net(char *cfgfile, char *weightfile, char *outfile) |
| | | { |
| | | gpu_index = -1; |
| | |
| | | if(weightfile){ |
| | | load_weights(&net, weightfile); |
| | | } |
| | | int i, j; |
| | | int i; |
| | | for(i = 0; i < net.n; ++i){ |
| | | layer l = net.layers[i]; |
| | | if(l.type == CONVOLUTIONAL){ |
| | | if(l.type == CONVOLUTIONAL && !l.batch_normalize){ |
| | | net.layers[i] = normalize_layer(l, l.n); |
| | | } |
| | | if (l.type == CONNECTED && !l.batch_normalize) { |
| | | net.layers[i] = normalize_layer(l, l.outputs); |
| | | } |
| | | if (l.type == GRU && l.batch_normalize) { |
| | | *l.input_z_layer = normalize_layer(*l.input_z_layer, l.input_z_layer->outputs); |
| | | *l.input_r_layer = normalize_layer(*l.input_r_layer, l.input_r_layer->outputs); |
| | | *l.input_h_layer = normalize_layer(*l.input_h_layer, l.input_h_layer->outputs); |
| | | *l.state_z_layer = normalize_layer(*l.state_z_layer, l.state_z_layer->outputs); |
| | | *l.state_r_layer = normalize_layer(*l.state_r_layer, l.state_r_layer->outputs); |
| | | *l.state_h_layer = normalize_layer(*l.state_h_layer, l.state_h_layer->outputs); |
| | | net.layers[i].batch_normalize=1; |
| | | net.layers[i].scales = calloc(l.n, sizeof(float)); |
| | | for(j = 0; j < l.n; ++j){ |
| | | net.layers[i].scales[i] = 1; |
| | | } |
| | | net.layers[i].rolling_mean = calloc(l.n, sizeof(float)); |
| | | net.layers[i].rolling_variance = calloc(l.n, sizeof(float)); |
| | | } |
| | | } |
| | | save_weights(net, outfile); |
| | |
| | | average(argc, argv); |
| | | } else if (0 == strcmp(argv[1], "yolo")){ |
| | | run_yolo(argc, argv); |
| | | } else if (0 == strcmp(argv[1], "detector")){ |
| | | run_detector(argc, argv); |
| | | } else if (0 == strcmp(argv[1], "cifar")){ |
| | | run_cifar(argc, argv); |
| | | } else if (0 == strcmp(argv[1], "go")){ |
| | |
| | | change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0); |
| | | } else if (0 == strcmp(argv[1], "rgbgr")){ |
| | | rgbgr_net(argv[2], argv[3], argv[4]); |
| | | } else if (0 == strcmp(argv[1], "reset")){ |
| | | reset_normalize_net(argv[2], argv[3], argv[4]); |
| | | } else if (0 == strcmp(argv[1], "denormalize")){ |
| | | denormalize_net(argv[2], argv[3], argv[4]); |
| | | } else if (0 == strcmp(argv[1], "normalize")){ |
| | |
| | | |
| | | if (w < .01 || h < .01) continue; |
| | | |
| | | truth[i*5+0] = id; |
| | | truth[i*5+1] = x; |
| | | truth[i*5+2] = y; |
| | | truth[i*5+3] = w; |
| | | truth[i*5+4] = h; |
| | | truth[i*5+0] = x; |
| | | truth[i*5+1] = y; |
| | | truth[i*5+2] = w; |
| | | truth[i*5+3] = h; |
| | | truth[i*5+4] = id; |
| | | } |
| | | free(boxes); |
| | | } |
| | |
| | | #include "demo.h" |
| | | #include <sys/time.h> |
| | | |
| | | #define FRAMES 3 |
| | | #define FRAMES 1 |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | |
| | | #ifndef REGION_LAYER_H |
| | | #define REGION_LAYER_H |
| | | #ifndef DETECTION_LAYER_H |
| | | #define DETECTION_LAYER_H |
| | | |
| | | #include "layer.h" |
| | | #include "network.h" |
| | |
| | | int class = max_index(probs[i], classes); |
| | | float prob = probs[i][class]; |
| | | if(prob > thresh){ |
| | | int width = pow(prob, 1./2.)*10+1; |
| | | width = 8; |
| | | //int width = pow(prob, 1./2.)*30+1; |
| | | int width = 8; |
| | | printf("%s: %.0f%%\n", names[class], prob*100); |
| | | int offset = class*1 % classes; |
| | | float red = get_color(2,offset,classes); |
| | | float green = get_color(1,offset,classes); |
| | | float blue = get_color(0,offset,classes); |
| | | float rgb[3]; |
| | | |
| | | //width = prob*20+2; |
| | | |
| | | rgb[0] = red; |
| | | rgb[1] = green; |
| | | rgb[2] = blue; |
| | |
| | | BATCHNORM, |
| | | NETWORK, |
| | | XNOR, |
| | | REGION, |
| | | BLANK |
| | | } LAYER_TYPE; |
| | | |
| | |
| | | #include "activation_layer.h" |
| | | #include "deconvolutional_layer.h" |
| | | #include "detection_layer.h" |
| | | #include "region_layer.h" |
| | | #include "normalization_layer.h" |
| | | #include "batchnorm_layer.h" |
| | | #include "maxpool_layer.h" |
| | |
| | | return "softmax"; |
| | | case DETECTION: |
| | | return "detection"; |
| | | case REGION: |
| | | return "region"; |
| | | case DROPOUT: |
| | | return "dropout"; |
| | | case CROP: |
| | |
| | | forward_batchnorm_layer(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | forward_detection_layer(l, state); |
| | | } else if(l.type == REGION){ |
| | | forward_region_layer(l, state); |
| | | } else if(l.type == CONNECTED){ |
| | | forward_connected_layer(l, state); |
| | | } else if(l.type == RNN){ |
| | |
| | | float sum = 0; |
| | | int count = 0; |
| | | for(i = 0; i < net.n; ++i){ |
| | | if(net.layers[i].type == COST){ |
| | | sum += net.layers[i].cost[0]; |
| | | ++count; |
| | | } |
| | | if(net.layers[i].type == DETECTION){ |
| | | if(net.layers[i].cost){ |
| | | sum += net.layers[i].cost[0]; |
| | | ++count; |
| | | } |
| | |
| | | backward_dropout_layer(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | backward_detection_layer(l, state); |
| | | } else if(l.type == REGION){ |
| | | backward_region_layer(l, state); |
| | | } else if(l.type == SOFTMAX){ |
| | | if(i != 0) backward_softmax_layer(l, state); |
| | | } else if(l.type == CONNECTED){ |
| | |
| | | #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 "deconvolutional_layer.h" |
| | |
| | | forward_local_layer_gpu(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | forward_detection_layer_gpu(l, state); |
| | | } else if(l.type == REGION){ |
| | | forward_region_layer_gpu(l, state); |
| | | } else if(l.type == CONNECTED){ |
| | | forward_connected_layer_gpu(l, state); |
| | | } else if(l.type == RNN){ |
| | |
| | | backward_dropout_layer_gpu(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | backward_detection_layer_gpu(l, state); |
| | | } else if(l.type == REGION){ |
| | | backward_region_layer_gpu(l, state); |
| | | } else if(l.type == NORMALIZATION){ |
| | | backward_normalization_layer_gpu(l, state); |
| | | } else if(l.type == BATCHNORM){ |
| | |
| | | state.net = net; |
| | | int x_size = get_network_input_size(net)*net.batch; |
| | | int y_size = get_network_output_size(net)*net.batch; |
| | | if(net.layers[net.n-1].type == DETECTION) y_size = net.layers[net.n-1].truths*net.batch; |
| | | if(net.layers[net.n-1].truths) y_size = net.layers[net.n-1].truths*net.batch; |
| | | if(!*net.input_gpu){ |
| | | *net.input_gpu = cuda_make_array(x, x_size); |
| | | *net.truth_gpu = cuda_make_array(y, y_size); |
| | |
| | | #include "softmax_layer.h" |
| | | #include "dropout_layer.h" |
| | | #include "detection_layer.h" |
| | | #include "region_layer.h" |
| | | #include "avgpool_layer.h" |
| | | #include "local_layer.h" |
| | | #include "route_layer.h" |
| | |
| | | int is_shortcut(section *s); |
| | | int is_cost(section *s); |
| | | int is_detection(section *s); |
| | | int is_region(section *s); |
| | | int is_route(section *s); |
| | | list *read_cfg(char *filename); |
| | | |
| | |
| | | return layer; |
| | | } |
| | | |
| | | layer parse_region(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); |
| | | assert(l.outputs == params.inputs); |
| | | |
| | | l.softmax = option_find_int(options, "softmax", 0); |
| | | l.max_boxes = option_find_int_quiet(options, "max",30); |
| | | l.jitter = option_find_float(options, "jitter", .2); |
| | | l.rescore = option_find_int_quiet(options, "rescore",0); |
| | | |
| | | l.coord_scale = option_find_float(options, "coord_scale", 1); |
| | | l.object_scale = option_find_float(options, "object_scale", 1); |
| | | l.noobject_scale = option_find_float(options, "noobject_scale", 1); |
| | | l.class_scale = option_find_float(options, "class_scale", 1); |
| | | return l; |
| | | } |
| | | detection_layer parse_detection(list *options, size_params params) |
| | | { |
| | | int coords = option_find_int(options, "coords", 1); |
| | |
| | | l = parse_crop(options, params); |
| | | }else if(is_cost(s)){ |
| | | l = parse_cost(options, params); |
| | | }else if(is_region(s)){ |
| | | l = parse_region(options, params); |
| | | }else if(is_detection(s)){ |
| | | l = parse_detection(options, params); |
| | | }else if(is_softmax(s)){ |
| | |
| | | if (strcmp(type, "[crop]")==0) return CROP; |
| | | if (strcmp(type, "[cost]")==0) return COST; |
| | | if (strcmp(type, "[detection]")==0) return DETECTION; |
| | | if (strcmp(type, "[region]")==0) return REGION; |
| | | if (strcmp(type, "[local]")==0) return LOCAL; |
| | | if (strcmp(type, "[deconv]")==0 |
| | | || strcmp(type, "[deconvolutional]")==0) return DECONVOLUTIONAL; |
| | |
| | | { |
| | | return (strcmp(s->type, "[cost]")==0); |
| | | } |
| | | int is_region(section *s) |
| | | { |
| | | return (strcmp(s->type, "[region]")==0); |
| | | } |
| | | int is_detection(section *s) |
| | | { |
| | | return (strcmp(s->type, "[detection]")==0); |