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.

resize.cpp 3.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * \file dnn/test/cpu/resize.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/common/resize.h"
  12. #include "test/common/checker.h"
  13. #include "test/cpu/fixture.h"
  14. namespace megdnn {
  15. namespace test {
  16. TEST_F(CPU, RESIZE_CV) {
  17. using namespace resize;
  18. std::vector<TestArg> args = get_cv_args();
  19. Checker<Resize> checker(handle());
  20. for (auto&& arg : args) {
  21. checker.set_param(arg.param)
  22. .set_dtype(0, dtype::Uint8())
  23. .set_dtype(1, dtype::Uint8())
  24. .set_epsilon(1 + 1e-3)
  25. .execs({arg.src, arg.dst});
  26. }
  27. for (auto&& arg : args) {
  28. checker.set_param(arg.param)
  29. .set_dtype(0, dtype::Float32())
  30. .set_dtype(1, dtype::Float32())
  31. .execs({arg.src, arg.dst});
  32. }
  33. }
  34. TEST_F(CPU, RESIZE) {
  35. using namespace resize;
  36. std::vector<TestArg> args = get_args();
  37. Checker<Resize> checker(handle());
  38. for (auto&& arg : args) {
  39. checker.set_param(arg.param)
  40. .set_dtype(0, dtype::Uint8())
  41. .set_dtype(1, dtype::Uint8())
  42. .set_epsilon(1 + 1e-3)
  43. .execs({arg.src, arg.dst});
  44. }
  45. for (auto&& arg : args) {
  46. checker.set_param(arg.param)
  47. .set_dtype(0, dtype::Float32())
  48. .set_dtype(1, dtype::Float32())
  49. .execs({arg.src, arg.dst});
  50. }
  51. }
  52. TEST_F(CPU, RESIZE_NCHW_WITH_STRIDE) {
  53. param::Resize param;
  54. param.format = param::Resize::Format::NCHW;
  55. param.imode = param::Resize::InterpolationMode::LINEAR;
  56. Checker<Resize> checker(handle());
  57. checker.set_epsilon(1 + 1e-3).set_param(param);
  58. auto run = [&](TensorShape src_shape, std::vector<ptrdiff_t> src_layout,
  59. TensorShape dst_shape, DType dtype) {
  60. checker.set_dtype(0, dtype).set_dtype(1, dtype).execl(
  61. {{src_shape, src_layout, dtype}, {dst_shape, dtype}});
  62. };
  63. for (DType& dtype : std::vector<DType>{dtype::Float32(), dtype::Uint8()}) {
  64. run({2, 3, 4, 4}, {256, 32, 8, 1}, {2, 3, 3, 3}, dtype);
  65. run({1, 3, 4, 3}, {105, 35, 7, 2}, {1, 3, 5, 5}, dtype);
  66. run({2, 3, 4, 4}, {-256, 32, -8, 1}, {2, 3, 3, 3}, dtype);
  67. run({2, 3, 4, 4}, {256, -32, 8, -1}, {2, 3, 3, 3}, dtype);
  68. run({2, 3, 4, 4}, {-256, -32, -8, -1}, {2, 3, 3, 3}, dtype);
  69. }
  70. }
  71. TEST_F(CPU, RESIZE_NCHW4) {
  72. using namespace resize;
  73. auto args = get_nchw4_args();
  74. Checker<Resize> checker(handle());
  75. for (auto&& arg : args) {
  76. checker.set_param(arg.param)
  77. .set_dtype(0, dtype::QuantizedS8(1.0f))
  78. .set_dtype(1, dtype::QuantizedS8(1.0f))
  79. .set_epsilon(1 + 1e-3)
  80. .execs({arg.src, arg.dst});
  81. }
  82. }
  83. } // namespace test
  84. } // namespace megdnn
  85. // vim: syntax=cpp.doxygen