From 390a0cf923cee683e5be300390c736a2ab9b7fd5 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sat, 11 Apr 2015 08:24:07 +0000
Subject: [PATCH] not much changed...
---
src/image.c | 4 +-
src/detection.c | 9 ++--
src/activations.h | 4 +
src/connected_layer.c | 2
src/data.c | 4 --
src/activation_kernels.cu | 6 +++
src/crop_layer_kernels.cu | 46 ++++++++++++++++++++---
src/activations.c | 7 +++
8 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/src/activation_kernels.cu b/src/activation_kernels.cu
index 32c032c..fb1126e 100644
--- a/src/activation_kernels.cu
+++ b/src/activation_kernels.cu
@@ -6,6 +6,7 @@
__device__ float linear_activate_kernel(float x){return x;}
__device__ float logistic_activate_kernel(float x){return 1./(1. + exp(-x));}
__device__ float relu_activate_kernel(float x){return x*(x>0);}
+__device__ float relie_activate_kernel(float x){return x*(x>0);}
__device__ float ramp_activate_kernel(float x){return x*(x>0)+.1*x;}
__device__ float tanh_activate_kernel(float x){return (exp(2*x)-1)/(exp(2*x)+1);}
__device__ float plse_activate_kernel(float x)
@@ -18,6 +19,7 @@
__device__ float linear_gradient_kernel(float x){return 1;}
__device__ float logistic_gradient_kernel(float x){return (1-x)*x;}
__device__ float relu_gradient_kernel(float x){return (x>0);}
+__device__ float relie_gradient_kernel(float x){return (x>0) ? 1 : .01;}
__device__ float ramp_gradient_kernel(float x){return (x>0)+.1;}
__device__ float tanh_gradient_kernel(float x){return 1-x*x;}
__device__ float plse_gradient_kernel(float x){return (x < 0 || x > 1) ? .01 : .125;}
@@ -31,6 +33,8 @@
return logistic_activate_kernel(x);
case RELU:
return relu_activate_kernel(x);
+ case RELIE:
+ return relie_activate_kernel(x);
case RAMP:
return ramp_activate_kernel(x);
case TANH:
@@ -50,6 +54,8 @@
return logistic_gradient_kernel(x);
case RELU:
return relu_gradient_kernel(x);
+ case RELIE:
+ return relie_gradient_kernel(x);
case RAMP:
return ramp_gradient_kernel(x);
case TANH:
diff --git a/src/activations.c b/src/activations.c
index 20fc97b..8b607c2 100644
--- a/src/activations.c
+++ b/src/activations.c
@@ -12,6 +12,8 @@
return "logistic";
case RELU:
return "relu";
+ case RELIE:
+ return "relie";
case RAMP:
return "ramp";
case LINEAR:
@@ -30,6 +32,7 @@
{
if (strcmp(s, "logistic")==0) return LOGISTIC;
if (strcmp(s, "relu")==0) return RELU;
+ if (strcmp(s, "relie")==0) return RELIE;
if (strcmp(s, "plse")==0) return PLSE;
if (strcmp(s, "linear")==0) return LINEAR;
if (strcmp(s, "ramp")==0) return RAMP;
@@ -47,6 +50,8 @@
return logistic_activate(x);
case RELU:
return relu_activate(x);
+ case RELIE:
+ return relie_activate(x);
case RAMP:
return ramp_activate(x);
case TANH:
@@ -74,6 +79,8 @@
return logistic_gradient(x);
case RELU:
return relu_gradient(x);
+ case RELIE:
+ return relie_gradient(x);
case RAMP:
return ramp_gradient(x);
case TANH:
diff --git a/src/activations.h b/src/activations.h
index f28ac0d..07c5b5e 100644
--- a/src/activations.h
+++ b/src/activations.h
@@ -3,7 +3,7 @@
#define ACTIVATIONS_H
typedef enum{
- LOGISTIC, RELU, LINEAR, RAMP, TANH, PLSE
+ LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE
}ACTIVATION;
ACTIVATION get_activation(char *s);
@@ -21,6 +21,7 @@
static inline float linear_activate(float x){return x;}
static inline float logistic_activate(float x){return 1./(1. + exp(-x));}
static inline float relu_activate(float x){return x*(x>0);}
+static inline float relie_activate(float x){return x*(x>0);}
static inline float ramp_activate(float x){return x*(x>0)+.1*x;}
static inline float tanh_activate(float x){return (exp(2*x)-1)/(exp(2*x)+1);}
static inline float plse_activate(float x)
@@ -33,6 +34,7 @@
static inline float linear_gradient(float x){return 1;}
static inline float logistic_gradient(float x){return (1-x)*x;}
static inline float relu_gradient(float x){return (x>0);}
+static inline float relie_gradient(float x){return (x>0) ? 1 : .01;}
static inline float ramp_gradient(float x){return (x>0)+.1;}
static inline float tanh_gradient(float x){return 1-x*x;}
static inline float plse_gradient(float x){return (x < 0 || x > 1) ? .01 : .125;}
diff --git a/src/connected_layer.c b/src/connected_layer.c
index 1466ca4..4c40fc0 100644
--- a/src/connected_layer.c
+++ b/src/connected_layer.c
@@ -33,7 +33,7 @@
float scale = 1./sqrt(inputs);
for(i = 0; i < inputs*outputs; ++i){
- layer->weights[i] = scale*rand_normal();
+ //layer->weights[i] = scale*rand_normal();
}
for(i = 0; i < outputs; ++i){
diff --git a/src/crop_layer_kernels.cu b/src/crop_layer_kernels.cu
index 8c97f35..ca6bb20 100644
--- a/src/crop_layer_kernels.cu
+++ b/src/crop_layer_kernels.cu
@@ -1,15 +1,41 @@
extern "C" {
#include "crop_layer.h"
+#include "utils.h"
#include "cuda.h"
+#include "image.h"
}
#define BLOCK 256
-__global__ void forward_crop_layer_kernel(float *input, int size, int c, int h, int w, int crop_height, int crop_width, int dh, int dw, int flip, float *output)
+__device__ float get_pixel_kernel(float *image, int w, int h, int x, int y, int c)
+{
+ if(x < 0 || x >= w || y < 0 || y >= h) return 0;
+ return image[x + w*(y + c*h)];
+}
+
+__device__ float billinear_interpolate_kernel(float *image, int w, int h, float x, float y, int c)
+{
+ int ix = (int) floorf(x);
+ int iy = (int) floorf(y);
+
+ float dx = x - ix;
+ float dy = y - iy;
+
+ float val = (1-dy) * (1-dx) * get_pixel_kernel(image, w, h, ix, iy, c) +
+ dy * (1-dx) * get_pixel_kernel(image, w, h, ix, iy+1, c) +
+ (1-dy) * dx * get_pixel_kernel(image, w, h, ix+1, iy, c) +
+ dy * dx * get_pixel_kernel(image, w, h, ix+1, iy+1, c);
+ return val;
+}
+
+__global__ void forward_crop_layer_kernel(float *input, int size, int c, int h, int w, int crop_height, int crop_width, int dh, int dw, int flip, float angle, float *output)
{
int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
if(id >= size) return;
+ float cx = w/2.;
+ float cy = h/2.;
+
int count = id;
int j = id % crop_width;
id /= crop_width;
@@ -18,10 +44,16 @@
int k = id % c;
id /= c;
int b = id;
- int col = (flip) ? w - dw - j - 1 : j + dw;
- int row = i + dh;
- int index = col+w*(row+h*(k + c*b));
- output[count] = input[index];
+
+ input += w*h*c*b;
+
+ int x = (flip) ? w - dw - j - 1 : j + dw;
+ int y = i + dh;
+
+ float rx = cos(angle)*(x-cx) - sin(angle)*(y-cy) + cx;
+ float ry = sin(angle)*(x-cx) + cos(angle)*(y-cy) + cy;
+
+ output[count] = billinear_interpolate_kernel(input, w, h, rx, ry, k);
}
extern "C" void forward_crop_layer_gpu(crop_layer layer, network_state state)
@@ -29,7 +61,9 @@
int flip = (layer.flip && rand()%2);
int dh = rand()%(layer.h - layer.crop_height + 1);
int dw = rand()%(layer.w - layer.crop_width + 1);
+ float angle = rand_uniform() - .5;
if(!state.train){
+ angle = 0;
flip = 0;
dh = (layer.h - layer.crop_height)/2;
dw = (layer.w - layer.crop_width)/2;
@@ -40,7 +74,7 @@
dim3 dimGrid((size-1)/BLOCK + 1, 1, 1);
forward_crop_layer_kernel<<<cuda_gridsize(size), BLOCK>>>(state.input, size, layer.c, layer.h, layer.w,
- layer.crop_height, layer.crop_width, dh, dw, flip, layer.output_gpu);
+ layer.crop_height, layer.crop_width, dh, dw, flip, angle, layer.output_gpu);
check_error(cudaPeekAtLastError());
}
diff --git a/src/data.c b/src/data.c
index 34108f6..1ef2c40 100644
--- a/src/data.c
+++ b/src/data.c
@@ -59,10 +59,6 @@
image im = load_image_color(paths[i], w, h);
translate_image(im, -128);
scale_image(im, 1./128);
- float rad = rand_uniform() - .5;
- image rot = rotate_image(im, rad);
- free_image(im);
- im = rot;
X.vals[i] = im.data;
X.cols = im.h*im.w*im.c;
}
diff --git a/src/detection.c b/src/detection.c
index 1e24418..1cf9ef0 100644
--- a/src/detection.c
+++ b/src/detection.c
@@ -4,12 +4,12 @@
#include "parser.h"
-char *class_names[] = {"bg", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
+char *class_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
char *inet_class_names[] = {"bg", "accordion", "airplane", "ant", "antelope", "apple", "armadillo", "artichoke", "axe", "baby bed", "backpack", "bagel", "balance beam", "banana", "band aid", "banjo", "baseball", "basketball", "bathing cap", "beaker", "bear", "bee", "bell pepper", "bench", "bicycle", "binder", "bird", "bookshelf", "bow tie", "bow", "bowl", "brassiere", "burrito", "bus", "butterfly", "camel", "can opener", "car", "cart", "cattle", "cello", "centipede", "chain saw", "chair", "chime", "cocktail shaker", "coffee maker", "computer keyboard", "computer mouse", "corkscrew", "cream", "croquet ball", "crutch", "cucumber", "cup or mug", "diaper", "digital clock", "dishwasher", "dog", "domestic cat", "dragonfly", "drum", "dumbbell", "electric fan", "elephant", "face powder", "fig", "filing cabinet", "flower pot", "flute", "fox", "french horn", "frog", "frying pan", "giant panda", "goldfish", "golf ball", "golfcart", "guacamole", "guitar", "hair dryer", "hair spray", "hamburger", "hammer", "hamster", "harmonica", "harp", "hat with a wide brim", "head cabbage", "helmet", "hippopotamus", "horizontal bar", "horse", "hotdog", "iPod", "isopod", "jellyfish", "koala bear", "ladle", "ladybug", "lamp", "laptop", "lemon", "lion", "lipstick", "lizard", "lobster", "maillot", "maraca", "microphone", "microwave", "milk can", "miniskirt", "monkey", "motorcycle", "mushroom", "nail", "neck brace", "oboe", "orange", "otter", "pencil box", "pencil sharpener", "perfume", "person", "piano", "pineapple", "ping-pong ball", "pitcher", "pizza", "plastic bag", "plate rack", "pomegranate", "popsicle", "porcupine", "power drill", "pretzel", "printer", "puck", "punching bag", "purse", "rabbit", "racket", "ray", "red panda", "refrigerator", "remote control", "rubber eraser", "rugby ball", "ruler", "salt or pepper shaker", "saxophone", "scorpion", "screwdriver", "seal", "sheep", "ski", "skunk", "snail", "snake", "snowmobile", "snowplow", "soap dispenser", "soccer ball", "sofa", "spatula", "squirrel", "starfish", "stethoscope", "stove", "strainer", "strawberry", "stretcher", "sunglasses", "swimming trunks", "swine", "syringe", "table", "tape player", "tennis ball", "tick", "tie", "tiger", "toaster", "traffic light", "train", "trombone", "trumpet", "turtle", "tv or monitor", "unicycle", "vacuum", "violin", "volleyball", "waffle iron", "washer", "water bottle", "watercraft", "whale", "wine bottle", "zebra"};
#define AMNT 3
void draw_detection(image im, float *box, int side)
{
- int classes = 201;
+ int classes = 20;
int elems = 4+classes;
int j;
int r, c;
@@ -20,10 +20,10 @@
//printf("%d\n", j);
//printf("Prob: %f\n", box[j]);
int class = max_index(box+j, classes);
- if(box[j+class] > .02 || 1){
+ if(box[j+class] > .2){
//int z;
//for(z = 0; z < classes; ++z) printf("%f %s\n", box[j+z], class_names[z]);
- printf("%f %s\n", box[j+class], inet_class_names[class]);
+ printf("%f %s\n", box[j+class], class_names[class]);
float red = get_color(0,class,classes);
float green = get_color(1,class,classes);
float blue = get_color(2,class,classes);
@@ -178,7 +178,6 @@
}
}
}
-
time=clock();
free_data(val);
}
diff --git a/src/image.c b/src/image.c
index d85a054..49d4647 100644
--- a/src/image.c
+++ b/src/image.c
@@ -330,8 +330,8 @@
float billinear_interpolate(image im, float x, float y, int c)
{
- int ix = (int) x;
- int iy = (int) y;
+ int ix = (int) floorf(x);
+ int iy = (int) floorf(y);
float dx = x - ix;
float dy = y - iy;
--
Gitblit v1.10.0