History

dnn/native: add log error message

Ting Fu committed 6 years ago

Commit c8ba0da1 parent 230cf9d24 files · +122 −52Browse files

Showing the changes to libavfilter (17 of 24 files). Show all

Unified · Split

17 files
  1. libavfilter/dnn/dnn_backend_native.c +44 −11
  2. libavfilter/dnn/dnn_backend_native.h +5 −0
  3. libavfilter/dnn/dnn_backend_native_layer_avgpool.c +8 −2
  4. libavfilter/dnn/dnn_backend_native_layer_avgpool.h +1 −1
  5. libavfilter/dnn/dnn_backend_native_layer_conv2d.c +7 −3
  6. libavfilter/dnn/dnn_backend_native_layer_conv2d.h +1 −1
  7. libavfilter/dnn/dnn_backend_native_layer_depth2space.c +7 −3
  8. libavfilter/dnn/dnn_backend_native_layer_depth2space.h +1 −1
  9. libavfilter/dnn/dnn_backend_native_layer_mathbinary.c +8 −3
  10. libavfilter/dnn/dnn_backend_native_layer_mathbinary.h +1 −1
  11. libavfilter/dnn/dnn_backend_native_layer_mathunary.c +8 −3
  12. libavfilter/dnn/dnn_backend_native_layer_mathunary.h +1 −1
  13. libavfilter/dnn/dnn_backend_native_layer_maximum.c +7 −3
  14. libavfilter/dnn/dnn_backend_native_layer_maximum.h +1 −1
  15. libavfilter/dnn/dnn_backend_native_layer_pad.c +7 −3
  16. libavfilter/dnn/dnn_backend_native_layer_pad.h +1 −1
  17. libavfilter/dnn/dnn_backend_native_layers.h +1 −1
