| | |
| | | #include "utils.h" |
| | | #include "parser.h" |
| | | #include "box.h" |
| | | #include "demo.h" |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | |
| | | args.d = &buffer; |
| | | args.type = REGION_DATA; |
| | | |
| | | args.angle = net.angle; |
| | | args.exposure = net.exposure; |
| | | args.saturation = net.saturation; |
| | | args.hue = net.hue; |
| | | |
| | | pthread_t load_thread = load_data_in_thread(args); |
| | | clock_t time; |
| | | //while(i*imgs < N*120){ |
| | |
| | | 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; |
| | |
| | | int nms = 1; |
| | | float iou_thresh = .5; |
| | | |
| | | int nthreads = 2; |
| | | int nthreads = 8; |
| | | image *val = calloc(nthreads, sizeof(image)); |
| | | image *val_resized = calloc(nthreads, sizeof(image)); |
| | | image *buf = calloc(nthreads, sizeof(image)); |
| | |
| | | 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"); |
| | |
| | | char buff[256]; |
| | | char *input = buff; |
| | | int j; |
| | | float nms=.5; |
| | | float nms=.4; |
| | | box *boxes = calloc(l.side*l.side*l.n, sizeof(box)); |
| | | float **probs = calloc(l.side*l.side*l.n, sizeof(float *)); |
| | | for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = calloc(l.classes, sizeof(float *)); |
| | |
| | | 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); |
| | | show_image(im, "predictions"); |
| | | save_image(im, "predictions"); |
| | | show_image(im, "predictions"); |
| | | |
| | | show_image(sized, "resized"); |
| | | free_image(im); |
| | | free_image(sized); |
| | | #ifdef OPENCV |
| | |
| | | } |
| | | } |
| | | |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename); |
| | | |
| | | void run_yolo(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); |
| | | int frame_skip = find_int_arg(argc, argv, "-s", 0); |
| | | if(argc < 4){ |
| | | fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]); |
| | | return; |
| | |
| | | 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, frame_skip); |
| | | } |