29 dense_params =
av_malloc(
sizeof(*dense_params));
40 dnn_size += kernel_size * 4;
44 if (dnn_size > file_size || dense_params->
input_num <= 0 ||
51 if (!dense_params->
kernel) {
55 for (
int i = 0;
i < kernel_size; ++
i) {
62 if (!dense_params->
biases){
72 layer->
params = dense_params;
89 int32_t input_operand_index = input_operand_indexes[0];
90 int number = operands[input_operand_index].
dims[0];
91 int height = operands[input_operand_index].
dims[1];
92 int width = operands[input_operand_index].
dims[2];
93 int channel = operands[input_operand_index].
dims[3];
94 const float *
input = operands[input_operand_index].
data;
97 int src_linesize = width *
channel;
98 DnnOperand *output_operand = &operands[output_operand_index];
99 output_operand->
dims[0] = number;
105 if (output_operand->
length <= 0) {
110 if (!output_operand->
data) {
114 output = output_operand->
data;
118 for (
int y = 0; y <
height; ++y) {
119 for (
int x = 0; x <
width; ++x) {
120 for (
int n_filter = 0; n_filter < dense_params->
output_num; ++n_filter) {
122 output[n_filter] = dense_params->
biases[n_filter];
124 output[n_filter] = 0.f;
126 for (
int ch = 0; ch < dense_params->
input_num; ++ch) {
128 input_pel = input[y * src_linesize + x * dense_params->
input_num + ch];
129 output[n_filter] += input_pel * dense_params->
kernel[n_filter*dense_params->
input_num + ch];
133 output[n_filter] =
FFMAX(output[n_filter], 0.0);
136 output[n_filter] = 2.0f / (1.0f +
exp(-2.0
f * output[n_filter])) - 1.0
f;
139 output[n_filter] = 1.0f / (1.0f +
exp(-output[n_filter]));
144 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.
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.
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 ff_dnn_load_layer_dense(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
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
DNNActivationFunc activation
int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters, NativeContext *ctx)
channel
Use these values when setting the channel map with ebur128_set_channel().
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
int32_t output_operand_index