From e56d1eff13bf8b6863cd213db157b9544cb9e3a7 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 21 Jul 2015 18:46:24 +0000
Subject: [PATCH] Switch to fast resize

---
 src/image.c               |   25 ++-----------------------
 Makefile                  |    4 ++--
 src/data.c                |   15 ---------------
 src/crop_layer_kernels.cu |    4 ++--
 src/image.h               |    2 +-
 5 files changed, 7 insertions(+), 43 deletions(-)

diff --git a/Makefile b/Makefile
index 1b42277..32ff4c0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-GPU=1
-OPENCV=1
+GPU=0
+OPENCV=0
 DEBUG=0
 
 ARCH= -arch=sm_52
diff --git a/src/crop_layer_kernels.cu b/src/crop_layer_kernels.cu
index 9df915c..2c3aefe 100644
--- a/src/crop_layer_kernels.cu
+++ b/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)
diff --git a/src/data.c b/src/data.c
index 2b61853..5140ce6 100644
--- a/src/data.c
+++ b/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;
 }
diff --git a/src/image.c b/src/image.c
index c499c79..ae8ca0a 100644
--- a/src/image.c
+++ b/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;
diff --git a/src/image.h b/src/image.h
index 1506077..e380025 100644
--- a/src/image.h
+++ b/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);
 

--
Gitblit v1.10.0