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_concat.cpp 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "layer/concat.h"
  15. #include "testutil.h"
  16. static int test_concat(const std::vector<ncnn::Mat>& a, int axis)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, axis); //axis
  20. std::vector<ncnn::Mat> weights(0);
  21. int ret = test_layer<ncnn::Concat>("Concat", pd, weights, a);
  22. if (ret != 0)
  23. {
  24. fprintf(stderr, "test_concat failed a[0].dims=%d a[0]=(%d %d %d) axis=%d\n", a[0].dims, a[0].w, a[0].h, a[0].c, axis);
  25. }
  26. return ret;
  27. }
  28. static int test_concat_0()
  29. {
  30. std::vector<ncnn::Mat> a(3);
  31. a[0] = RandomMat(16, 12, 24);
  32. a[1] = RandomMat(16, 12, 24);
  33. a[2] = RandomMat(16, 12, 24);
  34. return 0
  35. || test_concat(a, 0)
  36. || test_concat(a, 1)
  37. || test_concat(a, 2);
  38. }
  39. static int test_concat_1()
  40. {
  41. std::vector<ncnn::Mat> a(3);
  42. a[0] = RandomMat(7, 3, 3);
  43. a[1] = RandomMat(7, 3, 8);
  44. a[2] = RandomMat(7, 3, 5);
  45. std::vector<ncnn::Mat> b(3);
  46. b[0] = RandomMat(9, 5, 8);
  47. b[1] = RandomMat(9, 5, 4);
  48. b[2] = RandomMat(9, 5, 12);
  49. return test_concat(a, 0) || test_concat(b, 0);
  50. }
  51. static int test_concat_2()
  52. {
  53. std::vector<ncnn::Mat> a(3);
  54. a[0] = RandomMat(7, 3, 5);
  55. a[1] = RandomMat(7, 8, 5);
  56. a[2] = RandomMat(7, 5, 5);
  57. std::vector<ncnn::Mat> b(3);
  58. b[0] = RandomMat(9, 8, 12);
  59. b[1] = RandomMat(9, 3, 12);
  60. b[2] = RandomMat(9, 5, 12);
  61. return test_concat(a, 1) || test_concat(b, 1);
  62. }
  63. static int test_concat_3()
  64. {
  65. std::vector<ncnn::Mat> a(3);
  66. a[0] = RandomMat(8, 9, 3);
  67. a[1] = RandomMat(3, 9, 3);
  68. a[2] = RandomMat(5, 9, 3);
  69. std::vector<ncnn::Mat> b(3);
  70. b[0] = RandomMat(1, 7, 16);
  71. b[1] = RandomMat(8, 7, 16);
  72. b[2] = RandomMat(7, 7, 16);
  73. return test_concat(a, 2) || test_concat(b, 2);
  74. }
  75. static int test_concat_4()
  76. {
  77. std::vector<ncnn::Mat> a(3);
  78. a[0] = RandomMat(11, 3);
  79. a[1] = RandomMat(11, 8);
  80. a[2] = RandomMat(11, 5);
  81. std::vector<ncnn::Mat> b(3);
  82. b[0] = RandomMat(15, 12);
  83. b[1] = RandomMat(15, 8);
  84. b[2] = RandomMat(15, 4);
  85. return test_concat(a, 0) || test_concat(b, 0);
  86. }
  87. static int test_concat_5()
  88. {
  89. std::vector<ncnn::Mat> a(3);
  90. a[0] = RandomMat(9, 7);
  91. a[1] = RandomMat(8, 7);
  92. a[2] = RandomMat(11, 7);
  93. std::vector<ncnn::Mat> b(3);
  94. b[0] = RandomMat(13, 24);
  95. b[1] = RandomMat(18, 24);
  96. b[2] = RandomMat(15, 24);
  97. return test_concat(a, 1) || test_concat(b, 1);
  98. }
  99. static int test_concat_6()
  100. {
  101. std::vector<ncnn::Mat> a(3);
  102. a[0] = RandomMat(3);
  103. a[1] = RandomMat(8);
  104. a[2] = RandomMat(5);
  105. std::vector<ncnn::Mat> b(3);
  106. b[0] = RandomMat(4);
  107. b[1] = RandomMat(8);
  108. b[2] = RandomMat(12);
  109. return test_concat(a, 0) || test_concat(b, 0);
  110. }
  111. int main()
  112. {
  113. SRAND(7767517);
  114. return 0
  115. || test_concat_0()
  116. || test_concat_1()
  117. || test_concat_2()
  118. || test_concat_3()
  119. || test_concat_4()
  120. || test_concat_5()
  121. || test_concat_6();
  122. }