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.

images2neibs.cpp 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * \file dnn/test/naive/images2neibs.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "test/naive/fixture.h"
  12. #include "megdnn/oprs/nn.h"
  13. #include "test/common/checker.h"
  14. using namespace megdnn;
  15. using namespace test;
  16. TEST_F(NAIVE, IMAGES2NEIBS_FORWARD) {
  17. Checker<Images2Neibs> checker(handle(), /* check_dispatch */ false);
  18. Images2Neibs::Param param(0, 0, 1, 1, 1, 1, 2, 2);
  19. checker.set_param(param).exect(
  20. Testcase{
  21. TensorValue(
  22. {1, 1, 3, 3}, dtype::Uint8(), {0, 1, 2, 3, 4, 5, 6, 7, 8}),
  23. {}},
  24. Testcase{
  25. {},
  26. TensorValue(
  27. {1, 1, 2, 2, 2, 2}, dtype::Uint8(),
  28. {0, 1, 3, 4, 1, 2, 4, 5, 3, 4, 6, 7, 4, 5, 7, 8})});
  29. param.pad_h = 1;
  30. param.pad_w = 1;
  31. param.stride_h = 2;
  32. param.stride_w = 2;
  33. param.dilate_h = 2;
  34. param.dilate_w = 2;
  35. param.window_h = 3;
  36. param.window_w = 3;
  37. checker.set_param(param).exect(
  38. Testcase{
  39. TensorValue(
  40. {1, 1, 6, 7}, dtype::Uint8(),
  41. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  42. 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
  43. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41}),
  44. {}},
  45. Testcase{
  46. {},
  47. TensorValue(
  48. {1, 1, 2, 3, 3, 3}, dtype::Uint8(),
  49. {0, 0, 0, 0, 8, 10, 0, 22, 24, 0, 0, 0, 8, 10,
  50. 12, 22, 24, 26, 0, 0, 0, 10, 12, 0, 24, 26, 0, 0,
  51. 8, 10, 0, 22, 24, 0, 36, 38, 8, 10, 12, 22, 24, 26,
  52. 36, 38, 40, 10, 12, 0, 24, 26, 0, 38, 40, 0})});
  53. }
  54. TEST_F(NAIVE, IMAGES2NEIBS_FORWARD_CD4) {
  55. Checker<Images2Neibs> checker(handle(), /* check_dispatch */ false);
  56. Images2Neibs::Param param(0, 0, 1, 1, 1, 1, 2, 2);
  57. checker.set_param(param).exect(
  58. Testcase{
  59. TensorValue(
  60. {1, 3, 1, 3, 4}, dtype::Uint8(),
  61. {0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0,
  62. 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0}),
  63. {}},
  64. Testcase{
  65. {},
  66. TensorValue(
  67. {1, 2, 1, 2, 2, 2, 4}, dtype::Uint8(),
  68. {0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0,
  69. 1, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0,
  70. 3, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0,
  71. 4, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0})});
  72. param.pad_h = 1;
  73. param.pad_w = 1;
  74. param.stride_h = 2;
  75. param.stride_w = 2;
  76. param.dilate_h = 2;
  77. param.dilate_w = 2;
  78. param.window_h = 3;
  79. param.window_w = 3;
  80. checker.set_param(param).exect(
  81. Testcase{
  82. TensorValue(
  83. {1, 6, 1, 7, 4}, dtype::Uint8(),
  84. {0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0,
  85. 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0,
  86. 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0,
  87. 12, 0, 0, 0, 13, 0, 0, 0, 14, 0, 0, 0, 15, 0, 0, 0,
  88. 16, 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 19, 0, 0, 0,
  89. 20, 0, 0, 0, 21, 0, 0, 0, 22, 0, 0, 0, 23, 0, 0, 0,
  90. 24, 0, 0, 0, 25, 0, 0, 0, 26, 0, 0, 0, 27, 0, 0, 0,
  91. 28, 0, 0, 0, 29, 0, 0, 0, 30, 0, 0, 0, 31, 0, 0, 0,
  92. 32, 0, 0, 0, 33, 0, 0, 0, 34, 0, 0, 0, 35, 0, 0, 0,
  93. 36, 0, 0, 0, 37, 0, 0, 0, 38, 0, 0, 0, 39, 0, 0, 0,
  94. 40, 0, 0, 0, 41, 0, 0, 0}),
  95. {}},
  96. Testcase{
  97. {},
  98. TensorValue(
  99. {1, 2, 1, 3, 3, 3, 4}, dtype::Uint8(),
  100. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  101. 8, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0,
  102. 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  103. 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 22, 0, 0, 0,
  104. 24, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  105. 0, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
  106. 24, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107. 8, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0,
  108. 24, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 38, 0, 0, 0,
  109. 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 22, 0, 0, 0,
  110. 24, 0, 0, 0, 26, 0, 0, 0, 36, 0, 0, 0, 38, 0, 0, 0,
  111. 40, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
  112. 24, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0,
  113. 40, 0, 0, 0, 0, 0, 0, 0})});
  114. }