From c592fc7491ac739587214eee0784801abfbba9df Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 27 Jan 2015 21:52:37 +0000
Subject: [PATCH] New name: Darknet
---
src/crop_layer.c | 41 ++++++++++++++++++++---------------------
1 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/crop_layer.c b/src/crop_layer.c
index 58e1b55..df6eb41 100644
--- a/src/crop_layer.c
+++ b/src/crop_layer.c
@@ -1,4 +1,5 @@
#include "crop_layer.h"
+#include "cuda.h"
#include <stdio.h>
image get_crop_image(crop_layer layer)
@@ -21,34 +22,32 @@
layer->crop_width = crop_width;
layer->crop_height = crop_height;
layer->output = calloc(crop_width*crop_height * c*batch, sizeof(float));
- layer->delta = calloc(crop_width*crop_height * c*batch, sizeof(float));
+ #ifdef GPU
+ layer->output_gpu = cuda_make_array(layer->output, crop_width*crop_height*c*batch);
+ #endif
return layer;
}
+
void forward_crop_layer(const crop_layer layer, float *input)
{
- int i,j,c,b;
+ int i,j,c,b,row,col;
+ int index;
+ int count = 0;
+ int flip = (layer.flip && rand()%2);
int dh = rand()%(layer.h - layer.crop_height);
int dw = rand()%(layer.w - layer.crop_width);
- int count = 0;
- if(layer.flip && rand()%2){
- for(b = 0; b < layer.batch; ++b){
- for(c = 0; c < layer.c; ++c){
- for(i = dh; i < dh+layer.crop_height; ++i){
- for(j = dw+layer.crop_width-1; j >= dw; --j){
- int index = j+layer.w*(i+layer.h*(c + layer.c*b));
- layer.output[count++] = input[index];
+ for(b = 0; b < layer.batch; ++b){
+ for(c = 0; c < layer.c; ++c){
+ for(i = 0; i < layer.crop_height; ++i){
+ for(j = 0; j < layer.crop_width; ++j){
+ if(flip){
+ col = layer.w - dw - j - 1;
+ }else{
+ col = j + dw;
}
- }
- }
- }
- }else{
- for(b = 0; b < layer.batch; ++b){
- for(c = 0; c < layer.c; ++c){
- for(i = dh; i < dh+layer.crop_height; ++i){
- for(j = dw; j < dw+layer.crop_width; ++j){
- int index = j+layer.w*(i+layer.h*(c + layer.c*b));
- layer.output[count++] = input[index];
- }
+ row = i + dh;
+ index = col+layer.w*(row+layer.h*(c + layer.c*b));
+ layer.output[count++] = input[index];
}
}
}
--
Gitblit v1.10.0