| | |
| | | __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); |
| | |
| | | typedef struct box{ |
| | | int id; |
| | | float x,y,w,h; |
| | | float left, right, top, bottom; |
| | | } box; |
| | | |
| | | 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); |
| | |
| | | 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) |
| | | { |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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); |