dnn-layer-maximum-test.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2019 Guo Yejun
  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. #include <stdio.h>
  21. #include <string.h>
  22. #include <math.h>
  23. #include "libavfilter/dnn/dnn_backend_native_layer_maximum.h"
  24. #define EPSON 0.00001
  25. static int test(void)
  26. {
  27. DnnLayerMaximumParams params;
  28. DnnOperand operands[2];
  29. int32_t input_indexes[1];
  30. float input[1*1*2*3] = {
  31. -3, 2.5, 2, -2.1, 7.8, 100
  32. };
  33. float *output;
  34. params.val.y = 2.3;
  35. operands[0].data = input;
  36. operands[0].dims[0] = 1;
  37. operands[0].dims[1] = 1;
  38. operands[0].dims[2] = 2;
  39. operands[0].dims[3] = 3;
  40. operands[1].data = NULL;
  41. input_indexes[0] = 0;
  42. dnn_execute_layer_maximum(operands, input_indexes, 1, &params);
  43. output = operands[1].data;
  44. for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
  45. float expected_output = input[i] > params.val.y ? input[i] : params.val.y;
  46. if (fabs(output[i] - expected_output) > EPSON) {
  47. printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
  48. av_freep(&output);
  49. return 1;
  50. }
  51. }
  52. av_freep(&output);
  53. return 0;
  54. }
  55. int main(int argc, char **argv)
  56. {
  57. if (test())
  58. return 1;
  59. return 0;
  60. }