Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GPU=0
OPENCV=0
OPENCV=1
DEBUG=0

ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20
Expand Down
Binary file added data/probs/0.01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/probs/0.26.png
Binary file added data/probs/0.27.png
Binary file added data/probs/0.28.png
Binary file added data/probs/0.29.png
Binary file added data/probs/0.30.png
Binary file added data/probs/0.31.png
Binary file added data/probs/0.32.png
Binary file added data/probs/0.33.png
Binary file added data/probs/0.34.png
Binary file added data/probs/0.35.png
Binary file added data/probs/0.36.png
Binary file added data/probs/0.37.png
Binary file added data/probs/0.38.png
Binary file added data/probs/0.39.png
Binary file added data/probs/0.40.png
Binary file added data/probs/0.41.png
Binary file added data/probs/0.42.png
Binary file added data/probs/0.43.png
Binary file added data/probs/0.44.png
Binary file added data/probs/0.45.png
Binary file added data/probs/0.46.png
Binary file added data/probs/0.47.png
Binary file added data/probs/0.48.png
Binary file added data/probs/0.49.png
Binary file added data/probs/0.50.png
Binary file added data/probs/0.51.png
Binary file added data/probs/0.52.png
Binary file added data/probs/0.53.png
Binary file added data/probs/0.54.png
Binary file added data/probs/0.55.png
Binary file added data/probs/0.56.png
Binary file added data/probs/0.57.png
Binary file added data/probs/0.58.png
Binary file added data/probs/0.59.png
Binary file added data/probs/0.60.png
Binary file added data/probs/0.61.png
Binary file added data/probs/0.62.png
Binary file added data/probs/0.63.png
Binary file added data/probs/0.64.png
Binary file added data/probs/0.65.png
Binary file added data/probs/0.66.png
Binary file added data/probs/0.67.png
Binary file added data/probs/0.68.png
Binary file added data/probs/0.69.png
Binary file added data/probs/0.70.png
Binary file added data/probs/0.71.png
Binary file added data/probs/0.72.png
Binary file added data/probs/0.73.png
Binary file added data/probs/0.74.png
Binary file added data/probs/0.75.png
Binary file added data/probs/0.76.png
Binary file added data/probs/0.77.png
Binary file added data/probs/0.78.png
Binary file added data/probs/0.79.png
Binary file added data/probs/0.80.png
Binary file added data/probs/0.81.png
Binary file added data/probs/0.82.png
Binary file added data/probs/0.83.png
Binary file added data/probs/0.84.png
Binary file added data/probs/0.85.png
Binary file added data/probs/0.86.png
Binary file added data/probs/0.87.png
Binary file added data/probs/0.88.png
Binary file added data/probs/0.89.png
Binary file added data/probs/0.90.png
Binary file added data/probs/0.91.png
Binary file added data/probs/0.92.png
Binary file added data/probs/0.93.png
Binary file added data/probs/0.94.png
Binary file added data/probs/0.95.png
Binary file added data/probs/0.96.png
Binary file added data/probs/0.97.png
Binary file added data/probs/0.98.png
Binary file added data/probs/0.99.png
10 changes: 10 additions & 0 deletions data/probs/make_probs.py
Original file line number Diff line number Diff line change
@@ -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))
11 changes: 9 additions & 2 deletions src/coco.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
53 changes: 37 additions & 16 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -110,6 +123,7 @@ void draw_detections( image im,
float thresh,
box *boxes,
float **probs,
image *probs_labels,
char **names,
image *labels,
int classes
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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
}

Expand All @@ -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){
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -667,16 +687,16 @@ 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;
}

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);
Expand Down Expand Up @@ -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){
Expand All @@ -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){
Expand All @@ -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;
}*/

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -76,4 +76,3 @@ image get_image_layer(image m, int l);
void free_image(image m);
void test_resize(char *filename);
#endif

Loading