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;
104 int src_linesize = width * conv_params->
input_num;
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)
121 output = 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) {
129 output[n_filter] = conv_params->
biases[n_filter];
131 output[n_filter] = 0.f;
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 +
156 output[n_filter] =
FFMAX(output[n_filter], 0.0);
159 output[n_filter] = 2.0f / (1.0f +
exp(-2.0
f * output[n_filter])) - 1.0
f;
162 output[n_filter] = 1.0f / (1.0f +
exp(-output[n_filter]));
167 output[n_filter] =
FFMAX(output[n_filter], 0.0) + 0.2 *
FFMIN(output[n_filter], 0.0);
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
DNNActivationFunc activation
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.
DNNDataType data_type
support different kinds of data type such as float, half float, int8 etc, first support float now...
#define i(width, name, range_min, range_max)
unsigned int avio_rl32(AVIOContext *s)
void * data
data pointer with data length in bytes.
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.
int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters)
int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
#define CLAMP_TO_EDGE(x, w)
DNNConvPaddingParam padding_method
channel
Use these values when setting the channel map with ebur128_set_channel().
int32_t calculate_operand_data_length(const DnnOperand *oprd)
int32_t output_operand_index