Signed-off-by: Ting Fu
---
V2:
Fix the issue in V1: make fate failed
libavfilter/dnn/dnn_backend_native.c | 74 +++
libavfilter/dnn/dnn_backend_native.h | 5 ++
.../dnn/dnn_backend_native_layer_avgpool.c| 2 +-
.../dnn/dnn_backend_native_layer_avgpool.h| 2 +-
.../dnn/dnn_backend_native_layer_conv2d.c | 2 +-
.../dnn/dnn_backend_native_layer_conv2d.h | 2 +-
.../dnn_backend_native_layer_depth2space.c| 2 +-
.../dnn_backend_native_layer_depth2space.h| 2 +-
.../dnn/dnn_backend_native_layer_mathbinary.c | 10 ++-
.../dnn/dnn_backend_native_layer_mathbinary.h | 2 +-
.../dnn/dnn_backend_native_layer_mathunary.c | 10 ++-
.../dnn/dnn_backend_native_layer_mathunary.h | 2 +-
.../dnn/dnn_backend_native_layer_maximum.c| 2 +-
.../dnn/dnn_backend_native_layer_maximum.h| 2 +-
.../dnn/dnn_backend_native_layer_pad.c| 2 +-
.../dnn/dnn_backend_native_layer_pad.h| 2 +-
libavfilter/dnn/dnn_backend_native_layers.h | 2 +-
tests/dnn/dnn-layer-avgpool-test.c| 4 +-
tests/dnn/dnn-layer-conv2d-test.c | 4 +-
tests/dnn/dnn-layer-depth2space-test.c| 2 +-
tests/dnn/dnn-layer-mathbinary-test.c | 6 +-
tests/dnn/dnn-layer-mathunary-test.c | 2 +-
tests/dnn/dnn-layer-maximum-test.c| 2 +-
tests/dnn/dnn-layer-pad-test.c| 6 +-
24 files changed, 103 insertions(+), 48 deletions(-)
diff --git a/libavfilter/dnn/dnn_backend_native.c
b/libavfilter/dnn/dnn_backend_native.c
index adc652a2c4..6ddffa54af 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -28,15 +28,30 @@
#include "dnn_backend_native_layer_conv2d.h"
#include "dnn_backend_native_layers.h"
+static const AVClass dnn_native_class = {
+.class_name = "dnn_native",
+.item_name = av_default_item_name,
+.option = NULL,
+.version= LIBAVUTIL_VERSION_INT,
+.category = AV_CLASS_CATEGORY_FILTER,
+};
+
+NetworkContext network_ctx = {
+.class = &dnn_native_class,
+};
+
static DNNReturnType get_input_native(void *model, DNNData *input, const char
*input_name)
{
ConvolutionalNetwork *network = (ConvolutionalNetwork *)model;
+NetworkContext *ctx = network->log_ctx;
for (int i = 0; i < network->operands_num; ++i) {
DnnOperand *oprd = &network->operands[i];
if (strcmp(oprd->name, input_name) == 0) {
-if (oprd->type != DOT_INPUT)
+if (oprd->type != DOT_INPUT) {
+av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is
not input node\n", input_name);
return DNN_ERROR;
+}
input->dt = oprd->data_type;
av_assert0(oprd->dims[0] == 1);
input->height = oprd->dims[1];
@@ -47,30 +62,37 @@ static DNNReturnType get_input_native(void *model, DNNData
*input, const char *i
}
// do not find the input operand
+av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name);
return DNN_ERROR;
}
static DNNReturnType set_input_output_native(void *model, DNNData *input,
const char *input_name, const char **output_names, uint32_t nb_output)
{
ConvolutionalNetwork *network = (ConvolutionalNetwork *)model;
+NetworkContext *ctx = network->log_ctx;
DnnOperand *oprd = NULL;
-if (network->layers_num <= 0 || network->operands_num <= 0)
+if (network->layers_num <= 0 || network->operands_num <= 0) {
+av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n");
return DNN_ERROR;
+}
/* inputs */
for (int i = 0; i < network->operands_num; ++i) {
oprd = &network->operands[i];
if (strcmp(oprd->name, input_name) == 0) {
-if (oprd->type != DOT_INPUT)
+if (oprd->type != DOT_INPUT) {
+av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is
not input node\n", input_name);
return DNN_ERROR;
+}
break;
}
oprd = NULL;
}
-
-if (!oprd)
+if (!oprd) {
+av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n",
input_name);
return DNN_ERROR;
+}
oprd->dims[0] = 1;
oprd->dims[1] = input->height;
@@ -79,11 +101,15 @@ static DNNReturnType set_input_output_native(void *model,
DNNData *input, const
av_freep(&oprd->data);
oprd->length = calculate_operand_data_length(oprd);
-if (oprd->length <= 0)
+if (oprd->length <= 0) {
+av_log(ctx, AV_LOG_ERROR, "The input data length overflow\n");
return DNN_ERROR;
+}
oprd->data = av_malloc(oprd->length);
-if (!oprd->data)
+if (!oprd->data) {
+av_log(ctx, AV_LOG_ERROR, "Failed to malloc memory for input data\n");
return DNN_ERROR;
+}
input->data = oprd->data;
@@ -91,8 +117,10 @@ static DNNReturnType set_input_output_native(void *model,
DNND