activation_layer.c
Go to the documentation of this file.
00001 #include "activation_layer.h"
00002 #include "utils.h"
00003 #include "cuda.h"
00004 #include "blas.h"
00005 #include "gemm.h"
00006 
00007 #include <math.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 layer make_activation_layer(int batch, int inputs, ACTIVATION activation)
00013 {
00014     layer l = {0};
00015     l.type = ACTIVE;
00016 
00017     l.inputs = inputs;
00018     l.outputs = inputs;
00019     l.batch=batch;
00020 
00021     l.output = calloc(batch*inputs, sizeof(float*));
00022     l.delta = calloc(batch*inputs, sizeof(float*));
00023 
00024     l.forward = forward_activation_layer;
00025     l.backward = backward_activation_layer;
00026 #ifdef GPU
00027     l.forward_gpu = forward_activation_layer_gpu;
00028     l.backward_gpu = backward_activation_layer_gpu;
00029 
00030     l.output_gpu = cuda_make_array(l.output, inputs*batch);
00031     l.delta_gpu = cuda_make_array(l.delta, inputs*batch);
00032 #endif
00033     l.activation = activation;
00034     fprintf(stderr, "Activation Layer: %d inputs\n", inputs);
00035     return l;
00036 }
00037 
00038 void forward_activation_layer(layer l, network_state state)
00039 {
00040     copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1);
00041     activate_array(l.output, l.outputs*l.batch, l.activation);
00042 }
00043 
00044 void backward_activation_layer(layer l, network_state state)
00045 {
00046     gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);
00047     copy_cpu(l.outputs*l.batch, l.delta, 1, state.delta, 1);
00048 }
00049 
00050 #ifdef GPU
00051 
00052 void forward_activation_layer_gpu(layer l, network_state state)
00053 {
00054     copy_ongpu(l.outputs*l.batch, state.input, 1, l.output_gpu, 1);
00055     activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation);
00056 }
00057 
00058 void backward_activation_layer_gpu(layer l, network_state state)
00059 {
00060     gradient_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu);
00061     copy_ongpu(l.outputs*l.batch, l.delta_gpu, 1, state.delta, 1);
00062 }
00063 #endif


rail_object_detector
Author(s):
autogenerated on Sat Jun 8 2019 20:26:29