test_infer_params.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************
  2. * Copyright (C) [2021] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #include <gtest/gtest.h>
  21. #include <memory>
  22. #include <string>
  23. #include <list>
  24. #include "cnstream_logging.hpp"
  25. #include "inferencer2.hpp"
  26. #include "video_postproc.hpp"
  27. #include "video_preproc.hpp"
  28. #include "test_base.hpp"
  29. namespace cnstream {
  30. TEST(Inferencer2, CheckParamSet) {
  31. std::string ssd_model_path = GetExePath() + "../../data/models/MLU270/Primary_Detector/ssd/resnet34_ssd.cambricon";
  32. std::string model_path = GetExePath() + "../../data/models/resnet50_nhwc.model";
  33. std::string infer_name = "detector";
  34. std::unique_ptr<Inferencer2> infer(new Inferencer2(infer_name));
  35. ModuleParamSet param;
  36. param.clear();
  37. param["postproc_name"] = "empty_postproc";
  38. if (infer_server::Predictor::Backend() == "magicmind") {
  39. param["model_path"] = model_path;
  40. EXPECT_TRUE(infer->CheckParamSet(param));
  41. } else {
  42. param["model_path"] = ssd_model_path;
  43. EXPECT_TRUE(infer->CheckParamSet(param));
  44. param["func_name"] = "subnet0";
  45. EXPECT_TRUE(infer->CheckParamSet(param));
  46. }
  47. param["preproc_name"] = "empty_preproc";
  48. EXPECT_TRUE(infer->CheckParamSet(param));
  49. param["device_id"] = "no_number"; // device id must be a number
  50. EXPECT_FALSE(infer->CheckParamSet(param));
  51. param["device_id"] = "0";
  52. EXPECT_TRUE(infer->CheckParamSet(param));
  53. param["engine_num"] = "no_number"; // engine num must be a number
  54. EXPECT_FALSE(infer->CheckParamSet(param));
  55. param["engine_num"] = "1";
  56. EXPECT_TRUE(infer->CheckParamSet(param));
  57. param["batching_timeout"] = "no_number"; // batching timeout must be a number
  58. EXPECT_FALSE(infer->CheckParamSet(param));
  59. param["batching_timeout"] = "100";
  60. EXPECT_TRUE(infer->CheckParamSet(param));
  61. // batch strategy must be one of them
  62. std::list<std::string> batch_strategy = {"static", "STATIC", "dynamic", "DYNAMIC"};
  63. param["batch_strategy"] = "error_type";
  64. EXPECT_FALSE(infer->CheckParamSet(param));
  65. for (auto type : batch_strategy) {
  66. param["batch_strategy"] = type;
  67. EXPECT_TRUE(infer->CheckParamSet(param));
  68. }
  69. // data order must be NCHW or NHWC
  70. std::list<std::string> data_order = {"NCHW", "NHWC"};
  71. param["data_order"] = "error_type";
  72. EXPECT_FALSE(infer->CheckParamSet(param));
  73. for (auto type : data_order) {
  74. param["data_order"] = type;
  75. EXPECT_TRUE(infer->CheckParamSet(param));
  76. }
  77. param["threshold"] = "0.5";
  78. EXPECT_TRUE(infer->CheckParamSet(param));
  79. // show stats must be one of bool_type
  80. std::list<std::string> bool_type = {"1", "true", "True", "TRUE", "0", "false", "False", "FALSE"};
  81. param["show_stats"] = "error_type";
  82. EXPECT_FALSE(infer->CheckParamSet(param));
  83. for (auto type : bool_type) {
  84. param["show_stats"] = type;
  85. EXPECT_TRUE(infer->CheckParamSet(param));
  86. }
  87. // object_infer must be one of bool_type
  88. param["object_infer"] = "error_type";
  89. EXPECT_FALSE(infer->CheckParamSet(param));
  90. for (auto type : bool_type) {
  91. param["object_infer"] = type;
  92. EXPECT_TRUE(infer->CheckParamSet(param));
  93. }
  94. // keep_aspect_ratio must be one of bool_type
  95. param["keep_aspect_ratio"] = "error_type";
  96. EXPECT_FALSE(infer->CheckParamSet(param));
  97. for (auto type : bool_type) {
  98. param["keep_aspect_ratio"] = type;
  99. EXPECT_TRUE(infer->CheckParamSet(param));
  100. }
  101. // normalize must be one of bool_type
  102. param["normalize"] = "error_type";
  103. EXPECT_FALSE(infer->CheckParamSet(param));
  104. for (auto type : bool_type) {
  105. param["normalize"] = type;
  106. EXPECT_TRUE(infer->CheckParamSet(param));
  107. }
  108. // model_input_pixel_format must be one of format
  109. std::list<std::string> format = {"RGBA32", "BGRA32", "ARGB32", "ABGR32", "RGB24", "BGR24"};
  110. param["model_input_pixel_format"] = "error_type";
  111. EXPECT_FALSE(infer->CheckParamSet(param));
  112. for (auto type : format) {
  113. param["model_input_pixel_format"] = type;
  114. EXPECT_TRUE(infer->CheckParamSet(param));
  115. }
  116. // TODO(dmh): test mean and std
  117. }
  118. } // namespace cnstream