mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Working?
This commit is contained in:
35
src/softmax_layer.c
Normal file
35
src/softmax_layer.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "softmax_layer.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
softmax_layer *make_softmax_layer(int inputs)
|
||||
{
|
||||
printf("Softmax Layer: %d inputs\n", inputs);
|
||||
softmax_layer *layer = calloc(1, sizeof(softmax_layer));
|
||||
layer->inputs = inputs;
|
||||
layer->output = calloc(inputs, sizeof(double));
|
||||
layer->delta = calloc(inputs, sizeof(double));
|
||||
return layer;
|
||||
}
|
||||
|
||||
void forward_softmax_layer(const softmax_layer layer, double *input)
|
||||
{
|
||||
int i;
|
||||
double sum = 0;
|
||||
for(i = 0; i < layer.inputs; ++i){
|
||||
sum += exp(input[i]);
|
||||
}
|
||||
for(i = 0; i < layer.inputs; ++i){
|
||||
layer.output[i] = exp(input[i])/sum;
|
||||
}
|
||||
}
|
||||
|
||||
void backward_softmax_layer(const softmax_layer layer, double *input, double *delta)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < layer.inputs; ++i){
|
||||
delta[i] = layer.delta[i];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user