| | |
| | | GPU=1 |
| | | OPENCV=1 |
| | | GPU=0 |
| | | OPENCV=0 |
| | | DEBUG=0 |
| | | |
| | | ARCH= -arch=sm_52 |
| | |
| | | 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); |
| | |
| | | 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) |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | } |
| | | */ |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | for(k = 0; k < im.c; ++k){ |
| | | for(r = 0; r < h; ++r){ |
| | | float sy = r*h_scale; |
| | |
| | | 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); |
| | | |