|
|
@ -1,5 +1,6 @@ |
|
|
|
#include <assert.h> |
|
|
|
#include <assert.h> |
|
|
|
#include <math.h> |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
#include <algorithm> |
|
|
|
#include "commonmodel.h" |
|
|
|
#include "commonmodel.h" |
|
|
|
#include "common/clutil.h" |
|
|
|
#include "common/clutil.h" |
|
|
|
#include "common/mat.h" |
|
|
|
#include "common/mat.h" |
|
|
@ -48,18 +49,10 @@ void frame_free(ModelFrame* frame) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void softmax(const float* input, float* output, size_t len) { |
|
|
|
void softmax(const float* input, float* output, size_t len) { |
|
|
|
float max_val = -FLT_MAX; |
|
|
|
const float max_val = *std::max_element(input, input + len); |
|
|
|
for(int i = 0; i < len; i++) { |
|
|
|
|
|
|
|
const float v = input[i]; |
|
|
|
|
|
|
|
if( v > max_val ) { |
|
|
|
|
|
|
|
max_val = v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float denominator = 0; |
|
|
|
float denominator = 0; |
|
|
|
for(int i = 0; i < len; i++) { |
|
|
|
for(int i = 0; i < len; i++) { |
|
|
|
float const v = input[i]; |
|
|
|
float const v_exp = expf(input[i] - max_val); |
|
|
|
float const v_exp = expf(v - max_val); |
|
|
|
|
|
|
|
denominator += v_exp; |
|
|
|
denominator += v_exp; |
|
|
|
output[i] = v_exp; |
|
|
|
output[i] = v_exp; |
|
|
|
} |
|
|
|
} |
|
|
@ -68,7 +61,6 @@ void softmax(const float* input, float* output, size_t len) { |
|
|
|
for(int i = 0; i < len; i++) { |
|
|
|
for(int i = 0; i < len; i++) { |
|
|
|
output[i] *= inv_denominator; |
|
|
|
output[i] *= inv_denominator; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float sigmoid(float input) { |
|
|
|
float sigmoid(float input) { |
|
|
|