mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Switch to fast resize
This commit is contained in:
parent
8ed0a5538e
commit
e56d1eff13
@ -78,7 +78,7 @@ __device__ float3 hsv_to_rgb_kernel(float3 hsv)
|
||||
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 @@ __global__ void forward_crop_layer_kernel(float *input, float *rand, int size, i
|
||||
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)
|
||||
|
15
src/data.c
15
src/data.c
@ -425,18 +425,10 @@ data load_data_detection_jitter_random(int n, char **paths, int m, int classes,
|
||||
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 @@ data load_data_detection_jitter_random(int n, char **paths, int m, int classes,
|
||||
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 @@ data load_data_detection_jitter_random(int n, char **paths, int m, int classes,
|
||||
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;
|
||||
}
|
||||
|
25
src/image.c
25
src/image.c
@ -332,7 +332,7 @@ image rotate_image(image im, float rad)
|
||||
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 @@ void saturate_exposure_image(image im, float sat, float exposure)
|
||||
}
|
||||
*/
|
||||
|
||||
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,27 +564,7 @@ float billinear_interpolate(image im, float x, float y, int c)
|
||||
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);
|
||||
@ -607,7 +587,6 @@ image resize_image2(image im, int w, int h)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(k = 0; k < im.c; ++k){
|
||||
for(r = 0; r < h; ++r){
|
||||
float sy = r*h_scale;
|
||||
|
@ -64,7 +64,7 @@ float get_pixel(image m, int x, int y, int c);
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user