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

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