libavfilter/dnn/dnn_backend_native.c+44−11
@@ -28,15 +28,26 @@ · 27 unmodified lines
2828 #include "dnn_backend_native_layer_conv2d.h"
2929 #include "dnn_backend_native_layers.h"
3030
31+static const AVClass dnn_native_class = {
32+ .class_name = "dnn_native",
33+ .item_name = av_default_item_name,
34+ .option = NULL,
35+ .version = LIBAVUTIL_VERSION_INT,
36+ .category = AV_CLASS_CATEGORY_FILTER,
37+};
38+
3139 static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name)
3240 {
3341 NativeModel *native_model = (NativeModel *)model;
42+ NativeContext *ctx = &native_model->ctx;
3443
3544 for (int i = 0; i < native_model->operands_num; ++i) {
3645 DnnOperand *oprd = &native_model->operands[i];
3746 if (strcmp(oprd->name, input_name) == 0) {
38− if (oprd->type != DOT_INPUT)
47+ if (oprd->type != DOT_INPUT) {
48+ av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", input_name);
3949 return DNN_ERROR;
50+ }
4051 input->dt = oprd->data_type;
4152 av_assert0(oprd->dims[0] == 1);
4253 input->height = oprd->dims[1];
@@ -47,30 +58,37 @@ static DNNReturnType get_input_native(void *model, DNNData *input, const char *i · 4 unmodified lines
4758 }
4859
4960 // do not find the input operand
61+ av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name);
5062 return DNN_ERROR;
5163 }
5264
5365 static DNNReturnType set_input_native(void *model, DNNData *input, const char *input_name)
5466 {
5567 NativeModel *native_model = (NativeModel *)model;
68+ NativeContext *ctx = &native_model->ctx;
5669 DnnOperand *oprd = NULL;
5770
58− if (native_model->layers_num <= 0 || native_model->operands_num <= 0)
71+ if (native_model->layers_num <= 0 || native_model->operands_num <= 0) {
72+ av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n");
5973 return DNN_ERROR;
74+ }
6075
6176 /* inputs */
6277 for (int i = 0; i < native_model->operands_num; ++i) {
6378 oprd = &native_model->operands[i];
6479 if (strcmp(oprd->name, input_name) == 0) {
65− if (oprd->type != DOT_INPUT)
80+ if (oprd->type != DOT_INPUT) {
81+ av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", input_name);
6682 return DNN_ERROR;
83+ }
6784 break;
6885 }
6986 oprd = NULL;
7087 }
71−
72− if (!oprd)
88+ if (!oprd) {
89+ av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name);
7390 return DNN_ERROR;
91+ }
7492
7593 oprd->dims[0] = 1;
7694 oprd->dims[1] = input->height;
@@ -79,11 +97,15 @@ static DNNReturnType set_input_native(void *model, DNNData *input, const char *i · 2 unmodified lines
7997
8098 av_freep(&oprd->data);
8199 oprd->length = calculate_operand_data_length(oprd);
82− if (oprd->length <= 0)
100+ if (oprd->length <= 0) {
101+ av_log(ctx, AV_LOG_ERROR, "The input data length overflow\n");
83102 return DNN_ERROR;
103+ }
84104 oprd->data = av_malloc(oprd->length);
85− if (!oprd->data)
105+ if (!oprd->data) {
106+ av_log(ctx, AV_LOG_ERROR, "Failed to malloc memory for input data\n");
86107 return DNN_ERROR;
108+ }
87109
88110 input->data = oprd->data;
89111
@@ -150,6 +172,8 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio · 60 unmodified lines
150172 if (!native_model){
151173 goto fail;
152174 }
175+
176+ native_model->ctx.class = &dnn_native_class;
153177 model->model = (void *)native_model;
154178
155179 avio_seek(model_file_context, file_size - 8, SEEK_SET);
@@ -237,19 +261,26 @@ fail: · 81 unmodified lines
237261 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output)
238262 {
239263 NativeModel *native_model = (NativeModel *)model->model;
264+ NativeContext *ctx = &native_model->ctx;
240265 int32_t layer;
241266
242− if (native_model->layers_num <= 0 || native_model->operands_num <= 0)
267+ if (native_model->layers_num <= 0 || native_model->operands_num <= 0) {
268+ av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n");
243269 return DNN_ERROR;
244− if (!native_model->operands[0].data)
270+ }
271+ if (!native_model->operands[0].data) {
272+ av_log(ctx, AV_LOG_ERROR, "Empty model input data\n");
245273 return DNN_ERROR;
274+ }
246275
247276 for (layer = 0; layer < native_model->layers_num; ++layer){
248277 DNNLayerType layer_type = native_model->layers[layer].type;
249278 if (layer_funcs[layer_type].pf_exec(native_model->operands,
250279 native_model->layers[layer].input_operand_indexes,
251280 native_model->layers[layer].output_operand_index,
252− native_model->layers[layer].params) == DNN_ERROR) {
281+ native_model->layers[layer].params,
282+ &native_model->ctx) == DNN_ERROR) {
283+ av_log(ctx, AV_LOG_ERROR, "Failed to execuet model\n");
253284 return DNN_ERROR;
254285 }
255286 }
@@ -264,8 +295,10 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output · 8 unmodified lines
264295 }
265296 }
266297
267− if (oprd == NULL)
298+ if (oprd == NULL) {
299+ av_log(ctx, AV_LOG_ERROR, "Could not find output in model\n");
268300 return DNN_ERROR;
301+ }
269302
270303 outputs[i].data = oprd->data;
271304 outputs[i].height = oprd->dims[1];
libavfilter/dnn/dnn_backend_native.h+5−0
@@ -106,8 +106,13 @@ typedef struct InputParams{ · 105 unmodified lines
106106 int height, width, channels;
107107 } InputParams;
108108
109+typedef struct NativeContext {
110+ const AVClass *class;
111+} NativeContext;
112+
109113 // Represents simple feed-forward convolutional network.
110114 typedef struct NativeModel{
115+ NativeContext ctx;
111116 Layer *layers;
112117 int32_t layers_num;
113118 DnnOperand *operands;
libavfilter/dnn/dnn_backend_native_layer_avgpool.c+8−2
@@ -56,7 +56,7 @@ int dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int f · 55 unmodified lines
5656 }
5757
5858 int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes,
59− int32_t output_operand_index, const void *parameters)
59+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
6060 {
6161 float *output;
6262 int height_end, width_end, height_radius, width_radius, output_height, output_width, kernel_area;
@@ -107,9 +107,15 @@ int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operan · 44 unmodified lines
107107 output_operand->dims[3] = channel;
108108 output_operand->data_type = operands[input_operand_index].data_type;
109109 output_operand->length = calculate_operand_data_length(output_operand);
110+ if (output_operand->length <= 0) {
111+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
112+ return DNN_ERROR;
113+ }
110114 output_operand->data = av_realloc(output_operand->data, output_operand->length);
111− if (!output_operand->data)
115+ if (!output_operand->data) {
116+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
112117 return DNN_ERROR;
118+ }
113119 output = output_operand->data;
114120
115121 for (int y = 0; y < height_end; y += kernel_strides) {
libavfilter/dnn/dnn_backend_native_layer_avgpool.h+1−1
@@ -35,6 +35,6 @@ typedef struct AvgPoolParams{ · 34 unmodified lines
3535
3636 int dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
3737 int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes,
38− int32_t output_operand_index, const void *parameters);
38+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
3939
4040 #endif
libavfilter/dnn/dnn_backend_native_layer_conv2d.c+7−3
@@ -89,7 +89,7 @@ int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int fil · 88 unmodified lines
8989 }
9090
9191 int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes,
92− int32_t output_operand_index, const void *parameters)
92+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
9393 {
9494 float *output;
9595 int32_t input_operand_index = input_operand_indexes[0];
@@ -113,11 +113,15 @@ int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_ · 17 unmodified lines
113113 output_operand->dims[3] = conv_params->output_num;
114114 output_operand->data_type = operands[input_operand_index].data_type;
115115 output_operand->length = calculate_operand_data_length(output_operand);
116− if (output_operand->length <= 0)
116+ if (output_operand->length <= 0) {
117+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
117118 return DNN_ERROR;
119+ }
118120 output_operand->data = av_realloc(output_operand->data, output_operand->length);
119− if (!output_operand->data)
121+ if (!output_operand->data) {
122+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
120123 return DNN_ERROR;
124+ }
121125 output = output_operand->data;
122126
123127 av_assert0(channel == conv_params->input_num);
libavfilter/dnn/dnn_backend_native_layer_conv2d.h+1−1
@@ -37,5 +37,5 @@ typedef struct ConvolutionalParams{ · 36 unmodified lines
3737
3838 int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
3939 int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes,
40− int32_t output_operand_index, const void *parameters);
40+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
4141 #endif
libavfilter/dnn/dnn_backend_native_layer_depth2space.c+7−3
@@ -50,7 +50,7 @@ int dnn_load_layer_depth2space(Layer *layer, AVIOContext *model_file_context, in · 49 unmodified lines
5050 }
5151
5252 int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes,
53− int32_t output_operand_index, const void *parameters)
53+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
5454 {
5555 float *output;
5656 const DepthToSpaceParams *params = (const DepthToSpaceParams *)parameters;
@@ -75,11 +75,15 @@ int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_ope · 18 unmodified lines
7575 output_operand->dims[3] = new_channels;
7676 output_operand->data_type = operands[input_operand_index].data_type;
7777 output_operand->length = calculate_operand_data_length(output_operand);
78− if (output_operand->length <= 0)
78+ if (output_operand->length <= 0) {
79+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
7980 return DNN_ERROR;
81+ }
8082 output_operand->data = av_realloc(output_operand->data, output_operand->length);
81− if (!output_operand->data)
83+ if (!output_operand->data) {
84+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
8285 return DNN_ERROR;
86+ }
8387 output = output_operand->data;
8488
8589 for (y = 0; y < height; ++y){
libavfilter/dnn/dnn_backend_native_layer_depth2space.h+1−1
@@ -36,6 +36,6 @@ typedef struct DepthToSpaceParams{ · 35 unmodified lines
3636
3737 int dnn_load_layer_depth2space(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
3838 int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes,
39− int32_t output_operand_index, const void *parameters);
39+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
4040
4141 #endif
libavfilter/dnn/dnn_backend_native_layer_mathbinary.c+8−3
@@ -149,7 +149,7 @@ int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, in · 148 unmodified lines
149149 }
150150
151151 int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_operand_indexes,
152− int32_t output_operand_index, const void *parameters)
152+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
153153 {
154154 const DnnOperand *input = &operands[input_operand_indexes[0]];
155155 DnnOperand *output = &operands[output_operand_index];
@@ -160,11 +160,15 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_ope · 4 unmodified lines
160160
161161 output->data_type = input->data_type;
162162 output->length = calculate_operand_data_length(output);
163− if (output->length <= 0)
163+ if (output->length <= 0) {
164+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
164165 return DNN_ERROR;
166+ }
165167 output->data = av_realloc(output->data, output->length);
166− if (!output->data)
168+ if (!output->data) {
169+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
167170 return DNN_ERROR;
171+ }
168172
169173 switch (params->bin_op) {
170174 case DMBO_SUB:
@@ -186,6 +190,7 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_ope · 15 unmodified lines
186190 math_binary_not_commutative(floormod, params, input, output, operands, input_operand_indexes);
187191 return 0;
188192 default:
193+ av_log(ctx, AV_LOG_ERROR, "Unmatch math binary operator\n");
189194 return DNN_ERROR;
190195 }
191196 }
libavfilter/dnn/dnn_backend_native_layer_mathbinary.h+1−1
@@ -49,6 +49,6 @@ typedef struct DnnLayerMathBinaryParams{ · 48 unmodified lines
4949
5050 int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
5151 int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_operand_indexes,
52− int32_t output_operand_index, const void *parameters);
52+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
5353
5454 #endif
libavfilter/dnn/dnn_backend_native_layer_mathunary.c+8−3
@@ -53,7 +53,7 @@ int dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context, int · 52 unmodified lines
5353 }
5454
5555 int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes,
56− int32_t output_operand_index, const void *parameters)
56+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
5757 {
5858 const DnnOperand *input = &operands[input_operand_indexes[0]];
5959 DnnOperand *output = &operands[output_operand_index];
@@ -67,11 +67,15 @@ int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_oper · 7 unmodified lines
6767
6868 output->data_type = input->data_type;
6969 output->length = calculate_operand_data_length(output);
70− if (output->length <= 0)
70+ if (output->length <= 0) {
71+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
7172 return DNN_ERROR;
73+ }
7274 output->data = av_realloc(output->data, output->length);
73− if (!output->data)
75+ if (!output->data) {
76+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
7477 return DNN_ERROR;
78+ }
7579
7680 dims_count = calculate_operand_dims_count(output);
7781 src = input->data;
@@ -143,6 +147,7 @@ int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_oper · 65 unmodified lines
143147 dst[i] = round(src[i]);
144148 return 0;
145149 default:
150+ av_log(ctx, AV_LOG_ERROR, "Unmatch math unary operator\n");
146151 return DNN_ERROR;
147152 }
148153 }
libavfilter/dnn/dnn_backend_native_layer_mathunary.h+1−1
@@ -55,6 +55,6 @@ typedef struct DnnLayerMathUnaryParams{ · 54 unmodified lines
5555
5656 int dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
5757 int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes,
58− int32_t output_operand_index, const void *parameters);
58+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
5959
6060 #endif
libavfilter/dnn/dnn_backend_native_layer_maximum.c+7−3
@@ -50,7 +50,7 @@ int dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int fi · 49 unmodified lines
5050 }
5151
5252 int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes,
53− int32_t output_operand_index, const void *parameters)
53+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
5454 {
5555 const DnnOperand *input = &operands[input_operand_indexes[0]];
5656 DnnOperand *output = &operands[output_operand_index];
@@ -64,11 +64,15 @@ int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand · 7 unmodified lines
6464
6565 output->data_type = input->data_type;
6666 output->length = calculate_operand_data_length(output);
67− if (output->length <= 0)
67+ if (output->length <= 0) {
68+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
6869 return DNN_ERROR;
70+ }
6971 output->data = av_realloc(output->data, output->length);
70− if (!output->data)
72+ if (!output->data) {
73+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
7174 return DNN_ERROR;
75+ }
7276
7377 dims_count = calculate_operand_dims_count(output);
7478 src = input->data;
libavfilter/dnn/dnn_backend_native_layer_maximum.h+1−1
@@ -39,6 +39,6 @@ typedef struct DnnLayerMaximumParams{ · 38 unmodified lines
3939
4040 int dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
4141 int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes,
42− int32_t output_operand_index, const void *parameters);
42+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
4343
4444 #endif
libavfilter/dnn/dnn_backend_native_layer_pad.c+7−3
@@ -76,7 +76,7 @@ static int after_get_buddy(int given, int border, LayerPadModeParam mode) · 75 unmodified lines
7676 }
7777
7878 int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_indexes,
79− int32_t output_operand_index, const void *parameters)
79+ int32_t output_operand_index, const void *parameters, NativeContext *ctx)
8080 {
8181 int32_t before_paddings;
8282 int32_t after_paddings;
@@ -111,11 +111,15 @@ int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_ind · 28 unmodified lines
111111 output_operand->dims[3] = new_channel;
112112 output_operand->data_type = operands[input_operand_index].data_type;
113113 output_operand->length = calculate_operand_data_length(output_operand);
114− if (output_operand->length <= 0)
114+ if (output_operand->length <= 0) {
115+ av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
115116 return DNN_ERROR;
117+ }
116118 output_operand->data = av_realloc(output_operand->data, output_operand->length);
117− if (!output_operand->data)
119+ if (!output_operand->data) {
120+ av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
118121 return DNN_ERROR;
122+ }
119123 output = output_operand->data;
120124
121125 // copy the original data
libavfilter/dnn/dnn_backend_native_layer_pad.h+1−1
@@ -38,6 +38,6 @@ typedef struct LayerPadParams{ · 37 unmodified lines
3838
3939 int dnn_load_layer_pad(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
4040 int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_indexes,
41− int32_t output_operand_index, const void *parameters);
41+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
4242
4343 #endif
libavfilter/dnn/dnn_backend_native_layers.h+1−1
@@ -25,7 +25,7 @@ · 24 unmodified lines
2525 #include "dnn_backend_native.h"
2626
2727 typedef int (*LAYER_EXEC_FUNC)(DnnOperand *operands, const int32_t *input_operand_indexes,
28− int32_t output_operand_index, const void *parameters);
28+ int32_t output_operand_index, const void *parameters, NativeContext *ctx);
2929 typedef int (*LAYER_LOAD_FUNC)(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num);
3030
3131 typedef struct LayerFunc {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t