not much changed...

This commit is contained in:
Joseph Redmon 2015-04-11 01:24:07 -07:00
parent 5a49c1d962
commit 390a0cf923
8 changed files with 63 additions and 19 deletions

View File

@ -6,6 +6,7 @@ extern "C" {
__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 plse_activate_kernel(float x)
__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 @@ __device__ float activate_kernel(float x, ACTIVATION a)
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 @@ __device__ float gradient_kernel(float x, ACTIVATION a)
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:

View File

@ -12,6 +12,8 @@ char *get_activation_string(ACTIVATION a)
return "logistic";
case RELU:
return "relu";
case RELIE:
return "relie";
case RAMP:
return "ramp";
case LINEAR:
@ -30,6 +32,7 @@ ACTIVATION get_activation(char *s)
{
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 @@ float activate(float x, ACTIVATION a)
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 @@ float gradient(float x, ACTIVATION a)
return logistic_gradient(x);
case RELU:
return relu_gradient(x);
case RELIE:
return relie_gradient(x);
case RAMP:
return ramp_gradient(x);
case TANH:

View File

@ -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 @@ void gradient_array_ongpu(float *x, int n, ACTIVATION a, float *delta);
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 plse_activate(float x)
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;}

View File

@ -33,7 +33,7 @@ connected_layer *make_connected_layer(int batch, int inputs, int outputs, ACTIVA
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){

View File

@ -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 @@ __global__ void forward_crop_layer_kernel(float *input, int size, int c, int h,
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 @@ extern "C" void forward_crop_layer_gpu(crop_layer layer, network_state state)
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 @@ extern "C" void forward_crop_layer_gpu(crop_layer layer, network_state state)
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());
}

View File

@ -59,10 +59,6 @@ matrix load_image_paths(char **paths, int n, int w, int h)
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;
}

View File

@ -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 @@ void draw_detection(image im, float *box, int side)
//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 @@ void validate_detection(char *cfgfile, char *weightfile)
}
}
}
time=clock();
free_data(val);
}

View File

@ -330,8 +330,8 @@ image crop_image(image im, int dx, int dy, int w, int h)
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;