101 files modified
2 files added
2 files deleted
| | |
| | | GPU=0 |
| | | GPU=1 |
| | | OPENCV=1 |
| | | CUDNN=0 |
| | | DEBUG=0 |
| | |
| | | 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 coco_demo.o tag.o cifar.o yolo_demo.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 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 |
| | | 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 |
| | |
| | | [net] |
| | | batch=64 |
| | | subdivisions=4 |
| | | batch=1 |
| | | subdivisions=1 |
| | | height=448 |
| | | width=448 |
| | | channels=3 |
| | |
| | | [net] |
| | | batch=64 |
| | | subdivisions=64 |
| | | batch=1 |
| | | subdivisions=1 |
| | | height=448 |
| | | width=448 |
| | | channels=3 |
| | |
| | | scales=2.5,2,2,.1,.1 |
| | | max_batches = 40000 |
| | | |
| | | [crop] |
| | | crop_width=448 |
| | | crop_height=448 |
| | | flip=0 |
| | | angle=0 |
| | | saturation = 1.5 |
| | | exposure = 1.5 |
| | | |
| | | [convolutional] |
| | | filters=64 |
| | | size=7 |
| | |
| | | output=4096 |
| | | activation=leaky |
| | | |
| | | [dropout] |
| | | probability=.5 |
| | | |
| | | [connected] |
| | | output= 1470 |
| | | activation=linear |
| | |
| | | } |
| | | |
| | | |
| | | __device__ float lhtan_activate_kernel(float x) |
| | | { |
| | | if(x < 0) return .001*x; |
| | | if(x > 1) return .001*(x-1) + 1; |
| | | return x; |
| | | } |
| | | __device__ float lhtan_gradient_kernel(float x) |
| | | { |
| | | if(x > 0 && x < 1) return 1; |
| | | return .001; |
| | | } |
| | | |
| | | __device__ float hardtan_activate_kernel(float x) |
| | | { |
| | | if (x < -1) return -1; |
| | |
| | | return stair_activate_kernel(x); |
| | | case HARDTAN: |
| | | return hardtan_activate_kernel(x); |
| | | case LHTAN: |
| | | return lhtan_activate_kernel(x); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | return stair_gradient_kernel(x); |
| | | case HARDTAN: |
| | | return hardtan_gradient_kernel(x); |
| | | case LHTAN: |
| | | return lhtan_gradient_kernel(x); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | return "stair"; |
| | | case HARDTAN: |
| | | return "hardtan"; |
| | | case LHTAN: |
| | | return "lhtan"; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | if (strcmp(s, "relie")==0) return RELIE; |
| | | if (strcmp(s, "plse")==0) return PLSE; |
| | | if (strcmp(s, "hardtan")==0) return HARDTAN; |
| | | if (strcmp(s, "lhtan")==0) return LHTAN; |
| | | if (strcmp(s, "linear")==0) return LINEAR; |
| | | if (strcmp(s, "ramp")==0) return RAMP; |
| | | if (strcmp(s, "leaky")==0) return LEAKY; |
| | |
| | | return stair_activate(x); |
| | | case HARDTAN: |
| | | return hardtan_activate(x); |
| | | case LHTAN: |
| | | return lhtan_activate(x); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | return stair_gradient(x); |
| | | case HARDTAN: |
| | | return hardtan_gradient(x); |
| | | case LHTAN: |
| | | return lhtan_gradient(x); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | #include "math.h" |
| | | |
| | | typedef enum{ |
| | | LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN |
| | | LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN |
| | | }ACTIVATION; |
| | | |
| | | ACTIVATION get_activation(char *s); |
| | |
| | | return .125*x + .5; |
| | | } |
| | | |
| | | static inline float lhtan_activate(float x) |
| | | { |
| | | if(x < 0) return .001*x; |
| | | if(x > 1) return .001*(x-1) + 1; |
| | | return x; |
| | | } |
| | | static inline float lhtan_gradient(float x) |
| | | { |
| | | if(x > 0 && x < 1) return 1; |
| | | return .001; |
| | | } |
| | | |
| | | static inline float hardtan_gradient(float x) |
| | | { |
| | | if (x > -1 && x < 1) return 1; |
| | |
| | | #include "utils.h" |
| | | #include "parser.h" |
| | | #include "box.h" |
| | | #include "demo.h" |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | | #endif |
| | | |
| | | void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness); |
| | | |
| | | 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"}; |
| | | |
| | | 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}; |
| | |
| | | save_weights(net, buff); |
| | | } |
| | | |
| | | void convert_coco_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness) |
| | | { |
| | | int i,j,n; |
| | | //int per_cell = 5*num+classes; |
| | | for (i = 0; i < side*side; ++i){ |
| | | int row = i / side; |
| | | int col = i % side; |
| | | for(n = 0; n < num; ++n){ |
| | | int index = i*num + n; |
| | | int p_index = side*side*classes + i*num + n; |
| | | float scale = predictions[p_index]; |
| | | int box_index = side*side*(classes + num) + (i*num + n)*4; |
| | | boxes[index].x = (predictions[box_index + 0] + col) / side * w; |
| | | boxes[index].y = (predictions[box_index + 1] + row) / side * h; |
| | | boxes[index].w = pow(predictions[box_index + 2], (square?2:1)) * w; |
| | | boxes[index].h = pow(predictions[box_index + 3], (square?2:1)) * h; |
| | | for(j = 0; j < classes; ++j){ |
| | | int class_index = i*classes; |
| | | float prob = scale*predictions[class_index+j]; |
| | | probs[index][j] = (prob > thresh) ? prob : 0; |
| | | } |
| | | if(only_objectness){ |
| | | probs[index][0] = scale; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void print_cocos(FILE *fp, int image_id, box *boxes, float **probs, int num_boxes, int classes, int w, int h) |
| | | { |
| | | int i, j; |
| | |
| | | float *predictions = network_predict(net, X); |
| | | int w = val[t].w; |
| | | int h = val[t].h; |
| | | convert_coco_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0); |
| | | convert_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0); |
| | | if (nms) do_nms_sort(boxes, probs, side*side*l.n, classes, iou_thresh); |
| | | print_cocos(fp, image_id, boxes, probs, side*side*l.n, classes, w, h); |
| | | free_image(val[t]); |
| | |
| | | image sized = resize_image(orig, net.w, net.h); |
| | | char *id = basecfg(path); |
| | | float *predictions = network_predict(net, sized.data); |
| | | convert_coco_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1); |
| | | convert_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1); |
| | | if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms_thresh); |
| | | |
| | | char *labelpath = find_replace(path, "images", "labels"); |
| | |
| | | time=clock(); |
| | | float *predictions = network_predict(net, X); |
| | | printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); |
| | | convert_coco_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0); |
| | | 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); |
| | | show_image(im, "predictions"); |
| | |
| | | } |
| | | } |
| | | |
| | | void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename); |
| | | static void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, char* filename) |
| | | { |
| | | #if defined(OPENCV) |
| | | demo_coco(cfgfile, weightfile, thresh, cam_index, filename); |
| | | #else |
| | | fprintf(stderr, "Need to compile with OpenCV for demo.\n"); |
| | | #endif |
| | | } |
| | | |
| | | void run_coco(int argc, char **argv) |
| | | { |
| | | int i; |
| | |
| | | } |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .2); |
| | | int cam_index = find_int_arg(argc, argv, "-c", 0); |
| | | char *file = find_char_arg(argc, argv, "-file", 0); |
| | | |
| | | if(argc < 4){ |
| | | fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]); |
| | |
| | | else if(0==strcmp(argv[2], "train")) train_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, file); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, coco_labels, 80); |
| | | } |
| | |
| | | |
| | | void forward_convolutional_layer_gpu(convolutional_layer l, network_state state) |
| | | { |
| | | int i; |
| | | |
| | | fill_ongpu(l.outputs*l.batch, 0, l.output_gpu, 1); |
| | | if(l.binary){ |
| | | binarize_filters_gpu(l.filters_gpu, l.n, l.c*l.size*l.size, l.binary_filters_gpu); |
| | |
| | | l.output_gpu); |
| | | |
| | | #else |
| | | int i; |
| | | int m = l.n; |
| | | int k = l.size*l.size*l.c; |
| | | int n = l.out_w*l.out_h; |
| New file |
| | |
| | | #include "network.h" |
| | | #include "detection_layer.h" |
| | | #include "cost_layer.h" |
| | | #include "utils.h" |
| | | #include "parser.h" |
| | | #include "box.h" |
| | | #include "image.h" |
| | | #include "demo.h" |
| | | #include <sys/time.h> |
| | | |
| | | #define FRAMES 3 |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | | #include "opencv2/imgproc/imgproc_c.h" |
| | | void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness); |
| | | |
| | | #define DELAY 0 |
| | | static int delay = DELAY; |
| | | |
| | | static char **demo_names; |
| | | static image *demo_labels; |
| | | static int demo_classes; |
| | | |
| | | static float **probs; |
| | | static box *boxes; |
| | | static network net; |
| | | static image in ; |
| | | static image in_s ; |
| | | static image det ; |
| | | static image det_s; |
| | | static image disp = {0}; |
| | | static CvCapture * cap; |
| | | static float fps = 0; |
| | | static float demo_thresh = 0; |
| | | |
| | | static float *predictions[FRAMES]; |
| | | static int demo_index = 0; |
| | | static image images[FRAMES]; |
| | | static float *avg; |
| | | |
| | | void *fetch_in_thread(void *ptr) |
| | | { |
| | | in = get_image_from_stream(cap); |
| | | if(!in.data){ |
| | | in = disp; |
| | | if(delay == DELAY) error("Stream closed."); |
| | | }else{ |
| | | if(disp.data){ |
| | | free_image(disp); |
| | | } |
| | | in_s = resize_image(in, net.w, net.h); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | void *detect_in_thread(void *ptr) |
| | | { |
| | | float nms = .4; |
| | | |
| | | detection_layer l = net.layers[net.n-1]; |
| | | float *X = det_s.data; |
| | | float *prediction = network_predict(net, X); |
| | | |
| | | memcpy(predictions[demo_index], prediction, l.outputs*sizeof(float)); |
| | | if(delay == DELAY){ |
| | | mean_arrays(predictions, FRAMES, l.outputs, avg); |
| | | } |
| | | |
| | | free_image(det_s); |
| | | convert_detections(avg, l.classes, l.n, l.sqrt, l.side, 1, 1, demo_thresh, probs, boxes, 0); |
| | | if (nms > 0) do_nms(boxes, probs, l.side*l.side*l.n, l.classes, nms); |
| | | printf("\033[2J"); |
| | | printf("\033[1;1H"); |
| | | printf("\nFPS:%.1f\n",fps); |
| | | printf("Objects:\n\n"); |
| | | |
| | | images[demo_index] = det; |
| | | det = images[(demo_index + FRAMES/2 + 1)%FRAMES]; |
| | | demo_index = (demo_index + 1)%FRAMES; |
| | | |
| | | draw_detections(det, l.side*l.side*l.n, demo_thresh, boxes, probs, demo_names, demo_labels, demo_classes); |
| | | if(delay == 0){ |
| | | delay = DELAY; |
| | | } else { |
| | | --delay; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | double get_wall_time() |
| | | { |
| | | struct timeval time; |
| | | if (gettimeofday(&time,NULL)){ |
| | | return 0; |
| | | } |
| | | return (double)time.tv_sec + (double)time.tv_usec * .000001; |
| | | } |
| | | |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes) |
| | | { |
| | | demo_names = names; |
| | | demo_labels = labels; |
| | | demo_classes = classes; |
| | | demo_thresh = thresh; |
| | | printf("Demo\n"); |
| | | net = parse_network_cfg(cfgfile); |
| | | if(weightfile){ |
| | | load_weights(&net, weightfile); |
| | | } |
| | | set_batch_network(&net, 1); |
| | | |
| | | srand(2222222); |
| | | |
| | | if(filename){ |
| | | cap = cvCaptureFromFile(filename); |
| | | }else{ |
| | | cap = cvCaptureFromCAM(cam_index); |
| | | } |
| | | |
| | | if(!cap) error("Couldn't connect to webcam.\n"); |
| | | |
| | | detection_layer l = net.layers[net.n-1]; |
| | | int j; |
| | | |
| | | avg = (float *) calloc(l.outputs, sizeof(float)); |
| | | for(j = 0; j < FRAMES; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float)); |
| | | for(j = 0; j < FRAMES; ++j) images[j] = make_image(1,1,3); |
| | | |
| | | boxes = (box *)calloc(l.side*l.side*l.n, sizeof(box)); |
| | | probs = (float **)calloc(l.side*l.side*l.n, sizeof(float *)); |
| | | for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *)); |
| | | |
| | | pthread_t fetch_thread; |
| | | pthread_t detect_thread; |
| | | |
| | | fetch_in_thread(0); |
| | | det = in; |
| | | det_s = in_s; |
| | | |
| | | fetch_in_thread(0); |
| | | detect_in_thread(0); |
| | | disp = det; |
| | | det = in; |
| | | det_s = in_s; |
| | | |
| | | for(j = 0; j < FRAMES/2; ++j){ |
| | | fetch_in_thread(0); |
| | | detect_in_thread(0); |
| | | disp = det; |
| | | det = in; |
| | | det_s = in_s; |
| | | } |
| | | |
| | | int count = 0; |
| | | cvNamedWindow("Demo", CV_WINDOW_NORMAL); |
| | | cvMoveWindow("Demo", 0, 0); |
| | | cvResizeWindow("Demo", 1352, 1013); |
| | | |
| | | double before = get_wall_time(); |
| | | |
| | | while(1){ |
| | | ++count; |
| | | if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); |
| | | if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); |
| | | //fetch_in_thread(0); |
| | | //detect_in_thread(0); |
| | | |
| | | show_image(disp, "Demo"); |
| | | cvWaitKey(1); |
| | | //char buff[256]; |
| | | //sprintf(buff, "coco/coco_%05d", count); |
| | | //save_image(disp, buff); |
| | | |
| | | //free_image(disp); |
| | | //cvWaitKey(10); |
| | | pthread_join(fetch_thread, 0); |
| | | pthread_join(detect_thread, 0); |
| | | |
| | | disp = det; |
| | | det = in; |
| | | det_s = in_s; |
| | | |
| | | if(delay == DELAY){ |
| | | double after = get_wall_time(); |
| | | float curr = 1./(after - before); |
| | | fps = curr; |
| | | before = after; |
| | | } |
| | | } |
| | | } |
| | | #else |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes) |
| | | { |
| | | fprintf(stderr, "Demo needs OpenCV for webcam images.\n"); |
| | | } |
| | | #endif |
| | | |
| New file |
| | |
| | | #ifndef DEMO |
| | | #define DEMO |
| | | |
| | | #include "image.h" |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes); |
| | | |
| | | #endif |
| | |
| | | softmax_array(l.output + index + offset, l.classes, 1, |
| | | l.output + index + offset); |
| | | } |
| | | int offset = locations*l.classes; |
| | | activate_array(l.output + index + offset, locations*l.n*(1+l.coords), LOGISTIC); |
| | | } |
| | | } |
| | | if(state.train){ |
| | |
| | | best_index = 0; |
| | | } |
| | | } |
| | | /* |
| | | if(1 && *(state.net.seen) < 100000){ |
| | | if(l.random && *(state.net.seen) < 64000){ |
| | | best_index = rand()%l.n; |
| | | } |
| | | */ |
| | | |
| | | int box_index = index + locations*(l.classes + l.n) + (i*l.n + best_index) * l.coords; |
| | | int tbox_index = truth_index + 1 + l.classes; |
| | |
| | | avg_iou += iou; |
| | | ++count; |
| | | } |
| | | if(l.softmax){ |
| | | gradient_array(l.output + index + locations*l.classes, locations*l.n*(1+l.coords), |
| | | LOGISTIC, l.delta + index + locations*l.classes); |
| | | } |
| | | } |
| | | |
| | | if(0){ |
| | |
| | | } |
| | | |
| | | |
| | | *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2); |
| | | |
| | | |
| | | printf("Detection Avg IOU: %f, Pos Cat: %f, All Cat: %f, Pos Obj: %f, Any Obj: %f, count: %d\n", avg_iou/count, avg_cat/count, avg_allcat/(count*l.classes), avg_obj/count, avg_anyobj/(l.batch*locations*l.n), count); |
| | |
| | | image get_image_from_stream(CvCapture *cap) |
| | | { |
| | | IplImage* src = cvQueryFrame(cap); |
| | | if (!src) return make_empty_image(0,0,0); |
| | | image im = ipl_to_image(src); |
| | | rgbgr_image(im); |
| | | return im; |
| | |
| | | float object_scale; |
| | | float noobject_scale; |
| | | float class_scale; |
| | | int random; |
| | | |
| | | int dontload; |
| | | int dontloadscales; |
| | |
| | | case EXP: |
| | | return net.learning_rate * pow(net.gamma, batch_num); |
| | | case POLY: |
| | | if (batch_num < net.burn_in) return net.learning_rate * pow((float)batch_num / net.burn_in, net.power); |
| | | return net.learning_rate * pow(1 - (float)batch_num / net.max_batches, net.power); |
| | | case RANDOM: |
| | | return net.learning_rate * pow(rand_uniform(0,1), net.power); |
| | |
| | | float *scales; |
| | | int *steps; |
| | | int num_steps; |
| | | int burn_in; |
| | | |
| | | int inputs; |
| | | int h, w, c; |
| | |
| | | layer.noobject_scale = option_find_float(options, "noobject_scale", 1); |
| | | layer.class_scale = option_find_float(options, "class_scale", 1); |
| | | layer.jitter = option_find_float(options, "jitter", .2); |
| | | layer.random = option_find_int_quiet(options, "random", 0); |
| | | return layer; |
| | | } |
| | | |
| | |
| | | |
| | | char *policy_s = option_find_str(options, "policy", "constant"); |
| | | net->policy = get_policy(policy_s); |
| | | net->burn_in = option_find_int_quiet(options, "burn_in", 0); |
| | | if(net->policy == STEP){ |
| | | net->step = option_find_int(options, "step", 1); |
| | | net->scale = option_find_float(options, "scale", 1); |
| | |
| | | #include "utils.h" |
| | | #include "parser.h" |
| | | #include "box.h" |
| | | #include "demo.h" |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | |
| | | save_weights(net, buff); |
| | | } |
| | | |
| | | void convert_yolo_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness) |
| | | void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness) |
| | | { |
| | | int i,j,n; |
| | | //int per_cell = 5*num+classes; |
| | |
| | | float *predictions = network_predict(net, X); |
| | | int w = val[t].w; |
| | | int h = val[t].h; |
| | | convert_yolo_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0); |
| | | convert_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0); |
| | | if (nms) do_nms_sort(boxes, probs, side*side*l.n, classes, iou_thresh); |
| | | print_yolo_detections(fps, id, boxes, probs, side*side*l.n, classes, w, h); |
| | | free(id); |
| | |
| | | image sized = resize_image(orig, net.w, net.h); |
| | | char *id = basecfg(path); |
| | | float *predictions = network_predict(net, sized.data); |
| | | convert_yolo_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1); |
| | | convert_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1); |
| | | if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms); |
| | | |
| | | char *labelpath = find_replace(path, "images", "labels"); |
| | |
| | | time=clock(); |
| | | float *predictions = network_predict(net, X); |
| | | printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); |
| | | convert_yolo_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0); |
| | | 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, voc_names, voc_labels, 20); |
| | | draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, voc_labels, 20); |
| | |
| | | } |
| | | } |
| | | |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename); |
| | | |
| | | void run_yolo(int argc, char **argv) |
| | | { |
| | | int i; |
| | |
| | | else if(0==strcmp(argv[2], "train")) train_yolo(cfg, weights); |
| | | else if(0==strcmp(argv[2], "valid")) validate_yolo(cfg, weights); |
| | | else if(0==strcmp(argv[2], "recall")) validate_yolo_recall(cfg, weights); |
| | | else if(0==strcmp(argv[2], "demo")) demo_yolo(cfg, weights, thresh, cam_index, filename); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, voc_labels, 20); |
| | | } |