From 6553b3f0e3e55fc30a99c7d4b5798aa86d18a114 Mon Sep 17 00:00:00 2001 From: Joseph Redmon Date: Sun, 29 Mar 2015 19:31:47 -0700 Subject: [PATCH] no comment --- src/convolutional_kernels.cu | 6 +++--- src/data.c | 5 +++++ src/image.c | 24 ++++++++++++++++++++++++ src/imagenet.c | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/convolutional_kernels.cu b/src/convolutional_kernels.cu index c28731f9..d260a95b 100644 --- a/src/convolutional_kernels.cu +++ b/src/convolutional_kernels.cu @@ -11,15 +11,15 @@ extern "C" { __global__ void bias_output_kernel(float *output, float *biases, int n, int size) { int offset = blockIdx.x * blockDim.x + threadIdx.x; - int filter = blockIdx.y % n; - int batch = blockIdx.y / n; + int filter = blockIdx.y; + int batch = blockIdx.z; if(offset < size) output[(batch*n+filter)*size + offset] = biases[filter]; } void bias_output_gpu(float *output, float *biases, int batch, int n, int size) { - dim3 dimGrid((size-1)/BLOCK + 1, n*batch, 1); + dim3 dimGrid((size-1)/BLOCK + 1, n, batch); dim3 dimBlock(BLOCK, 1, 1); bias_output_kernel<<>>(output, biases, n, size); diff --git a/src/data.c b/src/data.c index 70692487..c1167dad 100644 --- a/src/data.c +++ b/src/data.c @@ -66,6 +66,7 @@ matrix load_image_paths(char **paths, int n, int h, int w) typedef struct box{ int id; float x,y,w,h; + float left, right, top, bottom; } box; box *read_boxes(char *filename, int *n) @@ -83,6 +84,10 @@ box *read_boxes(char *filename, int *n) boxes[count].y = y; boxes[count].h = h; boxes[count].w = w; + boxes[count].left = x - w/2; + boxes[count].right = x + w/2; + boxes[count].top = y - h/2; + boxes[count].bottom = y + h/2; ++count; } fclose(file); diff --git a/src/image.c b/src/image.c index 174b24c4..2cfce634 100644 --- a/src/image.c +++ b/src/image.c @@ -395,6 +395,26 @@ image ipl_to_image(IplImage* src) return out; } +image crop_image(image im, int dr, int dc, int h, int w) +{ + image cropped = make_image(h, w, im.c); + int i, j, k; + for(k = 0; k < im.c; ++k){ + for(j = 0; j < h; ++j){ + for(i = 0; i < w; ++i){ + int r = j + dr; + int c = i + dc; + float val = 128; + if (r >= 0 && r < im.h && c >= 0 && c < im.w) { + val = get_pixel(im, r, c, k); + } + set_pixel(cropped, j, i, k, val); + } + } + } + return cropped; +} + // #wikipedia image resize_image(image im, int h, int w) { @@ -427,9 +447,13 @@ void test_resize(char *filename) image im = load_image(filename, 0,0); image small = resize_image(im, 63, 65); image big = resize_image(im, 512, 513); + image crop = crop_image(im, 10, 50, 100, 100); + image crop2 = crop_image(im, -50, -30, 400, 291); show_image(im, "original"); show_image(small, "smaller"); show_image(big, "bigger"); + show_image(crop, "crop"); + show_image(crop2, "crop2"); cvWaitKey(0); } diff --git a/src/imagenet.c b/src/imagenet.c index 9118c084..8a4ebcb3 100644 --- a/src/imagenet.c +++ b/src/imagenet.c @@ -38,6 +38,7 @@ void train_imagenet(char *cfgfile, char *weightfile) avg_loss = avg_loss*.9 + loss*.1; printf("%d: %f, %f avg, %lf seconds, %d images\n", i, loss, avg_loss, sec(clock()-time), net.seen); free_data(train); + //if(i%100 == 0 && net.learning_rate > .00001) net.learning_rate *= .97; if(i%100==0){ char buff[256]; sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i);