Skip to content

Commit

Permalink
so much need to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed May 6, 2016
1 parent 0dff437 commit c7b10ce
Show file tree
Hide file tree
Showing 37 changed files with 1,496 additions and 432 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GPU=1
OPENCV=1
GPU=0
OPENCV=0
DEBUG=0

ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20
Expand All @@ -11,7 +11,7 @@ OBJDIR=./obj/
CC=gcc
NVCC=nvcc
OPTS=-Ofast
LDFLAGS= -lm -pthread -lstdc++
LDFLAGS= -lm -pthread
COMMON=
CFLAGS=-Wall -Wfatal-errors

Expand All @@ -34,8 +34,9 @@ CFLAGS+= -DGPU
LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
endif

OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o rnn.o rnn_vid.o crnn_layer.o coco_demo.o tag.o cifar.o yolo_demo.o go.o
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o coco_demo.o tag.o cifar.o yolo_demo.o go.o batchnorm_layer.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
OBJ+=convolutional_kernels.o deconvolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o softmax_layer_kernels.o network_kernels.o avgpool_layer_kernels.o
endif

Expand Down
32 changes: 14 additions & 18 deletions cfg/darknet.cfg
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
[net]
batch=128
subdivisions=1
height=256
width=256
height=224
width=224
channels=3
momentum=0.9
decay=0.0005
max_crop=320

learning_rate=0.01
policy=sigmoid
gamma=.00002
step=400000
max_batches=800000

[crop]
crop_height=224
crop_width=224
flip=1
angle=0
saturation=1
exposure=1
learning_rate=0.1
policy=poly
power=4
max_batches=500000

[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
Expand All @@ -33,6 +26,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
Expand All @@ -44,6 +38,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
Expand All @@ -55,6 +50,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
Expand All @@ -66,6 +62,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
Expand All @@ -77,6 +74,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
Expand All @@ -88,6 +86,7 @@ size=2
stride=2

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
Expand All @@ -96,9 +95,6 @@ activation=leaky

[avgpool]

[dropout]
probability=.5

[connected]
output=1000
activation=leaky
Expand Down
17 changes: 16 additions & 1 deletion src/activation_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ __device__ float elu_activate_kernel(float x){return (x >= 0)*x + (x < 0)*(exp(x
__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 leaky_activate_kernel(float x){return (x>0) ? x : .1*x;}
__device__ float tanh_activate_kernel(float x){return (exp(2*x)-1)/(exp(2*x)+1);}
__device__ float tanh_activate_kernel(float x){return (2/(1 + exp(-2*x)) - 1);}
__device__ float plse_activate_kernel(float x)
{
if(x < -4) return .01 * (x + 4);
if(x > 4) return .01 * (x - 4) + 1;
return .125*x + .5;
}
__device__ float stair_activate_kernel(float x)
{
int n = floor(x);
if (n%2 == 0) return floor(x/2.);
else return (x - n) + floor(x/2.);
}

__device__ float linear_gradient_kernel(float x){return 1;}
__device__ float logistic_gradient_kernel(float x){return (1-x)*x;}
Expand All @@ -37,6 +43,11 @@ __device__ float ramp_gradient_kernel(float x){return (x>0)+.1;}
__device__ float leaky_gradient_kernel(float x){return (x>0) ? 1 : .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;}
__device__ float stair_gradient_kernel(float x)
{
if (floor(x) == x) return 0;
return 1;
}

__device__ float activate_kernel(float x, ACTIVATION a)
{
Expand All @@ -61,6 +72,8 @@ __device__ float activate_kernel(float x, ACTIVATION a)
return tanh_activate_kernel(x);
case PLSE:
return plse_activate_kernel(x);
case STAIR:
return stair_activate_kernel(x);
}
return 0;
}
Expand Down Expand Up @@ -88,6 +101,8 @@ __device__ float gradient_kernel(float x, ACTIVATION a)
return tanh_gradient_kernel(x);
case PLSE:
return plse_gradient_kernel(x);
case STAIR:
return stair_gradient_kernel(x);
}
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions src/activations.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ char *get_activation_string(ACTIVATION a)
return "plse";
case LEAKY:
return "leaky";
case STAIR:
return "stair";
default:
break;
}
Expand All @@ -46,6 +48,7 @@ ACTIVATION get_activation(char *s)
if (strcmp(s, "ramp")==0) return RAMP;
if (strcmp(s, "leaky")==0) return LEAKY;
if (strcmp(s, "tanh")==0) return TANH;
if (strcmp(s, "stair")==0) return STAIR;
fprintf(stderr, "Couldn't find activation function %s, going with ReLU\n", s);
return RELU;
}
Expand Down Expand Up @@ -73,6 +76,8 @@ float activate(float x, ACTIVATION a)
return tanh_activate(x);
case PLSE:
return plse_activate(x);
case STAIR:
return stair_activate(x);
}
return 0;
}
Expand Down Expand Up @@ -108,6 +113,8 @@ float gradient(float x, ACTIVATION a)
return tanh_gradient(x);
case PLSE:
return plse_gradient(x);
case STAIR:
return stair_gradient(x);
}
return 0;
}
Expand Down
13 changes: 12 additions & 1 deletion src/activations.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "math.h"

typedef enum{
LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY
LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR
}ACTIVATION;

ACTIVATION get_activation(char *s);
Expand All @@ -19,6 +19,12 @@ void activate_array_ongpu(float *x, int n, ACTIVATION a);
void gradient_array_ongpu(float *x, int n, ACTIVATION a, float *delta);
#endif

static inline float stair_activate(float x)
{
int n = floor(x);
if (n%2 == 0) return floor(x/2.);
else return (x - n) + floor(x/2.);
}
static inline float linear_activate(float x){return x;}
static inline float logistic_activate(float x){return 1./(1. + exp(-x));}
static inline float loggy_activate(float x){return 2./(1. + exp(-x)) - 1;}
Expand All @@ -42,6 +48,11 @@ static inline float loggy_gradient(float x)
float y = (x+1.)/2.;
return 2*(1-y)*y;
}
static inline float stair_gradient(float x)
{
if (floor(x) == x) return 0;
return 1;
}
static inline float relu_gradient(float x){return (x>0);}
static inline float elu_gradient(float x){return (x >= 0) + (x < 0)*(x + 1);}
static inline float relie_gradient(float x){return (x>0) ? 1 : .01;}
Expand Down
Loading

0 comments on commit c7b10ce

Please sign in to comment.