[FFmpeg-devel] [PATCH] libavfilter/dnn_native: Add multiple activation functions in dnn native

Xuewei Meng xwmeng96 at gmail.com
Tue May 21 09:52:49 EEST 2019


Add "Leaky_relu" and "None" option in activation function.

Signed-off-by: Xuewei Meng <xwmeng96 at gmail.com>
---
 libavfilter/dnn_backend_native.c | 5 +++++
 libavfilter/dnn_backend_native.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn_backend_native.c b/libavfilter/dnn_backend_native.c
index fa3f20e4a2..3c8465a283 100644
--- a/libavfilter/dnn_backend_native.c
+++ b/libavfilter/dnn_backend_native.c
@@ -270,6 +270,11 @@ static void convolve(const float *input, float *output, const ConvolutionalParam
                     break;
                 case SIGMOID:
                     output[n_filter] = 1.0f / (1.0f + exp(-output[n_filter]));
+                    break;
+                case NONE:
+                    break;
+                case LEAKY_RELU:
+                    output[n_filter] = FFMAX(output[n_filter], 0.0) + 0.2 * FFMIN(output[n_filter], 0.0);
                 }
             }
             output += conv_params->output_num;
diff --git a/libavfilter/dnn_backend_native.h b/libavfilter/dnn_backend_native.h
index d70cd16387..7e4e943137 100644
--- a/libavfilter/dnn_backend_native.h
+++ b/libavfilter/dnn_backend_native.h
@@ -32,7 +32,7 @@
 
 typedef enum {INPUT, CONV, DEPTH_TO_SPACE} DNNLayerType;
 
-typedef enum {RELU, TANH, SIGMOID} DNNActivationFunc;
+typedef enum {RELU, TANH, SIGMOID, NONE, LEAKY_RELU} DNNActivationFunc;
 
 typedef enum {VALID, SAME, SAME_CLAMP_TO_EDGE} DNNConvPaddingParam;
 
-- 
2.17.1



More information about the ffmpeg-devel mailing list