Joseph Redmon
2015-07-21 e56d1eff13bf8b6863cd213db157b9544cb9e3a7
Switch to fast resize
5 files modified
50 ■■■■ changed files
Makefile 4 ●●●● patch | view | raw | blame | history
src/crop_layer_kernels.cu 4 ●●●● patch | view | raw | blame | history
src/data.c 15 ●●●●● patch | view | raw | blame | history
src/image.c 25 ●●●●● patch | view | raw | blame | history
src/image.h 2 ●●● patch | view | raw | blame | history
Makefile
@@ -1,5 +1,5 @@
GPU=1
OPENCV=1
GPU=0
OPENCV=0
DEBUG=0
ARCH= -arch=sm_52
src/crop_layer_kernels.cu
@@ -78,7 +78,7 @@
    return make_float3(r, g, b);
}
__device__ float billinear_interpolate_kernel(float *image, int w, int h, float x, float y, int c)
__device__ float bilinear_interpolate_kernel(float *image, int w, int h, float x, float y, int c)
{
    int ix = (int) floorf(x);
    int iy = (int) floorf(y);
@@ -170,7 +170,7 @@
    float rx = cos(angle)*(x-cx) - sin(angle)*(y-cy) + cx;
    float ry = sin(angle)*(x-cx) + cos(angle)*(y-cy) + cy;
    output[count] = billinear_interpolate_kernel(input, w, h, rx, ry, k);
    output[count] = bilinear_interpolate_kernel(input, w, h, rx, ry, k);
}
extern "C" void forward_crop_layer_gpu(crop_layer layer, network_state state)
src/data.c
@@ -425,18 +425,10 @@
    d.X.vals = calloc(d.X.rows, sizeof(float*));
    d.X.cols = h*w*3;
    clock_t time;
    clock_t load = 0;
    clock_t resize = 0;
    clock_t crop = 0;
    int k = num_boxes*num_boxes*(4+classes+background);
    d.y = make_matrix(n, k);
    for(i = 0; i < n; ++i){
        time=clock();
        image orig = load_image_color(random_paths[i], 0, 0);
        load += clock() - time;
        time = clock();
        int oh = orig.h;
        int ow = orig.w;
@@ -465,9 +457,6 @@
        int flip = rand_r(&data_seed)%2;
        image cropped = crop_image(orig, pleft, ptop, swidth, sheight);
        crop += clock() - time;
        time = clock();
        float dx = ((float)pleft/ow)/sx;
        float dy = ((float)ptop /oh)/sy;
@@ -475,15 +464,11 @@
        if(flip) flip_image(sized);
        d.X.vals[i] = sized.data;
        resize += clock() - time;
        time = clock();
        fill_truth_detection(random_paths[i], d.y.vals[i], classes, num_boxes, flip, background, dx, dy, 1./sx, 1./sy);
        free_image(orig);
        free_image(cropped);
    }
    printf("load: %f, crop: %f, resize: %f\n", sec(load), sec(crop), sec(resize));
    free(random_paths);
    return d;
}
src/image.c
@@ -332,7 +332,7 @@
            for(x = 0; x < im.w; ++x){
                float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx;
                float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy;
                float val = billinear_interpolate(im, rx, ry, c);
                float val = bilinear_interpolate(im, rx, ry, c);
                set_pixel(rot, x, y, c, val);
            }
        }
@@ -549,7 +549,7 @@
   }
 */
float billinear_interpolate(image im, float x, float y, int c)
float bilinear_interpolate(image im, float x, float y, int c)
{
    int ix = (int) floorf(x);
    int iy = (int) floorf(y);
@@ -564,29 +564,9 @@
    return val;
}
// #wikipedia
image resize_image(image im, int w, int h)
{
    image resized = make_image(w, h, im.c);   
    int r, c, k;
    float w_scale = (float)(im.w - 1) / (w - 1);
    float h_scale = (float)(im.h - 1) / (h - 1);
    for(k = 0; k < im.c; ++k){
        for(r = 0; r < h; ++r){
            for(c = 0; c < w; ++c){
                float sx = c*w_scale;
                float sy = r*h_scale;
                float val = billinear_interpolate(im, sx, sy, k);
                set_pixel(resized, c, r, k, val);
            }
        }
    }
    return resized;
}
image resize_image2(image im, int w, int h)
{
    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);
@@ -607,7 +587,6 @@
            }
        }
    }
    for(k = 0; k < im.c; ++k){
        for(r = 0; r < h; ++r){
            float sy = r*h_scale;
src/image.h
@@ -64,7 +64,7 @@
float get_pixel_extend(image m, int x, int y, int c);
void set_pixel(image m, int x, int y, int c, float val);
void add_pixel(image m, int x, int y, int c, float val);
float billinear_interpolate(image im, float x, float y, int c);
float bilinear_interpolate(image im, float x, float y, int c);
image get_image_layer(image m, int l);