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.9 kB

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