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

test_flatten.cpp 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_flatten(const ncnn::Mat& a)
  5. {
  6. ncnn::ParamDict pd;
  7. std::vector<ncnn::Mat> weights(0);
  8. int ret = test_layer("Flatten", pd, weights, a);
  9. if (ret != 0)
  10. {
  11. fprintf(stderr, "test_flatten failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
  12. }
  13. return ret;
  14. }
  15. static int test_flatten_0()
  16. {
  17. return 0
  18. || test_flatten(RandomMat(2, 3, 4, 4))
  19. || test_flatten(RandomMat(3, 5, 7, 8))
  20. || test_flatten(RandomMat(1, 1, 1, 16))
  21. || test_flatten(RandomMat(9, 10, 2, 16))
  22. || test_flatten(RandomMat(1, 7, 1, 1))
  23. || test_flatten(RandomMat(6, 6, 6, 15))
  24. || test_flatten(RandomMat(2, 4, 4))
  25. || test_flatten(RandomMat(3, 5, 8))
  26. || test_flatten(RandomMat(1, 1, 16))
  27. || test_flatten(RandomMat(9, 10, 16))
  28. || test_flatten(RandomMat(1, 7, 1))
  29. || test_flatten(RandomMat(6, 6, 15))
  30. || test_flatten(RandomMat(13, 13))
  31. || test_flatten(RandomMat(16, 16))
  32. || test_flatten(RandomMat(8, 12))
  33. || test_flatten(RandomMat(8, 2))
  34. || test_flatten(RandomMat(32))
  35. || test_flatten(RandomMat(17));
  36. }
  37. static int test_flatten_int8(const ncnn::Mat& a)
  38. {
  39. ncnn::ParamDict pd;
  40. std::vector<ncnn::Mat> weights(0);
  41. int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING | TEST_LAYER_DISABLE_GPU_TESTING;
  42. int ret = test_layer("Flatten", pd, weights, a, 0.001, 0, flag);
  43. if (ret != 0)
  44. {
  45. fprintf(stderr, "test_flatten_int8 failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
  46. }
  47. return ret;
  48. }
  49. static int test_flatten_1()
  50. {
  51. return 0
  52. || test_flatten_int8(RandomS8Mat(2, 3, 4, 4))
  53. || test_flatten_int8(RandomS8Mat(3, 5, 7, 8))
  54. || test_flatten_int8(RandomS8Mat(1, 1, 1, 16))
  55. || test_flatten_int8(RandomS8Mat(9, 10, 2, 16))
  56. || test_flatten_int8(RandomS8Mat(1, 7, 1, 1))
  57. || test_flatten_int8(RandomS8Mat(6, 6, 6, 15))
  58. || test_flatten_int8(RandomS8Mat(2, 4, 16))
  59. || test_flatten_int8(RandomS8Mat(3, 5, 32))
  60. || test_flatten_int8(RandomS8Mat(1, 1, 64))
  61. || test_flatten_int8(RandomS8Mat(9, 10, 64))
  62. || test_flatten_int8(RandomS8Mat(1, 7, 4))
  63. || test_flatten_int8(RandomS8Mat(6, 6, 70))
  64. || test_flatten_int8(RandomS8Mat(13, 52))
  65. || test_flatten_int8(RandomS8Mat(16, 64))
  66. || test_flatten_int8(RandomS8Mat(8, 48))
  67. || test_flatten_int8(RandomS8Mat(16, 11))
  68. || test_flatten_int8(RandomS8Mat(8, 8))
  69. || test_flatten_int8(RandomS8Mat(128))
  70. || test_flatten_int8(RandomS8Mat(127));
  71. }
  72. int main()
  73. {
  74. SRAND(7767517);
  75. return test_flatten_0() || test_flatten_1();
  76. }