mirror of https://github.com/AlexeyAB/darknet.git
parent
9802287b58
commit
1578ec70d7
33 changed files with 850 additions and 175 deletions
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 160 KiB |
@ -0,0 +1,58 @@ |
|||||||
|
#include "activation_layer.h" |
||||||
|
#include "utils.h" |
||||||
|
#include "cuda.h" |
||||||
|
#include "blas.h" |
||||||
|
#include "gemm.h" |
||||||
|
|
||||||
|
#include <math.h> |
||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
|
||||||
|
layer make_activation_layer(int batch, int inputs, ACTIVATION activation) |
||||||
|
{ |
||||||
|
layer l = {0}; |
||||||
|
l.type = ACTIVE; |
||||||
|
|
||||||
|
l.inputs = inputs; |
||||||
|
l.outputs = inputs; |
||||||
|
l.batch=batch; |
||||||
|
|
||||||
|
l.output = calloc(batch*inputs, sizeof(float*)); |
||||||
|
l.delta = calloc(batch*inputs, sizeof(float*)); |
||||||
|
|
||||||
|
#ifdef GPU |
||||||
|
l.output_gpu = cuda_make_array(l.output, inputs*batch); |
||||||
|
l.delta_gpu = cuda_make_array(l.delta, inputs*batch); |
||||||
|
#endif |
||||||
|
l.activation = activation; |
||||||
|
fprintf(stderr, "Activation Layer: %d inputs\n", inputs); |
||||||
|
return l; |
||||||
|
} |
||||||
|
|
||||||
|
void forward_activation_layer(layer l, network_state state) |
||||||
|
{ |
||||||
|
copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1); |
||||||
|
activate_array(l.output, l.outputs*l.batch, l.activation); |
||||||
|
} |
||||||
|
|
||||||
|
void backward_activation_layer(layer l, network_state state) |
||||||
|
{ |
||||||
|
gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); |
||||||
|
copy_cpu(l.outputs*l.batch, l.delta, 1, state.delta, 1); |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef GPU |
||||||
|
|
||||||
|
void forward_activation_layer_gpu(layer l, network_state state) |
||||||
|
{ |
||||||
|
copy_ongpu(l.outputs*l.batch, state.input, 1, l.output_gpu, 1); |
||||||
|
activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation); |
||||||
|
} |
||||||
|
|
||||||
|
void backward_activation_layer_gpu(layer l, network_state state) |
||||||
|
{ |
||||||
|
gradient_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); |
||||||
|
copy_ongpu(l.outputs*l.batch, l.delta_gpu, 1, state.delta, 1); |
||||||
|
} |
||||||
|
#endif |
@ -0,0 +1,19 @@ |
|||||||
|
#ifndef ACTIVATION_LAYER_H |
||||||
|
#define ACTIVATION_LAYER_H |
||||||
|
|
||||||
|
#include "activations.h" |
||||||
|
#include "layer.h" |
||||||
|
#include "network.h" |
||||||
|
|
||||||
|
layer make_activation_layer(int batch, int inputs, ACTIVATION activation); |
||||||
|
|
||||||
|
void forward_activation_layer(layer l, network_state state); |
||||||
|
void backward_activation_layer(layer l, network_state state); |
||||||
|
|
||||||
|
#ifdef GPU |
||||||
|
void forward_activation_layer_gpu(layer l, network_state state); |
||||||
|
void backward_activation_layer_gpu(layer l, network_state state); |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
Loading…
Reference in new issue