| | |
| | | #endif |
| | | |
| | | char *voc_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"}; |
| | | |
| | | void draw_yolo(image im, int num, float thresh, box *boxes, float **probs, char *label) |
| | | { |
| | | int classes = 20; |
| | | int i; |
| | | |
| | | for(i = 0; i < num; ++i){ |
| | | int class = max_index(probs[i], classes); |
| | | float prob = probs[i][class]; |
| | | if(prob > thresh){ |
| | | int width = pow(prob, 1./2.)*10; |
| | | printf("%f %s\n", prob, voc_names[class]); |
| | | float red = get_color(0,class,classes); |
| | | float green = get_color(1,class,classes); |
| | | float blue = get_color(2,class,classes); |
| | | //red = green = blue = 0; |
| | | box b = boxes[i]; |
| | | |
| | | int left = (b.x-b.w/2.)*im.w; |
| | | int right = (b.x+b.w/2.)*im.w; |
| | | int top = (b.y-b.h/2.)*im.h; |
| | | int bot = (b.y+b.h/2.)*im.h; |
| | | |
| | | if(left < 0) left = 0; |
| | | if(right > im.w-1) right = im.w-1; |
| | | if(top < 0) top = 0; |
| | | if(bot > im.h-1) bot = im.h-1; |
| | | |
| | | draw_box_width(im, left, top, right, bot, width, red, green, blue); |
| | | } |
| | | } |
| | | show_image(im, label); |
| | | } |
| | | image voc_labels[20]; |
| | | |
| | | void train_yolo(char *cfgfile, char *weightfile) |
| | | { |
| | | //char *train_images = "/home/pjreddie/data/voc/person_detection/2010_person.txt"; |
| | | //char *train_images = "/home/pjreddie/data/people-art/train.txt"; |
| | | //char *train_images = "/home/pjreddie/data/voc/test/2012_trainval.txt"; |
| | | //char *train_images = "/home/pjreddie/data/voc/test/2010_trainval.txt"; |
| | | char *train_images = "/home/pjreddie/data/voc/test/train.txt"; |
| | | //char *train_images = "/home/pjreddie/data/voc/test/train_all.txt"; |
| | | //char *train_images = "/home/pjreddie/data/voc/test/2007_trainval.txt"; |
| | | char *train_images = "/data/voc/train.txt"; |
| | | char *backup_directory = "/home/pjreddie/backup/"; |
| | | srand(time(0)); |
| | | data_seed = time(0); |
| | |
| | | |
| | | printf("Loaded: %lf seconds\n", sec(clock()-time)); |
| | | |
| | | /* |
| | | image im = float_to_image(net.w, net.h, 3, train.X.vals[113]); |
| | | image copy = copy_image(im); |
| | | draw_yolo(copy, train.y.vals[113], 7, "truth"); |
| | | cvWaitKey(0); |
| | | free_image(copy); |
| | | */ |
| | | |
| | | time=clock(); |
| | | float loss = train_network(net, train); |
| | | if (avg_loss < 0) avg_loss = loss; |
| | | avg_loss = avg_loss*.9 + loss*.1; |
| | | |
| | | printf("%d: %f, %f avg, %f rate, %lf seconds, %d images\n", i, loss, avg_loss, get_current_rate(net), sec(clock()-time), i*imgs); |
| | | if(i%1000==0){ |
| | | if(i%1000==0 || i == 600){ |
| | | char buff[256]; |
| | | sprintf(buff, "%s/%s_%d.weights", backup_directory, base, i); |
| | | save_weights(net, buff); |
| | |
| | | srand(time(0)); |
| | | |
| | | char *base = "results/comp4_det_test_"; |
| | | //base = "/home/pjreddie/comp4_det_test_"; |
| | | //list *plist = get_paths("/home/pjreddie/data/people-art/test.txt"); |
| | | //list *plist = get_paths("/home/pjreddie/data/cubist/test.txt"); |
| | | |
| | | list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt"); |
| | | //list *plist = get_paths("/home/pjreddie/data/voc/test_2012.txt"); |
| | | list *plist = get_paths("data/voc.2007.test"); |
| | | //list *plist = get_paths("data/voc.2012.test"); |
| | | char **paths = (char **)list_to_array(plist); |
| | | |
| | | layer l = net.layers[net.n-1]; |
| | |
| | | srand(time(0)); |
| | | |
| | | char *base = "results/comp4_det_test_"; |
| | | list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt"); |
| | | list *plist = get_paths("data/voc.2007.test"); |
| | | char **paths = (char **)list_to_array(plist); |
| | | |
| | | layer l = net.layers[net.n-1]; |
| | |
| | | int i=0; |
| | | |
| | | float thresh = .001; |
| | | int nms = 0; |
| | | float iou_thresh = .5; |
| | | float nms_thresh = .5; |
| | | float nms = 0; |
| | | |
| | | int total = 0; |
| | | int correct = 0; |
| | |
| | | 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); |
| | | if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms_thresh); |
| | | if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms); |
| | | |
| | | char *labelpath = find_replace(path, "images", "labels"); |
| | | labelpath = find_replace(labelpath, "JPEGImages", "labels"); |
| | |
| | | char *input = buff; |
| | | int j; |
| | | float nms=.5; |
| | | printf("%d %d %d", l.side, l.n, l.classes); |
| | | 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 *)); |
| | |
| | | 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); |
| | | if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms); |
| | | draw_yolo(im, l.side*l.side*l.n, thresh, boxes, probs, "predictions"); |
| | | //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, 0, 20); |
| | | show_image(im, "predictions"); |
| | | save_image(im, "predictions"); |
| | | |
| | | show_image(sized, "resized"); |
| | | free_image(im); |
| | |
| | | #endif |
| | | */ |
| | | |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh); |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh, int cam_index); |
| | | #ifndef GPU |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh){} |
| | | void demo_yolo(char *cfgfile, char *weightfile, float thresh, int cam_index) |
| | | { |
| | | fprintf(stderr, "Darknet must be compiled with CUDA for YOLO demo.\n"); |
| | | } |
| | | #endif |
| | | |
| | | void run_yolo(int argc, char **argv) |
| | | { |
| | | int i; |
| | | for(i = 0; i < 20; ++i){ |
| | | char buff[256]; |
| | | sprintf(buff, "data/labels/%s.png", voc_names[i]); |
| | | voc_labels[i] = load_image_color(buff, 0, 0); |
| | | } |
| | | |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .2); |
| | | int cam_index = find_int_arg(argc, argv, "-c", 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); |
| | | else if(0==strcmp(argv[2], "demo")) demo_yolo(cfg, weights, thresh, cam_index); |
| | | } |