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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "testutil.h"
  15. #include "layer/concat.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. ncnn::Option opt;
  22. opt.num_threads = 1;
  23. opt.use_vulkan_compute = true;
  24. opt.use_int8_inference = false;
  25. int ret = test_layer<ncnn::Concat>("Concat", pd, weights, opt, a);
  26. if (ret != 0)
  27. {
  28. 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);
  29. }
  30. return ret;
  31. }
  32. static int test_concat_0()
  33. {
  34. std::vector<ncnn::Mat> a(3);
  35. a[0] = RandomMat(16, 12, 8);
  36. a[1] = RandomMat(16, 12, 8);
  37. a[2] = RandomMat(16, 12, 8);
  38. return 0
  39. || test_concat(a, 0)
  40. || test_concat(a, 1)
  41. || test_concat(a, 2)
  42. ;
  43. }
  44. static int test_concat_1()
  45. {
  46. std::vector<ncnn::Mat> a(3);
  47. a[0] = RandomMat(7, 3, 3);
  48. a[1] = RandomMat(7, 3, 8);
  49. a[2] = RandomMat(7, 3, 5);
  50. return test_concat(a, 0);
  51. }
  52. static int test_concat_2()
  53. {
  54. std::vector<ncnn::Mat> a(3);
  55. a[0] = RandomMat(7, 3, 2);
  56. a[1] = RandomMat(7, 8, 2);
  57. a[2] = RandomMat(7, 5, 2);
  58. return test_concat(a, 1);
  59. }
  60. static int test_concat_3()
  61. {
  62. std::vector<ncnn::Mat> a(3);
  63. a[0] = RandomMat(7, 3, 8);
  64. a[1] = RandomMat(7, 8, 8);
  65. a[2] = RandomMat(7, 5, 8);
  66. return test_concat(a, 1);
  67. }
  68. static int test_concat_4()
  69. {
  70. std::vector<ncnn::Mat> a(3);
  71. a[0] = RandomMat(3, 7, 2);
  72. a[1] = RandomMat(8, 7, 2);
  73. a[2] = RandomMat(5, 7, 2);
  74. return test_concat(a, 2);
  75. }
  76. static int test_concat_5()
  77. {
  78. std::vector<ncnn::Mat> a(3);
  79. a[0] = RandomMat(3, 7, 8);
  80. a[1] = RandomMat(8, 7, 8);
  81. a[2] = RandomMat(5, 7, 8);
  82. return test_concat(a, 2);
  83. }
  84. static int test_concat_6()
  85. {
  86. std::vector<ncnn::Mat> a(3);
  87. a[0] = RandomMat(7, 3);
  88. a[1] = RandomMat(7, 8);
  89. a[2] = RandomMat(7, 5);
  90. return test_concat(a, 0);
  91. }
  92. static int test_concat_7()
  93. {
  94. std::vector<ncnn::Mat> a(3);
  95. a[0] = RandomMat(3, 2);
  96. a[1] = RandomMat(8, 2);
  97. a[2] = RandomMat(5, 2);
  98. return test_concat(a, 1);
  99. }
  100. static int test_concat_8()
  101. {
  102. std::vector<ncnn::Mat> a(3);
  103. a[0] = RandomMat(3, 8);
  104. a[1] = RandomMat(8, 8);
  105. a[2] = RandomMat(5, 8);
  106. return test_concat(a, 1);
  107. }
  108. static int test_concat_9()
  109. {
  110. std::vector<ncnn::Mat> a(3);
  111. a[0] = RandomMat(3);
  112. a[1] = RandomMat(8);
  113. a[2] = RandomMat(5);
  114. return test_concat(a, 0);
  115. }
  116. static int test_concat_10()
  117. {
  118. std::vector<ncnn::Mat> a(3);
  119. a[0] = RandomMat(4);
  120. a[1] = RandomMat(8);
  121. a[2] = RandomMat(12);
  122. return test_concat(a, 0);
  123. }
  124. int main()
  125. {
  126. SRAND(7767517);
  127. return 0
  128. || test_concat_0()
  129. || test_concat_1()
  130. || test_concat_2()
  131. || test_concat_3()
  132. || test_concat_4()
  133. || test_concat_5()
  134. || test_concat_6()
  135. || test_concat_7()
  136. || test_concat_8()
  137. || test_concat_9()
  138. || test_concat_10()
  139. ;
  140. }