mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
faster resize?
This commit is contained in:
parent
38bd6ae6ba
commit
8ed0a5538e
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
GPU=0
|
GPU=1
|
||||||
OPENCV=0
|
OPENCV=1
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
ARCH= -arch=sm_52
|
ARCH= -arch=sm_52
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[net]
|
[net]
|
||||||
batch=64
|
batch=64
|
||||||
subdivisions=64
|
subdivisions=2
|
||||||
height=448
|
height=448
|
||||||
width=448
|
width=448
|
||||||
channels=3
|
channels=3
|
||||||
|
21
src/data.c
21
src/data.c
@ -425,10 +425,18 @@ 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.vals = calloc(d.X.rows, sizeof(float*));
|
||||||
d.X.cols = h*w*3;
|
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);
|
int k = num_boxes*num_boxes*(4+classes+background);
|
||||||
d.y = make_matrix(n, k);
|
d.y = make_matrix(n, k);
|
||||||
for(i = 0; i < n; ++i){
|
for(i = 0; i < n; ++i){
|
||||||
|
time=clock();
|
||||||
image orig = load_image_color(random_paths[i], 0, 0);
|
image orig = load_image_color(random_paths[i], 0, 0);
|
||||||
|
load += clock() - time;
|
||||||
|
time = clock();
|
||||||
|
|
||||||
int oh = orig.h;
|
int oh = orig.h;
|
||||||
int ow = orig.w;
|
int ow = orig.w;
|
||||||
@ -456,17 +464,26 @@ data load_data_detection_jitter_random(int n, char **paths, int m, int classes,
|
|||||||
|
|
||||||
int flip = rand_r(&data_seed)%2;
|
int flip = rand_r(&data_seed)%2;
|
||||||
image cropped = crop_image(orig, pleft, ptop, swidth, sheight);
|
image cropped = crop_image(orig, pleft, ptop, swidth, sheight);
|
||||||
|
|
||||||
|
crop += clock() - time;
|
||||||
|
time = clock();
|
||||||
|
|
||||||
float dx = ((float)pleft/ow)/sx;
|
float dx = ((float)pleft/ow)/sx;
|
||||||
float dy = ((float)ptop /oh)/sy;
|
float dy = ((float)ptop /oh)/sy;
|
||||||
|
|
||||||
free_image(orig);
|
|
||||||
image sized = resize_image(cropped, w, h);
|
image sized = resize_image(cropped, w, h);
|
||||||
free_image(cropped);
|
|
||||||
if(flip) flip_image(sized);
|
if(flip) flip_image(sized);
|
||||||
d.X.vals[i] = sized.data;
|
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);
|
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);
|
free(random_paths);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
50
src/image.c
50
src/image.c
@ -584,6 +584,51 @@ image resize_image(image im, int w, int h)
|
|||||||
return resized;
|
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);
|
||||||
|
float h_scale = (float)(im.h - 1) / (h - 1);
|
||||||
|
for(k = 0; k < im.c; ++k){
|
||||||
|
for(r = 0; r < im.h; ++r){
|
||||||
|
for(c = 0; c < w; ++c){
|
||||||
|
float val = 0;
|
||||||
|
if(c == w-1){
|
||||||
|
val = get_pixel(im, im.w-1, r, k);
|
||||||
|
} else {
|
||||||
|
float sx = c*w_scale;
|
||||||
|
int ix = (int) sx;
|
||||||
|
float dx = sx - ix;
|
||||||
|
val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k);
|
||||||
|
}
|
||||||
|
set_pixel(part, c, r, k, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(k = 0; k < im.c; ++k){
|
||||||
|
for(r = 0; r < h; ++r){
|
||||||
|
float sy = r*h_scale;
|
||||||
|
int iy = (int) sy;
|
||||||
|
float dy = sy - iy;
|
||||||
|
for(c = 0; c < w; ++c){
|
||||||
|
float val = (1-dy) * get_pixel(part, c, iy, k);
|
||||||
|
set_pixel(resized, c, r, k, val);
|
||||||
|
}
|
||||||
|
if(r == h-1) continue;
|
||||||
|
for(c = 0; c < w; ++c){
|
||||||
|
float val = dy * get_pixel(part, c, iy+1, k);
|
||||||
|
add_pixel(resized, c, r, k, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_image(part);
|
||||||
|
return resized;
|
||||||
|
}
|
||||||
|
|
||||||
void test_resize(char *filename)
|
void test_resize(char *filename)
|
||||||
{
|
{
|
||||||
image im = load_image(filename, 0,0, 3);
|
image im = load_image(filename, 0,0, 3);
|
||||||
@ -728,6 +773,11 @@ void set_pixel(image m, int x, int y, int c, float val)
|
|||||||
assert(x < m.w && y < m.h && c < m.c);
|
assert(x < m.w && y < m.h && c < m.c);
|
||||||
m.data[c*m.h*m.w + y*m.w + x] = val;
|
m.data[c*m.h*m.w + y*m.w + x] = val;
|
||||||
}
|
}
|
||||||
|
void add_pixel(image m, int x, int y, int c, float val)
|
||||||
|
{
|
||||||
|
assert(x < m.w && y < m.h && c < m.c);
|
||||||
|
m.data[c*m.h*m.w + y*m.w + x] += val;
|
||||||
|
}
|
||||||
|
|
||||||
void print_image(image m)
|
void print_image(image m)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,7 @@ image image_distance(image a, image b);
|
|||||||
void scale_image(image m, float s);
|
void scale_image(image m, float s);
|
||||||
image crop_image(image im, int dx, int dy, int w, int h);
|
image crop_image(image im, int dx, int dy, int w, int h);
|
||||||
image resize_image(image im, int w, int h);
|
image resize_image(image im, int w, int h);
|
||||||
|
image resize_image2(image im, int w, int h);
|
||||||
void translate_image(image m, float s);
|
void translate_image(image m, float s);
|
||||||
void normalize_image(image p);
|
void normalize_image(image p);
|
||||||
image rotate_image(image m, float rad);
|
image rotate_image(image m, float rad);
|
||||||
@ -62,6 +63,7 @@ image load_image_color(char *filename, int w, int h);
|
|||||||
float get_pixel(image m, int x, int y, int c);
|
float get_pixel(image m, int x, int y, int c);
|
||||||
float get_pixel_extend(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 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 billinear_interpolate(image im, float x, float y, int c);
|
||||||
|
|
||||||
image get_image_layer(image m, int l);
|
image get_image_layer(image m, int l);
|
||||||
|
Loading…
Reference in New Issue
Block a user