Go to the documentation of this file.
32 #define OFFSET(x) offsetof(NativeContext, x)
33 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM
48 const char **output_names, uint32_t nb_output,
AVFrame *out_frame,
58 if (strcmp(oprd->
name, input_name) == 0) {
78 const char *output_name,
int *output_width,
int *output_height)
99 in_frame->
width = input_width;
100 in_frame->
height = input_height;
103 *output_width = out_frame->
width;
104 *output_height = out_frame->
height;
117 #define DNN_NATIVE_MAGIC "FFMPEGDNNNATIVE"
121 int version, header_size, major_version_expected = 1;
124 int file_size, dnn_size, parsed_size;
131 file_size =
avio_size(model_file_context);
141 if (
avio_read(model_file_context, buf,
sizeof(buf)) !=
sizeof(buf) ||
144 dnn_size =
sizeof(buf);
148 if (
version != major_version_expected) {
155 header_size = dnn_size;
161 model->
model = native_model;
167 native_model->
model = model;
169 #if !HAVE_PTHREAD_CANCEL
172 "on this build (pthread support is required)\n");
176 avio_seek(model_file_context, file_size - 8, SEEK_SET);
180 avio_seek(model_file_context, header_size, SEEK_SET);
183 if (!native_model->
layers){
192 for (layer = 0; layer < native_model->
layers_num; ++layer){
200 native_model->
layers[layer].
type = layer_type;
205 dnn_size += parsed_size;
218 oprd = &native_model->
operands[operand_index];
223 dnn_size += name_len;
243 if (dnn_size != file_size){
262 const char **output_names, uint32_t nb_output,
AVFrame *out_frame,
278 if (strcmp(oprd->
name, input_name) == 0) {
320 if (nb_output != 1) {
327 for (layer = 0; layer < native_model->
layers_num; ++layer){
339 for (uint32_t
i = 0;
i < nb_output; ++
i) {
341 const char *output_name = output_names[
i];
343 if (strcmp(native_model->
operands[j].
name, output_name) == 0) {
376 const char **output_names, uint32_t nb_output,
AVFrame *out_frame)
391 return execute_model_native(model, input_name, in_frame, output_names, nb_output, out_frame, 1);
397 for (
int i = 0;
i < 4; ++
i)
406 uint64_t
len =
sizeof(float);
407 for (
int i = 0;
i < 4;
i++) {
423 if ((*model)->model) {
424 native_model = (*model)->
model;
425 if (native_model->
layers) {
426 for (layer = 0; layer < native_model->
layers_num; ++layer){
438 for (uint32_t operand = 0; operand < native_model->
operands_num; ++operand)
#define AV_LOG_WARNING
Something somehow does not look correct.
static FilteringContext * filter_ctx
int8_t isNHWC
NHWC if 1, otherwise NCHW.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
DNNModel * ff_dnn_load_model_native(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx)
static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name)
int64_t avio_size(AVIOContext *s)
Get the filesize.
AVFilterContext * filter_ctx
const LayerFunc ff_layer_funcs[DLT_COUNT]
static DNNReturnType execute_model_native(const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame, int do_ioproc)
DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
DNNReturnType(* get_output)(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
DNNLayerType
the enum value of DNNLayerType should not be changed, the same values are used in convert_from_tensor...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
DNNOperandType type
input/output/intermediate operand of the network
DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char name[128]
to avoid possible memory leak, do not use char *name
void * data
data pointer with data length in bytes.
#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.
DNNReturnType(* get_input)(void *model, DNNData *input, const char *input_name)
void ff_dnn_free_model_native(DNNModel **model)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
int(* pre_proc)(AVFrame *frame_in, DNNData *model_input, AVFilterContext *filter_ctx)
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVOption dnn_native_options[]
@ AV_CLASS_CATEGORY_FILTER
const OptionDef options[]
unsigned int avio_rl32(AVIOContext *s)
int32_t output_operand_index
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
int(* post_proc)(AVFrame *frame_out, DNNData *model_output, AVFilterContext *filter_ctx)
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
DNNFunctionType func_type
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, DNNFunctionType func_type, void *log_ctx)
static DNNReturnType get_output_native(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static const AVClass dnn_native_class
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int32_t ff_calculate_operand_dims_count(const DnnOperand *oprd)
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
#define AVIO_FLAG_READ
read-only