You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1KB

  1. /*
  2. * Copyright (c) 2018 Sergey Lavrushkin
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * DNN inference engine interface.
  23. */
  24. #ifndef AVFILTER_DNN_INTERFACE_H
  25. #define AVFILTER_DNN_INTERFACE_H
  26. typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
  27. typedef enum {DNN_NATIVE, DNN_TF} DNNBackendType;
  28. typedef struct DNNData{
  29. float *data;
  30. int width, height, channels;
  31. } DNNData;
  32. typedef struct DNNModel{
  33. // Stores model that can be different for different backends.
  34. void *model;
  35. // Sets model input and output, while allocating additional memory for intermediate calculations.
  36. // Should be called at least once before model execution.
  37. DNNReturnType (*set_input_output)(void *model, DNNData *input, DNNData *output);
  38. } DNNModel;
  39. // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.
  40. typedef struct DNNModule{
  41. // Loads model and parameters from given file. Returns NULL if it is not possible.
  42. DNNModel *(*load_model)(const char *model_filename);
  43. // Executes model with specified input and output. Returns DNN_ERROR otherwise.
  44. DNNReturnType (*execute_model)(const DNNModel *model);
  45. // Frees memory allocated for model.
  46. void (*free_model)(DNNModel **model);
  47. } DNNModule;
  48. // Initializes DNNModule depending on chosen backend.
  49. DNNModule *ff_get_dnn_module(DNNBackendType backend_type);
  50. #endif