mirror of https://github.com/FFmpeg/FFmpeg.git
the logic is that one layer in one separated source file to make the source files simple for maintaining. Signed-off-by: Guo, Yejun <yejun.guo@intel.com> Signed-off-by: Pedro Arthur <bygrandao@gmail.com>pull/323/head
parent
24f507301b
commit
48133fad05
6 changed files with 113 additions and 47 deletions
@ -0,0 +1,71 @@ |
||||
/*
|
||||
* Copyright (c) 2018 Sergey Lavrushkin |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/**
|
||||
* @file |
||||
* DNN native backend implementation. |
||||
*/ |
||||
|
||||
#include "dnn_backend_native.h" |
||||
#include "libavutil/avassert.h" |
||||
#include "dnn_backend_native_layer_depth2space.h" |
||||
|
||||
int depth_to_space(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, int block_size) |
||||
{ |
||||
float *output; |
||||
int32_t input_operand_index = input_operand_indexes[0]; |
||||
int number = operands[input_operand_index].dims[0]; |
||||
int height = operands[input_operand_index].dims[1]; |
||||
int width = operands[input_operand_index].dims[2]; |
||||
int channels = operands[input_operand_index].dims[3]; |
||||
const float *input = operands[input_operand_index].data; |
||||
|
||||
int y, x, by, bx, ch; |
||||
int new_channels = channels / (block_size * block_size); |
||||
int output_linesize = width * channels; |
||||
int by_linesize = output_linesize / block_size; |
||||
int x_linesize = new_channels * block_size; |
||||
|
||||
DnnOperand *output_operand = &operands[output_operand_index]; |
||||
output_operand->dims[0] = number; |
||||
output_operand->dims[1] = height * block_size; |
||||
output_operand->dims[2] = width * block_size; |
||||
output_operand->dims[3] = new_channels; |
||||
output_operand->length = calculate_operand_data_length(output_operand); |
||||
output_operand->data = av_realloc(output_operand->data, output_operand->length); |
||||
if (!output_operand->data) |
||||
return -1; |
||||
output = output_operand->data; |
||||
|
||||
for (y = 0; y < height; ++y){ |
||||
for (x = 0; x < width; ++x){ |
||||
for (by = 0; by < block_size; ++by){ |
||||
for (bx = 0; bx < block_size; ++bx){ |
||||
for (ch = 0; ch < new_channels; ++ch){ |
||||
output[by * by_linesize + x * x_linesize + bx * new_channels + ch] = input[ch]; |
||||
} |
||||
input += new_channels; |
||||
} |
||||
} |
||||
} |
||||
output += output_linesize; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,39 @@ |
||||
/*
|
||||
* Copyright (c) 2018 Sergey Lavrushkin |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/**
|
||||
* @file |
||||
* DNN inference functions interface for native backend. |
||||
*/ |
||||
|
||||
|
||||
#ifndef AVFILTER_DNN_DNN_BACKEND_NATIVE_DEPTH2SPACE_H |
||||
#define AVFILTER_DNN_DNN_BACKEND_NATIVE_DEPTH2SPACE_H |
||||
|
||||
#include "../dnn_interface.h" |
||||
#include "libavformat/avio.h" |
||||
|
||||
typedef struct DepthToSpaceParams{ |
||||
int block_size; |
||||
} DepthToSpaceParams; |
||||
|
||||
int depth_to_space(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, int block_size); |
||||
|
||||
#endif |
Loading…
Reference in new issue