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.

warp_perspective.cpp 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "test/cpu/fixture.h"
  2. #include "test/common/checker.h"
  3. #include "test/common/random_state.h"
  4. #include "test/common/rng.h"
  5. #include "test/common/warp_perspective.h"
  6. namespace megdnn {
  7. namespace test {
  8. TEST_F(CPU, WARP_PERSPECTIVE_CV) {
  9. //! Just for the format NHWC
  10. Checker<WarpPerspective> checker(handle());
  11. param::WarpPerspective param;
  12. class ResizeMatRNG : public RNG {
  13. void gen(const TensorND& tensor_) override {
  14. auto& gen = RandomState::generator();
  15. std::uniform_real_distribution<dt_float32> pdist3(1.9f, 3.1f);
  16. std::uniform_real_distribution<dt_float32> pdist(0.9f, 1.1f);
  17. std::uniform_real_distribution<dt_float32> pdisth(0.4f, 0.6f);
  18. std::uniform_real_distribution<dt_float32> ndist(-1.1f, -0.9f);
  19. std::uniform_real_distribution<dt_float32> ndist3(-3.1f, -1.9f);
  20. std::uniform_real_distribution<dt_float32> ndisth(-0.6f, -0.4f);
  21. std::uniform_int_distribution<int> dice(0, 5);
  22. float* ptr = tensor_.ptr<dt_float32>();
  23. auto N = tensor_.layout.shape[0];
  24. for (size_t n = 0; n < N; ++n) {
  25. for (size_t i = 0; i < 9; ++i) {
  26. switch (dice(gen)) {
  27. case 0:
  28. ptr[i] = pdist3(gen);
  29. break;
  30. case 1:
  31. ptr[i] = pdist(gen);
  32. break;
  33. case 2:
  34. ptr[i] = pdisth(gen);
  35. break;
  36. case 3:
  37. ptr[i] = ndist(gen);
  38. break;
  39. case 4:
  40. ptr[i] = ndist3(gen);
  41. break;
  42. case 5:
  43. ptr[i] = ndisth(gen);
  44. break;
  45. }
  46. }
  47. // is resize?
  48. if (n & 1) {
  49. ptr[1] = 0;
  50. ptr[3] = 0;
  51. ptr[6] = ptr[7] = 0;
  52. }
  53. ptr += 9;
  54. }
  55. }
  56. } rng;
  57. checker.set_rng(1, &rng);
  58. using BMode = param::WarpPerspective::BorderMode;
  59. param.format = param::WarpPerspective::Format::NHWC;
  60. for (auto mode :
  61. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  62. BMode::CONSTANT}) {
  63. param.bmode = mode;
  64. param.border_val = 1.737;
  65. checker.set_param(param);
  66. checker.exec({{1000, 2, 10, 3}, {1000, 3, 3}, {1000, 2, 12, 3}});
  67. }
  68. // resize nan case
  69. UniformFloatRNG rng_zero(0, 0);
  70. checker.set_rng(1, &rng_zero);
  71. {
  72. param.bmode = BMode::CONSTANT;
  73. param.border_val = 1.737;
  74. checker.set_param(param);
  75. checker.exec({{1000, 2, 10, 3}, {1000, 3, 3}, {1000, 2, 12, 3}});
  76. }
  77. auto args = warp_perspective::get_cv_args();
  78. for (auto&& arg : args) {
  79. checker.set_param(arg.param)
  80. .set_epsilon(1 + 1e-3)
  81. .set_dtype(0, dtype::Uint8())
  82. .set_dtype(1, dtype::Float32())
  83. .set_dtype(2, dtype::Uint8())
  84. .execs({arg.src, arg.trans, arg.dst});
  85. }
  86. for (auto&& arg : args) {
  87. checker.set_param(arg.param)
  88. .set_dtype(0, dtype::Float32())
  89. .set_dtype(1, dtype::Float32())
  90. .set_dtype(2, dtype::Float32())
  91. .execs({arg.src, arg.trans, arg.dst});
  92. }
  93. }
  94. } // namespace test
  95. } // namespace megdnn
  96. // vim: syntax=cpp.doxygen