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;
72 int src_linesize = width *
channel;
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));
95 height_end = height - avgpool_params->
kernel_size + 1;
96 width_end = width - avgpool_params->
kernel_size + 1;
99 output_height =
ceil((height - avgpool_params->
kernel_size + 1) / (kernel_strides * 1.0));
100 output_width =
ceil((width - avgpool_params->
kernel_size + 1) / (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) {
119 output = 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) {
124 output[n_channel] = 0.0;
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;
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
static __device__ float ceil(float a)
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
DNNDataType data_type
support different kinds of data type such as float, half float, int8 etc, first support float now...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
unsigned int avio_rl32(AVIOContext *s)
void * data
data pointer with data length in bytes.
int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters, NativeContext *ctx)
simple assert() macros that are a bit more flexible than ISO C assert().
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
DNN inference functions interface for native backend.
DNNPaddingParam padding_method
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
int32_t output_operand_index