diff --git a/Makefile b/Makefile index e296b9f..dbd562b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ GPU=0 -OPENCV=0 +OPENCV=1 DEBUG=0 ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20 diff --git a/data/probs/0.01.png b/data/probs/0.01.png new file mode 100644 index 0000000..62237f0 Binary files /dev/null and b/data/probs/0.01.png differ diff --git a/data/probs/0.02.png b/data/probs/0.02.png new file mode 100644 index 0000000..fd736d9 Binary files /dev/null and b/data/probs/0.02.png differ diff --git a/data/probs/0.03.png b/data/probs/0.03.png new file mode 100644 index 0000000..c39ba4e Binary files /dev/null and b/data/probs/0.03.png differ diff --git a/data/probs/0.04.png b/data/probs/0.04.png new file mode 100644 index 0000000..4dfccfd Binary files /dev/null and b/data/probs/0.04.png differ diff --git a/data/probs/0.05.png b/data/probs/0.05.png new file mode 100644 index 0000000..b8afa03 Binary files /dev/null and b/data/probs/0.05.png differ diff --git a/data/probs/0.06.png b/data/probs/0.06.png new file mode 100644 index 0000000..2f41222 Binary files /dev/null and b/data/probs/0.06.png differ diff --git a/data/probs/0.07.png b/data/probs/0.07.png new file mode 100644 index 0000000..3586495 Binary files /dev/null and b/data/probs/0.07.png differ diff --git a/data/probs/0.08.png b/data/probs/0.08.png new file mode 100644 index 0000000..0f5bdcb Binary files /dev/null and b/data/probs/0.08.png differ diff --git a/data/probs/0.09.png b/data/probs/0.09.png new file mode 100644 index 0000000..a793dbc Binary files /dev/null and b/data/probs/0.09.png differ diff --git a/data/probs/0.10.png b/data/probs/0.10.png new file mode 100644 index 0000000..22975c1 Binary files /dev/null and b/data/probs/0.10.png differ diff --git a/data/probs/0.11.png b/data/probs/0.11.png new file mode 100644 index 0000000..d2496db Binary files /dev/null and b/data/probs/0.11.png differ diff --git a/data/probs/0.12.png b/data/probs/0.12.png new file mode 100644 index 0000000..2938a03 Binary files /dev/null and b/data/probs/0.12.png differ diff --git a/data/probs/0.13.png b/data/probs/0.13.png new file mode 100644 index 0000000..ab204ab Binary files /dev/null and b/data/probs/0.13.png differ diff --git a/data/probs/0.14.png b/data/probs/0.14.png new file mode 100644 index 0000000..41a4b28 Binary files /dev/null and b/data/probs/0.14.png differ diff --git a/data/probs/0.15.png b/data/probs/0.15.png new file mode 100644 index 0000000..b4c7573 Binary files /dev/null and b/data/probs/0.15.png differ diff --git a/data/probs/0.16.png b/data/probs/0.16.png new file mode 100644 index 0000000..c74377c Binary files /dev/null and b/data/probs/0.16.png differ diff --git a/data/probs/0.17.png b/data/probs/0.17.png new file mode 100644 index 0000000..238c31a Binary files /dev/null and b/data/probs/0.17.png differ diff --git a/data/probs/0.18.png b/data/probs/0.18.png new file mode 100644 index 0000000..75826d1 Binary files /dev/null and b/data/probs/0.18.png differ diff --git a/data/probs/0.19.png b/data/probs/0.19.png new file mode 100644 index 0000000..fb4f16e Binary files /dev/null and b/data/probs/0.19.png differ diff --git a/data/probs/0.20.png b/data/probs/0.20.png new file mode 100644 index 0000000..0175db0 Binary files /dev/null and b/data/probs/0.20.png differ diff --git a/data/probs/0.21.png b/data/probs/0.21.png new file mode 100644 index 0000000..d537ebc Binary files /dev/null and b/data/probs/0.21.png differ diff --git a/data/probs/0.22.png b/data/probs/0.22.png new file mode 100644 index 0000000..d4b7cc3 Binary files /dev/null and b/data/probs/0.22.png differ diff --git a/data/probs/0.23.png b/data/probs/0.23.png new file mode 100644 index 0000000..733e106 Binary files /dev/null and b/data/probs/0.23.png differ diff --git a/data/probs/0.24.png b/data/probs/0.24.png new file mode 100644 index 0000000..0299447 Binary files /dev/null and b/data/probs/0.24.png differ diff --git a/data/probs/0.25.png b/data/probs/0.25.png new file mode 100644 index 0000000..b92d4b5 Binary files /dev/null and b/data/probs/0.25.png differ diff --git a/data/probs/0.26.png b/data/probs/0.26.png new file mode 100644 index 0000000..4ddce38 Binary files /dev/null and b/data/probs/0.26.png differ diff --git a/data/probs/0.27.png b/data/probs/0.27.png new file mode 100644 index 0000000..5e35ff7 Binary files /dev/null and b/data/probs/0.27.png differ diff --git a/data/probs/0.28.png b/data/probs/0.28.png new file mode 100644 index 0000000..896a5b1 Binary files /dev/null and b/data/probs/0.28.png differ diff --git a/data/probs/0.29.png b/data/probs/0.29.png new file mode 100644 index 0000000..e47c8c9 Binary files /dev/null and b/data/probs/0.29.png differ diff --git a/data/probs/0.30.png b/data/probs/0.30.png new file mode 100644 index 0000000..8e65a25 Binary files /dev/null and b/data/probs/0.30.png differ diff --git a/data/probs/0.31.png b/data/probs/0.31.png new file mode 100644 index 0000000..c159f09 Binary files /dev/null and b/data/probs/0.31.png differ diff --git a/data/probs/0.32.png b/data/probs/0.32.png new file mode 100644 index 0000000..aa05d02 Binary files /dev/null and b/data/probs/0.32.png differ diff --git a/data/probs/0.33.png b/data/probs/0.33.png new file mode 100644 index 0000000..a947ad6 Binary files /dev/null and b/data/probs/0.33.png differ diff --git a/data/probs/0.34.png b/data/probs/0.34.png new file mode 100644 index 0000000..5456323 Binary files /dev/null and b/data/probs/0.34.png differ diff --git a/data/probs/0.35.png b/data/probs/0.35.png new file mode 100644 index 0000000..0f060c9 Binary files /dev/null and b/data/probs/0.35.png differ diff --git a/data/probs/0.36.png b/data/probs/0.36.png new file mode 100644 index 0000000..6dfd011 Binary files /dev/null and b/data/probs/0.36.png differ diff --git a/data/probs/0.37.png b/data/probs/0.37.png new file mode 100644 index 0000000..ea6c2fd Binary files /dev/null and b/data/probs/0.37.png differ diff --git a/data/probs/0.38.png b/data/probs/0.38.png new file mode 100644 index 0000000..bdafe91 Binary files /dev/null and b/data/probs/0.38.png differ diff --git a/data/probs/0.39.png b/data/probs/0.39.png new file mode 100644 index 0000000..5592055 Binary files /dev/null and b/data/probs/0.39.png differ diff --git a/data/probs/0.40.png b/data/probs/0.40.png new file mode 100644 index 0000000..12c306f Binary files /dev/null and b/data/probs/0.40.png differ diff --git a/data/probs/0.41.png b/data/probs/0.41.png new file mode 100644 index 0000000..e780ff9 Binary files /dev/null and b/data/probs/0.41.png differ diff --git a/data/probs/0.42.png b/data/probs/0.42.png new file mode 100644 index 0000000..1de9639 Binary files /dev/null and b/data/probs/0.42.png differ diff --git a/data/probs/0.43.png b/data/probs/0.43.png new file mode 100644 index 0000000..fbe3105 Binary files /dev/null and b/data/probs/0.43.png differ diff --git a/data/probs/0.44.png b/data/probs/0.44.png new file mode 100644 index 0000000..cb860d3 Binary files /dev/null and b/data/probs/0.44.png differ diff --git a/data/probs/0.45.png b/data/probs/0.45.png new file mode 100644 index 0000000..6bc42da Binary files /dev/null and b/data/probs/0.45.png differ diff --git a/data/probs/0.46.png b/data/probs/0.46.png new file mode 100644 index 0000000..b891cfd Binary files /dev/null and b/data/probs/0.46.png differ diff --git a/data/probs/0.47.png b/data/probs/0.47.png new file mode 100644 index 0000000..6b4c220 Binary files /dev/null and b/data/probs/0.47.png differ diff --git a/data/probs/0.48.png b/data/probs/0.48.png new file mode 100644 index 0000000..c66c2f5 Binary files /dev/null and b/data/probs/0.48.png differ diff --git a/data/probs/0.49.png b/data/probs/0.49.png new file mode 100644 index 0000000..2a340cc Binary files /dev/null and b/data/probs/0.49.png differ diff --git a/data/probs/0.50.png b/data/probs/0.50.png new file mode 100644 index 0000000..9d3c868 Binary files /dev/null and b/data/probs/0.50.png differ diff --git a/data/probs/0.51.png b/data/probs/0.51.png new file mode 100644 index 0000000..7f3abb6 Binary files /dev/null and b/data/probs/0.51.png differ diff --git a/data/probs/0.52.png b/data/probs/0.52.png new file mode 100644 index 0000000..9f96509 Binary files /dev/null and b/data/probs/0.52.png differ diff --git a/data/probs/0.53.png b/data/probs/0.53.png new file mode 100644 index 0000000..0713013 Binary files /dev/null and b/data/probs/0.53.png differ diff --git a/data/probs/0.54.png b/data/probs/0.54.png new file mode 100644 index 0000000..a9f44cc Binary files /dev/null and b/data/probs/0.54.png differ diff --git a/data/probs/0.55.png b/data/probs/0.55.png new file mode 100644 index 0000000..ac90b41 Binary files /dev/null and b/data/probs/0.55.png differ diff --git a/data/probs/0.56.png b/data/probs/0.56.png new file mode 100644 index 0000000..bf9e751 Binary files /dev/null and b/data/probs/0.56.png differ diff --git a/data/probs/0.57.png b/data/probs/0.57.png new file mode 100644 index 0000000..b31da0a Binary files /dev/null and b/data/probs/0.57.png differ diff --git a/data/probs/0.58.png b/data/probs/0.58.png new file mode 100644 index 0000000..9396596 Binary files /dev/null and b/data/probs/0.58.png differ diff --git a/data/probs/0.59.png b/data/probs/0.59.png new file mode 100644 index 0000000..8884802 Binary files /dev/null and b/data/probs/0.59.png differ diff --git a/data/probs/0.60.png b/data/probs/0.60.png new file mode 100644 index 0000000..032646b Binary files /dev/null and b/data/probs/0.60.png differ diff --git a/data/probs/0.61.png b/data/probs/0.61.png new file mode 100644 index 0000000..98b679f Binary files /dev/null and b/data/probs/0.61.png differ diff --git a/data/probs/0.62.png b/data/probs/0.62.png new file mode 100644 index 0000000..4972ea9 Binary files /dev/null and b/data/probs/0.62.png differ diff --git a/data/probs/0.63.png b/data/probs/0.63.png new file mode 100644 index 0000000..c83eecb Binary files /dev/null and b/data/probs/0.63.png differ diff --git a/data/probs/0.64.png b/data/probs/0.64.png new file mode 100644 index 0000000..83034b9 Binary files /dev/null and b/data/probs/0.64.png differ diff --git a/data/probs/0.65.png b/data/probs/0.65.png new file mode 100644 index 0000000..99af3aa Binary files /dev/null and b/data/probs/0.65.png differ diff --git a/data/probs/0.66.png b/data/probs/0.66.png new file mode 100644 index 0000000..83cf8b6 Binary files /dev/null and b/data/probs/0.66.png differ diff --git a/data/probs/0.67.png b/data/probs/0.67.png new file mode 100644 index 0000000..855faba Binary files /dev/null and b/data/probs/0.67.png differ diff --git a/data/probs/0.68.png b/data/probs/0.68.png new file mode 100644 index 0000000..26ce43b Binary files /dev/null and b/data/probs/0.68.png differ diff --git a/data/probs/0.69.png b/data/probs/0.69.png new file mode 100644 index 0000000..f449d34 Binary files /dev/null and b/data/probs/0.69.png differ diff --git a/data/probs/0.70.png b/data/probs/0.70.png new file mode 100644 index 0000000..7e05fe5 Binary files /dev/null and b/data/probs/0.70.png differ diff --git a/data/probs/0.71.png b/data/probs/0.71.png new file mode 100644 index 0000000..b98cb0a Binary files /dev/null and b/data/probs/0.71.png differ diff --git a/data/probs/0.72.png b/data/probs/0.72.png new file mode 100644 index 0000000..e6cc94e Binary files /dev/null and b/data/probs/0.72.png differ diff --git a/data/probs/0.73.png b/data/probs/0.73.png new file mode 100644 index 0000000..3277e5d Binary files /dev/null and b/data/probs/0.73.png differ diff --git a/data/probs/0.74.png b/data/probs/0.74.png new file mode 100644 index 0000000..b7e52a1 Binary files /dev/null and b/data/probs/0.74.png differ diff --git a/data/probs/0.75.png b/data/probs/0.75.png new file mode 100644 index 0000000..0c9be1f Binary files /dev/null and b/data/probs/0.75.png differ diff --git a/data/probs/0.76.png b/data/probs/0.76.png new file mode 100644 index 0000000..c9d736e Binary files /dev/null and b/data/probs/0.76.png differ diff --git a/data/probs/0.77.png b/data/probs/0.77.png new file mode 100644 index 0000000..771819a Binary files /dev/null and b/data/probs/0.77.png differ diff --git a/data/probs/0.78.png b/data/probs/0.78.png new file mode 100644 index 0000000..ed8f9b7 Binary files /dev/null and b/data/probs/0.78.png differ diff --git a/data/probs/0.79.png b/data/probs/0.79.png new file mode 100644 index 0000000..0199de6 Binary files /dev/null and b/data/probs/0.79.png differ diff --git a/data/probs/0.80.png b/data/probs/0.80.png new file mode 100644 index 0000000..dbb31b2 Binary files /dev/null and b/data/probs/0.80.png differ diff --git a/data/probs/0.81.png b/data/probs/0.81.png new file mode 100644 index 0000000..fbfa795 Binary files /dev/null and b/data/probs/0.81.png differ diff --git a/data/probs/0.82.png b/data/probs/0.82.png new file mode 100644 index 0000000..a883133 Binary files /dev/null and b/data/probs/0.82.png differ diff --git a/data/probs/0.83.png b/data/probs/0.83.png new file mode 100644 index 0000000..8402307 Binary files /dev/null and b/data/probs/0.83.png differ diff --git a/data/probs/0.84.png b/data/probs/0.84.png new file mode 100644 index 0000000..9b1e93c Binary files /dev/null and b/data/probs/0.84.png differ diff --git a/data/probs/0.85.png b/data/probs/0.85.png new file mode 100644 index 0000000..123d58e Binary files /dev/null and b/data/probs/0.85.png differ diff --git a/data/probs/0.86.png b/data/probs/0.86.png new file mode 100644 index 0000000..e5fbd70 Binary files /dev/null and b/data/probs/0.86.png differ diff --git a/data/probs/0.87.png b/data/probs/0.87.png new file mode 100644 index 0000000..5f9ba0c Binary files /dev/null and b/data/probs/0.87.png differ diff --git a/data/probs/0.88.png b/data/probs/0.88.png new file mode 100644 index 0000000..dd1da9b Binary files /dev/null and b/data/probs/0.88.png differ diff --git a/data/probs/0.89.png b/data/probs/0.89.png new file mode 100644 index 0000000..3a0963e Binary files /dev/null and b/data/probs/0.89.png differ diff --git a/data/probs/0.90.png b/data/probs/0.90.png new file mode 100644 index 0000000..52aae5b Binary files /dev/null and b/data/probs/0.90.png differ diff --git a/data/probs/0.91.png b/data/probs/0.91.png new file mode 100644 index 0000000..0f347d9 Binary files /dev/null and b/data/probs/0.91.png differ diff --git a/data/probs/0.92.png b/data/probs/0.92.png new file mode 100644 index 0000000..071b12a Binary files /dev/null and b/data/probs/0.92.png differ diff --git a/data/probs/0.93.png b/data/probs/0.93.png new file mode 100644 index 0000000..769ac3b Binary files /dev/null and b/data/probs/0.93.png differ diff --git a/data/probs/0.94.png b/data/probs/0.94.png new file mode 100644 index 0000000..f58ce9a Binary files /dev/null and b/data/probs/0.94.png differ diff --git a/data/probs/0.95.png b/data/probs/0.95.png new file mode 100644 index 0000000..33df21c Binary files /dev/null and b/data/probs/0.95.png differ diff --git a/data/probs/0.96.png b/data/probs/0.96.png new file mode 100644 index 0000000..4d5a700 Binary files /dev/null and b/data/probs/0.96.png differ diff --git a/data/probs/0.97.png b/data/probs/0.97.png new file mode 100644 index 0000000..106c5e0 Binary files /dev/null and b/data/probs/0.97.png differ diff --git a/data/probs/0.98.png b/data/probs/0.98.png new file mode 100644 index 0000000..80dc89d Binary files /dev/null and b/data/probs/0.98.png differ diff --git a/data/probs/0.99.png b/data/probs/0.99.png new file mode 100644 index 0000000..4d292db Binary files /dev/null and b/data/probs/0.99.png differ diff --git a/data/probs/make_probs.py b/data/probs/make_probs.py new file mode 100644 index 0000000..6078b5f --- /dev/null +++ b/data/probs/make_probs.py @@ -0,0 +1,10 @@ +import os + +def frange(start, stop, step): + i = start + while i < stop: + yield i + i += step + +for prob in frange(0.01, 1.0, 0.01): + os.system("convert -fill black -background white -bordercolor white -border 4 -font futura-normal -pointsize 18 label:\"%s\" \"%s.png\""%(prob, prob)) diff --git a/src/coco.c b/src/coco.c index 41c2d80..ab048da 100644 --- a/src/coco.c +++ b/src/coco.c @@ -16,6 +16,7 @@ char *coco_classes[] = {"person","bicycle","car","motorcycle","airplane","bus"," 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}; image coco_labels[80]; +image probs_labels[99]; void train_coco(char *cfgfile, char *weightfile) { @@ -242,7 +243,7 @@ void validate_coco(char *cfgfile, char *weightfile) free_image(val_resized[t]); } } - fseek(fp, -2, SEEK_CUR); + fseek(fp, -2, SEEK_CUR); fprintf(fp, "\n]\n"); fclose(fp); @@ -372,7 +373,7 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh) 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); 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); + draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, probs_labels, coco_classes, coco_labels, 80); show_image(im, "predictions"); show_image(sized, "resized"); @@ -399,11 +400,17 @@ static void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, c void run_coco(int argc, char **argv) { int i; + float j; for(i = 0; i < 80; ++i){ char buff[256]; sprintf(buff, "data/labels/%s.png", coco_classes[i]); coco_labels[i] = load_image_color(buff, 0, 0); } + for(j = 0.01; j < 0.99; j+=0.01){ + char buff[256]; + sprintf(buff, "data/probs/%.2f.png", j); + probs_labels[(int)(j*100)] = 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); char *file = find_char_arg(argc, argv, "-file", 0); diff --git a/src/image.c b/src/image.c index 40015d1..7701698 100644 --- a/src/image.c +++ b/src/image.c @@ -28,24 +28,37 @@ float get_color(int c, int x, int max) return r; } -void draw_label(image a, int r, int c, image label, const float *rgb) +void draw_label(image a, int r, int c, image label, image prob_label, const float *rgb) { float ratio = (float) label.w / label.h; int h = label.h; int w = ratio * h; image rl = resize_image(label, w, h); if (r - h >= 0) r = r - h; + float ratiop = (float) prob_label.w / prob_label.h; + int hp = prob_label.h; + int wp = ratiop * hp; + image rpl = resize_image(prob_label, wp, hp); int i, j, k; for(j = 0; j < h && j + r < a.h; ++j){ for(i = 0; i < w && i + c < a.w; ++i){ for(k = 0; k < label.c; ++k){ float val = get_pixel(rl, i, j, k); + set_pixel(a, i+c+50, j+r, k, rgb[k] * val); + } + } + } + for(j = 0; j < hp && j + r < a.h; ++j){ + for(i = 0; i < wp && i + c < a.w; ++i){ + for(k = 0; k < prob_label.c; ++k){ + float val = get_pixel(rpl, i, j, k); set_pixel(a, i+c, j+r, k, rgb[k] * val); } } } free_image(rl); + free_image(rpl); } void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b) @@ -110,6 +123,7 @@ void draw_detections( image im, float thresh, box *boxes, float **probs, + image *probs_labels, char **names, image *labels, int classes @@ -152,7 +166,7 @@ void draw_detections( image im, draw_box_width(im, left, top, right, bot, thickness, red, green, blue); if (labels) - draw_label(im, top + thickness, left, labels[i_class], rgb); + draw_label(im, top + thickness, left, labels[i_class], probs_labels[(int)(100*f_prob)], rgb); } } } @@ -288,7 +302,7 @@ void show_image_cv(image p, const char *name) IplImage *disp = cvCreateImage(cvSize(p.w,p.h), IPL_DEPTH_8U, p.c); int step = disp->widthStep; - cvNamedWindow(buff, CV_WINDOW_NORMAL); + cvNamedWindow(buff, CV_WINDOW_NORMAL); //cvMoveWindow(buff, 100*(windows%10) + 200*(windows/10), 100*(windows%10)); ++windows; for(y = 0; y < p.h; ++y){ @@ -320,10 +334,11 @@ void show_image_cv(image p, const char *name) void show_image(image p, const char *name) { #ifdef OPENCV - show_image_cv(p, name); + /* show_image_cv(p, name); */ #else fprintf(stderr, "Not compiled with OpenCV, saving to %s.png instead\n", name); save_image(p, name); + save_image_jpg(p, name); #endif } @@ -350,10 +365,15 @@ void save_image_jpg(image p, char *name) image copy = copy_image(p); rgbgr_image(copy); int x,y,k; + int params[3]; char buff[256]; sprintf(buff, "%s.jpg", name); + params[0] = CV_IMWRITE_JPEG_QUALITY; + params[1] = 75; + params[2] = 0; + IplImage *disp = cvCreateImage(cvSize(p.w,p.h), IPL_DEPTH_8U, p.c); int step = disp->widthStep; for(y = 0; y < p.h; ++y){ @@ -363,7 +383,7 @@ void save_image_jpg(image p, char *name) } } } - cvSaveImage(buff, disp,0); + cvSaveImage(buff, disp, params); cvReleaseImage(&disp); free_image(copy); } @@ -596,7 +616,7 @@ image blend_image(image fore, image back, float alpha) for(k = 0; k < fore.c; ++k){ for(j = 0; j < fore.h; ++j){ for(i = 0; i < fore.w; ++i){ - float val = alpha * get_pixel(fore, i, j, k) + + float val = alpha * get_pixel(fore, i, j, k) + (1 - alpha)* get_pixel(back, i, j, k); set_pixel(blend, i, j, k, val); } @@ -667,8 +687,8 @@ float bilinear_interpolate(image im, float x, float y, int c) float dx = x - ix; float dy = y - iy; - float val = (1-dy) * (1-dx) * get_pixel_extend(im, ix, iy, c) + - dy * (1-dx) * get_pixel_extend(im, ix, iy+1, c) + + float val = (1-dy) * (1-dx) * get_pixel_extend(im, ix, iy, c) + + dy * (1-dx) * get_pixel_extend(im, ix, iy+1, c) + (1-dy) * dx * get_pixel_extend(im, ix+1, iy, c) + dy * dx * get_pixel_extend(im, ix+1, iy+1, c); return val; @@ -676,7 +696,7 @@ float bilinear_interpolate(image im, float x, float y, int c) image resize_image(image im, int w, int h) { - image resized = make_image(w, h, im.c); + image resized = make_image(w, h, im.c); image part = make_image(w, im.h, im.c); int r, c, k; float w_scale = (float)(im.w - 1) / (w - 1); @@ -792,7 +812,7 @@ image ipl_to_image(IplImage* src) IplImage* image_to_Ipl(image img, int w, int h, int depth, int c, int step) { - int i, j, k, count= 0; + int i, j, k, count= 0; IplImage* src= cvCreateImage(cvSize(w, h), depth, c); for(k= 0; k < c; ++k){ @@ -809,9 +829,9 @@ IplImage* image_to_Ipl(image img, int w, int h, int depth, int c, int step) /* Mat image_to_Mat(image img, int w, int h, int depth, int c) { - int i, j, k, count= 0; + int i, j, k, count= 0; IplImage* src= cvCreateImage(cvSize(w, h), depth, c); - + for(k= 0; k < c; ++k){ for(i = 0; i < h; ++i){ for(j = 0; j < w; ++j){ @@ -823,7 +843,7 @@ Mat image_to_Mat(image img, int w, int h, int depth, int c) cv::Mat dst = cv::cvarrToMat(src, true); cvReleaseImage(&src); - + return dst; }*/ @@ -983,7 +1003,7 @@ image collapse_images_vert(image *ims, int n) free_image(copy); } return filters; -} +} image collapse_images_horz(image *ims, int n) { @@ -1019,7 +1039,7 @@ image collapse_images_horz(image *ims, int n) free_image(copy); } return filters; -} +} void show_images(image *ims, int n, char *window) { @@ -1036,7 +1056,8 @@ void show_images(image *ims, int n, char *window) normalize_image(m); image sized = resize_image(m, m.w, m.h); save_image(sized, window); - show_image(sized, window); + save_image_jpg(sized, window); + /* show_image(sized, window); */ free_image(sized); free_image(m); } diff --git a/src/image.h b/src/image.h index 4846bc1..f7475ad 100644 --- a/src/image.h +++ b/src/image.h @@ -20,8 +20,8 @@ void flip_image(image a); void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b); void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b); void draw_bbox(image a, box bbox, int w, float r, float g, float b); -void draw_label(image a, int r, int c, image label, const float *rgb); -void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image *labels, int classes); +void draw_label(image a, int r, int c, image label, image prob_label, const float *rgb); +void draw_detections(image im, int num, float thresh, box *boxes, float **probs, image *probs_labels, char **names, image *labels, int classes); image image_distance(image a, image b); void scale_image(image m, float s); image crop_image(image im, int dx, int dy, int w, int h); @@ -76,4 +76,3 @@ image get_image_layer(image m, int l); void free_image(image m); void test_resize(char *filename); #endif - diff --git a/src/yolo.c b/src/yolo.c index 70f6f55..76eaf7c 100644 --- a/src/yolo.c +++ b/src/yolo.c @@ -18,6 +18,7 @@ char ** c_class_names; int i_num_cl; image *img_class_labels; +image probs_labels[99]; void train_yolo( char *cfgfile, char *weightfile, @@ -330,7 +331,7 @@ void validate_yolo_recall(char *cfgfile, char *weightfile) labelpath = find_replace(labelpath, "JPEGImages", "labels"); labelpath = find_replace(labelpath, ".jpg", ".txt"); labelpath = find_replace(labelpath, ".JPEG", ".txt"); - labelpath = find_replace(labelpath, ".png", ".txt"); + labelpath = find_replace(labelpath, ".png", ".txt"); int num_labels = 0; box_label *truth = read_boxes(labelpath, &num_labels); @@ -438,11 +439,12 @@ void test_yolo( char *cfgfile, // draw detections into image and show or write result if ( b_draw_detections ) { - draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, c_class_names, img_class_labels, l.classes); - show_image(im, "predictions"); + draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, probs_labels, c_class_names, img_class_labels, l.classes); + /* show_image(im, "predictions"); */ save_image(im, "predictions"); + save_image_jpg(im, "predictions"); - show_image(sized, "resized"); + /* show_image(sized, "resized"); */ } @@ -471,7 +473,7 @@ void test_yolo( char *cfgfile, if(top < 0) top = 0; if(bot > im.h-1) bot = im.h-1; - fprintf(fout_box, "%s %d %d %d %d %f class %d \n", input, left, top, right-left, bot-top, prob, i_class ); + fprintf(fout_box, "%s,%d,%d,%d,%d,%.2f,%s \n", input, left, top, right-left, bot-top, prob, c_class_names[i_class] ); } fclose(fout_box); @@ -525,7 +527,7 @@ void test_yolo_on_filelist( char *cfgfile, clock_t time; int j; - // allocate memory for prediction results + // allocate memory for prediction results 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) @@ -568,7 +570,7 @@ void test_yolo_on_filelist( char *cfgfile, // do actual prediction time=clock(); float *predictions = network_predict(net, X); - + printf("%s predicted in %f seconds.\n", c_filename, sec(clock()-time)); // convert results to original image size @@ -583,11 +585,12 @@ void test_yolo_on_filelist( char *cfgfile, // draw detections into image and show or write result if ( b_draw_detections ) { - draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, c_class_names, img_class_labels, l.classes); - show_image(im, "predictions"); + draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, probs_labels, c_class_names, img_class_labels, l.classes); + /* show_image(im, "predictions"); */ save_image(im, "predictions"); + save_image_jpg(im, "predictions"); - show_image(sized, "resized"); + /* show_image(sized, "resized"); */ } @@ -634,12 +637,12 @@ void test_yolo_on_filelist( char *cfgfile, } #endif } - + fclose( fp_filelist ); if (line) { free(line); - } + } } @@ -717,7 +720,7 @@ void print_help_dialog() printf(" -> detect in images from a usb cam (run yolo in test state) \n\n"); printf("demo_vid \n"); printf(" -> detect in a specified video (run yolo in test state) \n\n"); - + printf("\n---------------------------\n"); @@ -725,24 +728,24 @@ void print_help_dialog() printf("---------------------------\n\n"); printf("general settings \n"); printf(" -c_list_with_classnames -- (./data/classnames_VOC.txt), file with names of possible categories. THEIR NUMBER SHOULD MATCH YOUR MODEL LAYOUT. \n"); - printf("\n"); - + printf("\n"); + printf("mode \"test\" \n"); - printf(" -c_filename -- (0), filename of image to be processed. Interactive mode if empty. \n"); + printf(" -c_filename -- (0), filename of image to be processed. Interactive mode if empty. \n"); printf(" -draw -- (false), impaint results to image \n"); printf(" -write -- (false), write results to file \n"); printf(" -dest -- (./bboxes.txt), filename to write results into \n"); printf(" -nms -- (0.5), threshold for non-maximum-suppresion \n"); - printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); + printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); printf("\n"); printf("mode \"test_on_filelist\" \n"); - printf(" -c_filelist -- (0), name of list with image filenames (1 per line) \n"); + printf(" -c_filelist -- (0), name of list with image filenames (1 per line) \n"); printf(" -draw -- (false), impaint results to image \n"); printf(" -write -- (false), write results to file \n"); printf(" -dest -- (./bboxes.txt), filename to write results into \n"); printf(" -nms -- (0.5), threshold for non-maximum-suppresion \n"); - printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); + printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); printf("\n"); printf("mode \"train\" \n"); @@ -751,16 +754,16 @@ void print_help_dialog() printf("\n"); printf("mode \"valid\" \n"); - printf(" nothing else \n"); + printf(" nothing else \n"); printf("\n"); printf("mode \"recall\" \n"); - printf(" nothing else \n"); + printf(" nothing else \n"); printf("\n"); printf("mode \"demo_cam\" \n"); printf(" -cam_idx -- (0), index of camera port (for OpenCV) \n"); - printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); + printf(" -thresh -- (0.2), only accept detections with confidence scores above that value \n"); printf("\n"); printf("mode \"demo_vid\" \n"); @@ -770,8 +773,8 @@ void print_help_dialog() printf("\n========================\n"); printf("\n END OF YOLO HELP \n"); - printf("\n ENJOY!\n"); - printf("\n========================\n"); + printf("\n ENJOY!\n"); + printf("\n========================\n"); } void run_yolo(int argc, char **argv) @@ -784,6 +787,14 @@ void run_yolo(int argc, char **argv) return; } + float j; + + for(j = 0.01; j < 0.99; j+=0.01){ + char buff[256]; + sprintf(buff, "data/probs/%.2f.png", j); + probs_labels[(int)(j*100)] = load_image_color(buff, 0, 0); + } + // now do everything which is not needed for help char * c_list_with_classnames = find_char_arg(argc, argv, "-c_classes", "./data/classnames_VOC.txt"); @@ -896,7 +907,7 @@ void run_yolo(int argc, char **argv) char * c_dest = find_char_arg( argc, argv, "-dest", "./bboxes.txt"); float f_nms_threshold = find_float_arg( argc, argv, "-nms", 0.5); char * c_filelist = find_char_arg( argc, argv, "-c_filelist", 0); - float thresh = find_float_arg( argc, argv, "-thresh", .2); + float thresh = find_float_arg( argc, argv, "-thresh", .2); test_yolo_on_filelist( c_cfg, c_weights, c_filelist, thresh, b_draw_detections, b_write_detections, c_dest, f_nms_threshold ); } @@ -919,15 +930,15 @@ void run_yolo(int argc, char **argv) { int cam_index = find_int_arg( argc, argv, "-cam_idx", 0); float thresh = find_float_arg( argc, argv, "-thresh", .2); - + demo_yolo(c_cfg, c_weights, thresh, cam_index, "NULL" /*filename*/); } else if(0==strcmp(argv[2], "demo_vid")) { - float thresh = find_float_arg( argc, argv, "-thresh", .2); + float thresh = find_float_arg( argc, argv, "-thresh", .2); char * c_filename = find_char_arg( argc, argv, "-c_filename", 0); - - demo_yolo(c_cfg, c_weights, thresh, -1/*cam_index*/, c_filename); + + demo_yolo(c_cfg, c_weights, thresh, -1/*cam_index*/, c_filename); }