From 95b98f27ae4f413dd5c1911e3e3e8b87b0c6d4c0 Mon Sep 17 00:00:00 2001 From: nhzlx Date: Mon, 28 Jan 2019 05:09:11 +0000 Subject: [PATCH] fix trt models utest failed. test=develop --- paddle/fluid/inference/tests/api/tester_helper.h | 13 ++++--------- .../fluid/inference/tests/api/trt_models_tester.cc | 5 +++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/inference/tests/api/tester_helper.h b/paddle/fluid/inference/tests/api/tester_helper.h index b1f7a3464..a73fe9c95 100644 --- a/paddle/fluid/inference/tests/api/tester_helper.h +++ b/paddle/fluid/inference/tests/api/tester_helper.h @@ -56,13 +56,6 @@ DECLARE_int32(paddle_num_threads); namespace paddle { namespace inference { -float Random(float low, float high) { - static std::random_device rd; - static std::mt19937 mt(rd()); - std::uniform_real_distribution dist(low, high); - return dist(mt); -} - void PrintConfig(const PaddlePredictor::Config *config, bool use_analysis) { const auto *analysis_config = reinterpret_cast(config); @@ -146,7 +139,8 @@ void SetFakeImageInput(std::vector> *inputs, const std::string &dirname, bool is_combined = true, std::string model_filename = "model", std::string params_filename = "params", - const std::vector *feed_names = nullptr) { + const std::vector *feed_names = nullptr, + const int continuous_inuput_index = 0) { // Set fake_image_data PADDLE_ENFORCE_EQ(FLAGS_test_all_data, 0, "Only have single batch of data."); std::vector> feed_target_shapes = GetFeedTargetShapes( @@ -183,7 +177,8 @@ void SetFakeImageInput(std::vector> *inputs, float *input_data = static_cast(input.data.data()); // fill input data, for profile easily, do not use random data here. for (size_t j = 0; j < len; ++j) { - *(input_data + j) = Random(0.0, 1.0) / 10.; + *(input_data + j) = + static_cast((j + continuous_inuput_index) % len) / len; } } (*inputs).emplace_back(input_slots); diff --git a/paddle/fluid/inference/tests/api/trt_models_tester.cc b/paddle/fluid/inference/tests/api/trt_models_tester.cc index db7109b75..987695cb1 100644 --- a/paddle/fluid/inference/tests/api/trt_models_tester.cc +++ b/paddle/fluid/inference/tests/api/trt_models_tester.cc @@ -119,9 +119,10 @@ void compare_continuous_input(std::string model_dir, bool use_tensorrt) { std::vector> inputs_all; if (!FLAGS_prog_filename.empty() && !FLAGS_param_filename.empty()) { SetFakeImageInput(&inputs_all, model_dir, true, FLAGS_prog_filename, - FLAGS_param_filename); + FLAGS_param_filename, nullptr, i); } else { - SetFakeImageInput(&inputs_all, model_dir, false, "__model__", ""); + SetFakeImageInput(&inputs_all, model_dir, false, "__model__", "", nullptr, + i); } CompareNativeAndAnalysis(native_pred.get(), analysis_pred.get(), inputs_all); -- GitLab