| @@ -25,6 +25,7 @@ · 24 unmodified lines |
| 25 | 25 | |
| 26 | 26 | #include "dnn_backend_native.h" |
| 27 | 27 | #include "libavutil/avassert.h" |
| 28 | +#include "dnn_backend_native_layer_pad.h" |
| 28 | 29 | |
| 29 | 30 | static DNNReturnType set_input_output_native(void *model, DNNInputData *input, const char *input_name, const char **output_names, uint32_t nb_output) |
| 30 | 31 | { |
| @@ -32,6 +33,7 @@ static DNNReturnType set_input_output_native(void *model, DNNInputData *input, c · 1 unmodified line |
| 32 | 33 | InputParams *input_params; |
| 33 | 34 | ConvolutionalParams *conv_params; |
| 34 | 35 | DepthToSpaceParams *depth_to_space_params; |
| 36 | + LayerPadParams *pad_params; |
| 35 | 37 | int cur_width, cur_height, cur_channels; |
| 36 | 38 | int32_t layer; |
| 37 | 39 | |
| @@ -77,6 +79,12 @@ static DNNReturnType set_input_output_native(void *model, DNNInputData *input, c · 39 unmodified lines |
| 77 | 79 | cur_height *= depth_to_space_params->block_size; |
| 78 | 80 | cur_width *= depth_to_space_params->block_size; |
| 79 | 81 | break; |
| 82 | + case MIRROR_PAD: |
| 83 | + pad_params = (LayerPadParams *)network->layers[layer].params; |
| 84 | + cur_height = cur_height + pad_params->paddings[1][0] + pad_params->paddings[1][1]; |
| 85 | + cur_width = cur_width + pad_params->paddings[2][0] + pad_params->paddings[2][1]; |
| 86 | + cur_channels = cur_channels + pad_params->paddings[3][0] + pad_params->paddings[3][1]; |
| 87 | + break; |
| 80 | 88 | default: |
| 81 | 89 | return DNN_ERROR; |
| 82 | 90 | } |
| @@ -110,6 +118,7 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) · 27 unmodified lines |
| 110 | 118 | DNNLayerType layer_type; |
| 111 | 119 | ConvolutionalParams *conv_params; |
| 112 | 120 | DepthToSpaceParams *depth_to_space_params; |
| 121 | + LayerPadParams *pad_params; |
| 113 | 122 | |
| 114 | 123 | model = av_malloc(sizeof(DNNModel)); |
| 115 | 124 | if (!model){ |
| @@ -207,6 +216,23 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename) · 91 unmodified lines |
| 207 | 216 | network->layers[layer].type = DEPTH_TO_SPACE; |
| 208 | 217 | network->layers[layer].params = depth_to_space_params; |
| 209 | 218 | break; |
| 219 | + case MIRROR_PAD: |
| 220 | + pad_params = av_malloc(sizeof(LayerPadParams)); |
| 221 | + if (!pad_params){ |
| 222 | + avio_closep(&model_file_context); |
| 223 | + ff_dnn_free_model_native(&model); |
| 224 | + return NULL; |
| 225 | + } |
| 226 | + pad_params->mode = (int32_t)avio_rl32(model_file_context); |
| 227 | + dnn_size += 4; |
| 228 | + for (i = 0; i < 4; ++i) { |
| 229 | + pad_params->paddings[i][0] = avio_rl32(model_file_context); |
| 230 | + pad_params->paddings[i][1] = avio_rl32(model_file_context); |
| 231 | + dnn_size += 8; |
| 232 | + } |
| 233 | + network->layers[layer].type = MIRROR_PAD; |
| 234 | + network->layers[layer].params = pad_params; |
| 235 | + break; |
| 210 | 236 | default: |
| 211 | 237 | avio_closep(&model_file_context); |
| 212 | 238 | ff_dnn_free_model_native(&model); |
| @@ -314,6 +340,7 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output · 101 unmodified lines |
| 314 | 340 | InputParams *input_params; |
| 315 | 341 | ConvolutionalParams *conv_params; |
| 316 | 342 | DepthToSpaceParams *depth_to_space_params; |
| 343 | + LayerPadParams *pad_params; |
| 317 | 344 | |
| 318 | 345 | if (network->layers_num <= 0 || network->layers[0].type != INPUT || !network->layers[0].output){ |
| 319 | 346 | return DNN_ERROR; |
| @@ -348,6 +375,14 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output · 28 unmodified lines |
| 348 | 375 | cur_width *= depth_to_space_params->block_size; |
| 349 | 376 | cur_channels /= depth_to_space_params->block_size * depth_to_space_params->block_size; |
| 350 | 377 | break; |
| 378 | + case MIRROR_PAD: |
| 379 | + pad_params = (LayerPadParams *)network->layers[layer].params; |
| 380 | + dnn_execute_layer_pad(network->layers[layer - 1].output, network->layers[layer].output, |
| 381 | + pad_params, 1, cur_height, cur_width, cur_channels); |
| 382 | + cur_height = cur_height + pad_params->paddings[1][0] + pad_params->paddings[1][1]; |
| 383 | + cur_width = cur_width + pad_params->paddings[2][0] + pad_params->paddings[2][1]; |
| 384 | + cur_channels = cur_channels + pad_params->paddings[3][0] + pad_params->paddings[3][1]; |
| 385 | + break; |
| 351 | 386 | case INPUT: |
| 352 | 387 | return DNN_ERROR; |
| 353 | 388 | } |