Joseph Redmon
2015-04-01 a05c4bd2e99eead9e553241246b54409dac07c87
src/detection.c
@@ -26,13 +26,22 @@
                float green = get_color(1,class,classes);
                float blue = get_color(2,class,classes);
                //float maxheight = distance_from_edge(r, side);
                //float maxwidth  = distance_from_edge(c, side);
                j += classes;
                int d = im.w/side;
                int y = r*d+box[j]*d;
                int x = c*d+box[j+1]*d;
                int h = box[j+2]*im.h;
                int w = box[j+3]*im.w;
                draw_box(im, x-w/2, y-h/2, x+w/2, y+h/2,red,green,blue);
                float y = box[j+0];
                float x = box[j+1];
                x = (x+c)/side;
                y = (y+r)/side;
                float h = box[j+2]; //*maxheight;
                float w = box[j+3]; //*maxwidth;
                //printf("coords %f %f %f %f\n", x, y, w, h);
                int left  = (x-w/2)*im.w;
                int right = (x+w/2)*im.w;
                int top   = (y-h/2)*im.h;
                int bot   = (y+h/2)*im.h;
                draw_box(im, left, top, right, bot, red, green, blue);
            }
        }
    }
@@ -60,25 +69,20 @@
    char **paths = (char **)list_to_array(plist);
    printf("%d\n", plist->size);
    data train, buffer;
    int im_dim = 512;
    int jitter = 64;
    int im_dim = 448;
    int classes = 20;
    int background = 1;
    pthread_t load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, background, &buffer);
    pthread_t load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, background, &buffer);
    clock_t time;
    while(1){
        i += 1;
        time=clock();
        pthread_join(load_thread, 0);
        train = buffer;
        load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, background, &buffer);
        load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, background, &buffer);
/*
           image im = float_to_image(im_dim - jitter, im_dim-jitter, 3, train.X.vals[114]);
           draw_detection(im, train.y.vals[114], 7);
           show_image(im, "truth");
           cvWaitKey(0);
*/
           //image im = float_to_image(im_dim, im_dim, 3, train.X.vals[114]);
           //draw_detection(im, train.y.vals[114], 7);
        printf("Loaded: %lf seconds\n", sec(clock()-time));
        time=clock();
@@ -112,7 +116,9 @@
    int classes = 20;
    int background = 0;
    int nuisance = 1;
    int num_output = 7*7*(4+classes+background+nuisance);
    int num_boxes = 7;
    int per_box = 4+classes+background+nuisance;
    int num_output = num_boxes*num_boxes*per_box;
    int m = plist->size;
    int i = 0;
@@ -136,18 +142,20 @@
        matrix pred = network_predict_data(net, val);
        int j, k, class;
        for(j = 0; j < pred.rows; ++j){
            for(k = 0; k < pred.cols; k += classes+4+background+nuisance){
            for(k = 0; k < pred.cols; k += per_box){
                float scale = 1.;
                if(nuisance) scale = 1.-pred.vals[j][k];
                for(class = 0; class < classes; ++class){
                    int index = (k)/(classes+4+background+nuisance);
                    int r = index/7;
                    int c = index%7;
                int index = k/per_box;
                int row = index / num_boxes;
                int col = index % num_boxes;
                if (nuisance) scale = 1.-pred.vals[j][k];
                for (class = 0; class < classes; ++class){
                    int ci = k+classes+background+nuisance;
                    float y = (r + pred.vals[j][ci + 0])/7.;
                    float x = (c + pred.vals[j][ci + 1])/7.;
                    float h = pred.vals[j][ci + 2];
                    float w = pred.vals[j][ci + 3];
                    float y = (pred.vals[j][ci + 0] + row)/num_boxes;
                    float x = (pred.vals[j][ci + 1] + col)/num_boxes;
                    float h = pred.vals[j][ci + 2]; //* distance_from_edge(row, num_boxes);
                    h = h*h;
                    float w = pred.vals[j][ci + 3]; //* distance_from_edge(col, num_boxes);
                    w = w*w;
                    printf("%d %d %f %f %f %f %f\n", (i-1)*m/splits + j, class, scale*pred.vals[j][k+class+background+nuisance], y, x, h, w);
                }
            }