Joseph Redmon
2015-03-30 6553b3f0e3e55fc30a99c7d4b5798aa86d18a114
no comment
4 files modified
36 ■■■■■ changed files
src/convolutional_kernels.cu 6 ●●●● patch | view | raw | blame | history
src/data.c 5 ●●●●● patch | view | raw | blame | history
src/image.c 24 ●●●●● patch | view | raw | blame | history
src/imagenet.c 1 ●●●● patch | view | raw | blame | history
src/convolutional_kernels.cu
@@ -11,15 +11,15 @@
__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<<<dimGrid, dimBlock>>>(output, biases, n, size);
src/data.c
@@ -66,6 +66,7 @@
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 @@
        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);
src/image.c
@@ -395,6 +395,26 @@
    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 @@
    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);
}
src/imagenet.c
@@ -38,6 +38,7 @@
        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);