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 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. || test_concat(a, -1)
  39. || test_concat(a, -2)
  40. || test_concat(a, -3);
  41. }
  42. static int test_concat_1()
  43. {
  44. std::vector<ncnn::Mat> a(3);
  45. a[0] = RandomMat(7, 3, 3);
  46. a[1] = RandomMat(7, 3, 8);
  47. a[2] = RandomMat(7, 3, 5);
  48. std::vector<ncnn::Mat> b(3);
  49. b[0] = RandomMat(9, 5, 8);
  50. b[1] = RandomMat(9, 5, 4);
  51. b[2] = RandomMat(9, 5, 12);
  52. return 0
  53. || test_concat(a, 0)
  54. || test_concat(a, -3)
  55. || test_concat(b, 0)
  56. || test_concat(b, -3);
  57. }
  58. static int test_concat_2()
  59. {
  60. std::vector<ncnn::Mat> a(3);
  61. a[0] = RandomMat(7, 3, 5);
  62. a[1] = RandomMat(7, 8, 5);
  63. a[2] = RandomMat(7, 5, 5);
  64. std::vector<ncnn::Mat> b(3);
  65. b[0] = RandomMat(9, 8, 12);
  66. b[1] = RandomMat(9, 3, 12);
  67. b[2] = RandomMat(9, 5, 12);
  68. return 0
  69. || test_concat(a, 1)
  70. || test_concat(a, -2)
  71. || test_concat(b, 1)
  72. || test_concat(b, -2);
  73. }
  74. static int test_concat_3()
  75. {
  76. std::vector<ncnn::Mat> a(3);
  77. a[0] = RandomMat(8, 9, 3);
  78. a[1] = RandomMat(3, 9, 3);
  79. a[2] = RandomMat(5, 9, 3);
  80. std::vector<ncnn::Mat> b(3);
  81. b[0] = RandomMat(1, 7, 16);
  82. b[1] = RandomMat(8, 7, 16);
  83. b[2] = RandomMat(7, 7, 16);
  84. return 0
  85. || test_concat(a, 2)
  86. || test_concat(a, -1)
  87. || test_concat(b, 2)
  88. || test_concat(b, -1);
  89. }
  90. static int test_concat_4()
  91. {
  92. std::vector<ncnn::Mat> a(3);
  93. a[0] = RandomMat(11, 3);
  94. a[1] = RandomMat(11, 8);
  95. a[2] = RandomMat(11, 5);
  96. std::vector<ncnn::Mat> b(3);
  97. b[0] = RandomMat(15, 12);
  98. b[1] = RandomMat(15, 8);
  99. b[2] = RandomMat(15, 4);
  100. return 0
  101. || test_concat(a, 0)
  102. || test_concat(a, -2)
  103. || test_concat(b, 0)
  104. || test_concat(b, -2);
  105. }
  106. static int test_concat_5()
  107. {
  108. std::vector<ncnn::Mat> a(3);
  109. a[0] = RandomMat(9, 7);
  110. a[1] = RandomMat(8, 7);
  111. a[2] = RandomMat(11, 7);
  112. std::vector<ncnn::Mat> b(3);
  113. b[0] = RandomMat(13, 24);
  114. b[1] = RandomMat(18, 24);
  115. b[2] = RandomMat(15, 24);
  116. return 0
  117. || test_concat(a, 1)
  118. || test_concat(a, -1)
  119. || test_concat(b, 1)
  120. || test_concat(b, -1);
  121. }
  122. static int test_concat_6()
  123. {
  124. std::vector<ncnn::Mat> a(3);
  125. a[0] = RandomMat(3);
  126. a[1] = RandomMat(8);
  127. a[2] = RandomMat(5);
  128. std::vector<ncnn::Mat> b(3);
  129. b[0] = RandomMat(4);
  130. b[1] = RandomMat(8);
  131. b[2] = RandomMat(12);
  132. return 0
  133. || test_concat(a, 0)
  134. || test_concat(a, -1)
  135. || test_concat(b, 0)
  136. || test_concat(b, -1);
  137. }
  138. int main()
  139. {
  140. SRAND(7767517);
  141. return 0
  142. || test_concat_0()
  143. || test_concat_1()
  144. || test_concat_2()
  145. || test_concat_3()
  146. || test_concat_4()
  147. || test_concat_5()
  148. || test_concat_6();
  149. }