24 #define CLAMP_TO_EDGE(x, w) ((x) < 0 ? 0 : ((x) >= (w) ? (w - 1) : (x)))
31 conv_params =
av_malloc(
sizeof(*conv_params));
46 dnn_size += kernel_size * 4;
50 if (dnn_size > file_size || conv_params->
input_num <= 0 ||
57 if (!conv_params->
kernel) {
61 for (
int i = 0;
i < kernel_size; ++
i) {
78 layer->
params = conv_params;
92 int32_t output_operand_index,
const void *parameters)
95 int32_t input_operand_index = input_operand_indexes[0];
96 int number = operands[input_operand_index].
dims[0];
97 int height = operands[input_operand_index].
dims[1];
98 int width = operands[input_operand_index].
dims[2];
99 int channel = operands[input_operand_index].
dims[3];
100 const float *
input = operands[input_operand_index].
data;
106 int filter_size = conv_params->
kernel_size * filter_linesize;
109 DnnOperand *output_operand = &operands[output_operand_index];
110 output_operand->
dims[0] = number;
111 output_operand->
dims[1] =
height - pad_size * 2;
112 output_operand->
dims[2] =
width - pad_size * 2;
116 if (output_operand->
length <= 0)
119 if (!output_operand->
data)
125 for (
int y = pad_size; y <
height - pad_size; ++y) {
126 for (
int x = pad_size; x <
width - pad_size; ++x) {
127 for (
int n_filter = 0; n_filter < conv_params->
output_num; ++n_filter) {
133 for (
int ch = 0; ch < conv_params->
input_num; ++ch) {
134 for (
int kernel_y = 0; kernel_y < conv_params->
kernel_size; ++kernel_y) {
135 for (
int kernel_x = 0; kernel_x < conv_params->
kernel_size; ++kernel_x) {
140 input_pel =
input[y_pos * src_linesize + x_pos * conv_params->
input_num + ch];
142 int y_pos = y + (kernel_y - radius) * conv_params->
dilation;
143 int x_pos = x + (kernel_x - radius) * conv_params->
dilation;
144 input_pel = (x_pos < 0 || x_pos >=
width || y_pos < 0 || y_pos >=
height) ? 0.0 :
145 input[y_pos * src_linesize + x_pos * conv_params->
input_num + ch];
149 output[n_filter] += input_pel * conv_params->
kernel[n_filter * filter_size + kernel_y * filter_linesize +