33 avgpool_params =
av_malloc(
sizeof(*avgpool_params));
42 if (dnn_size > file_size || avgpool_params->
kernel_size <= 0 || avgpool_params->
strides <=0){
47 layer->
params = avgpool_params;
62 int height_end, width_end, height_radius, width_radius, output_height, output_width, kernel_area;
63 int32_t input_operand_index = input_operand_indexes[0];
64 int number = operands[input_operand_index].
dims[0];
65 int height = operands[input_operand_index].
dims[1];
66 int width = operands[input_operand_index].
dims[2];
67 int channel = operands[input_operand_index].
dims[3];
68 const float *
input = operands[input_operand_index].
data;
71 int kernel_strides = avgpool_params->
strides;
73 DnnOperand *output_operand = &operands[output_operand_index];
87 height_radius = avgpool_params->
kernel_size - ((
height - 1) % kernel_strides + 1);
88 width_radius = avgpool_params->
kernel_size - ((
width - 1) % kernel_strides + 1);
89 height_radius = height_radius < 0 ? 0 : height_radius >> 1;
90 width_radius = width_radius < 0 ? 0 : width_radius >> 1;
91 output_height =
ceil(
height / (kernel_strides * 1.0));
92 output_width =
ceil(
width / (kernel_strides * 1.0));
103 output_operand->
dims[0] = number;
104 output_operand->
dims[1] = output_height;
105 output_operand->
dims[2] = output_width;
110 if (output_operand->
length <= 0) {
115 if (!output_operand->
data) {
121 for (
int y = 0; y < height_end; y += kernel_strides) {
122 for (
int x = 0; x < width_end; x += kernel_strides) {
123 for (
int n_channel = 0; n_channel <
channel; ++n_channel) {
126 for (
int kernel_y = 0; kernel_y < avgpool_params->
kernel_size; ++kernel_y) {
127 for (
int kernel_x = 0; kernel_x < avgpool_params->
kernel_size; ++kernel_x) {
129 int y_pos = y + (kernel_y - height_radius);
130 int x_pos = x + (kernel_x - width_radius);
131 if (x_pos < 0 || x_pos >=
width || y_pos < 0 || y_pos >=
height) {
135 input_pel =
input[y_pos * src_linesize + x_pos *
channel + n_channel];
137 output[n_channel] += input_pel;
140 output[n_channel] /= kernel_area;