no comment

This commit is contained in:
Joseph Redmon 2015-03-29 19:31:47 -07:00
parent f98bf6bbdb
commit 6553b3f0e3
4 changed files with 33 additions and 3 deletions

View File

@ -11,15 +11,15 @@ extern "C" {
__global__ void bias_output_kernel(float *output, float *biases, int n, int size) __global__ void bias_output_kernel(float *output, float *biases, int n, int size)
{ {
int offset = blockIdx.x * blockDim.x + threadIdx.x; int offset = blockIdx.x * blockDim.x + threadIdx.x;
int filter = blockIdx.y % n; int filter = blockIdx.y;
int batch = blockIdx.y / n; int batch = blockIdx.z;
if(offset < size) output[(batch*n+filter)*size + offset] = biases[filter]; 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) 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); dim3 dimBlock(BLOCK, 1, 1);
bias_output_kernel<<<dimGrid, dimBlock>>>(output, biases, n, size); bias_output_kernel<<<dimGrid, dimBlock>>>(output, biases, n, size);

View File

@ -66,6 +66,7 @@ matrix load_image_paths(char **paths, int n, int h, int w)
typedef struct box{ typedef struct box{
int id; int id;
float x,y,w,h; float x,y,w,h;
float left, right, top, bottom;
} box; } box;
box *read_boxes(char *filename, int *n) box *read_boxes(char *filename, int *n)
@ -83,6 +84,10 @@ box *read_boxes(char *filename, int *n)
boxes[count].y = y; boxes[count].y = y;
boxes[count].h = h; boxes[count].h = h;
boxes[count].w = w; 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; ++count;
} }
fclose(file); fclose(file);

View File

@ -395,6 +395,26 @@ image ipl_to_image(IplImage* src)
return out; 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 // #wikipedia
image resize_image(image im, int h, int w) 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 im = load_image(filename, 0,0);
image small = resize_image(im, 63, 65); image small = resize_image(im, 63, 65);
image big = resize_image(im, 512, 513); 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(im, "original");
show_image(small, "smaller"); show_image(small, "smaller");
show_image(big, "bigger"); show_image(big, "bigger");
show_image(crop, "crop");
show_image(crop2, "crop2");
cvWaitKey(0); cvWaitKey(0);
} }

View File

@ -38,6 +38,7 @@ void train_imagenet(char *cfgfile, char *weightfile)
avg_loss = avg_loss*.9 + loss*.1; 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); printf("%d: %f, %f avg, %lf seconds, %d images\n", i, loss, avg_loss, sec(clock()-time), net.seen);
free_data(train); free_data(train);
//if(i%100 == 0 && net.learning_rate > .00001) net.learning_rate *= .97;
if(i%100==0){ if(i%100==0){
char buff[256]; char buff[256];
sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i); sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i);