Commit bdf1bbdb authored by Sergey Lavrushkin's avatar Sergey Lavrushkin Committed by Pedro Arthur

Adds dnn inference module for simple convolutional networks. Reimplements srcnn filter based on it.

Signed-off-by: 's avatarPedro Arthur <bygrandao@gmail.com>
parent cba16793
......@@ -9,6 +9,8 @@ version <next>:
- aderivative and aintegral audio filters
- pal75bars and pal100bars video filter sources
- support mbedTLS based TLS
- DNN inference interface
- Reimplemented SRCNN filter using DNN inference interface
version 4.0:
......
......@@ -12,6 +12,8 @@ OBJS = allfilters.o \
avfiltergraph.o \
buffersink.o \
buffersrc.o \
dnn_interface.o \
dnn_backend_native.o \
drawutils.o \
fifo.o \
formats.o \
......
This diff is collapsed.
/*
* Copyright (c) 2018 Sergey Lavrushkin
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* DNN inference functions interface for native backend.
*/
#ifndef AVFILTER_DNN_BACKEND_NATIVE_H
#define AVFILTER_DNN_BACKEND_NATIVE_H
#include "dnn_interface.h"
DNNModel* ff_dnn_load_model_native(const char* model_filename);
DNNModel* ff_dnn_load_default_model_native(DNNDefaultModel model_type);
DNNReturnType ff_dnn_execute_model_native(const DNNModel* model);
void ff_dnn_free_model_native(DNNModel** model);
#endif
/*
* Copyright (c) 2018 Sergey Lavrushkin
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Implements DNN module initialization with specified backend.
*/
#include "dnn_interface.h"
#include "dnn_backend_native.h"
#include "libavutil/mem.h"
DNNModule* ff_get_dnn_module(DNNBackendType backend_type)
{
DNNModule* dnn_module;
dnn_module = av_malloc(sizeof(DNNModule));
if(!dnn_module){
return NULL;
}
switch(backend_type){
case DNN_NATIVE:
dnn_module->load_model = &ff_dnn_load_model_native;
dnn_module->load_default_model = &ff_dnn_load_default_model_native;
dnn_module->execute_model = &ff_dnn_execute_model_native;
dnn_module->free_model = &ff_dnn_free_model_native;
}
return dnn_module;
}
/*
* Copyright (c) 2018 Sergey Lavrushkin
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* DNN inference engine interface.
*/
#ifndef AVFILTER_DNN_INTERFACE_H
#define AVFILTER_DNN_INTERFACE_H
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
typedef enum {DNN_NATIVE} DNNBackendType;
typedef enum {DNN_SRCNN} DNNDefaultModel;
typedef struct DNNData{
float* data;
int width, height, channels;
} DNNData;
typedef struct DNNModel{
// Stores model that can be different for different backends.
void* model;
// Sets model input and output, while allocating additional memory for intermediate calculations.
// Should be called at least once before model execution.
DNNReturnType (*set_input_output)(void* model, const DNNData* input, const DNNData* output);
} DNNModel;
// Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
typedef struct DNNModule{
// Loads model and parameters from given file. Returns NULL if it is not possible.
DNNModel* (*load_model)(const char* model_filename);
// Loads one of the default models
DNNModel* (*load_default_model)(DNNDefaultModel model_type);
// Executes model with specified input and output. Returns DNN_ERROR otherwise.
DNNReturnType (*execute_model)(const DNNModel* model);
// Frees memory allocated for model.
void (*free_model)(DNNModel** model);
} DNNModule;
// Initializes DNNModule depending on chosen backend.
DNNModule* ff_get_dnn_module(DNNBackendType backend_type);
#endif
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment