From d74ea0855fe7c17ac237670a28d3a276366ce4f0 Mon Sep 17 00:00:00 2001 From: Adam <38704900+grygielski@users.noreply.github.com> Date: Thu, 14 Nov 2019 04:23:17 +0100 Subject: [PATCH] Add relative error measure when (value > 1) (#21144) * Add relative error measure when value > 1 test=develop * Move code to CheckError function test=develop --- paddle/fluid/inference/tests/api/tester_helper.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/inference/tests/api/tester_helper.h b/paddle/fluid/inference/tests/api/tester_helper.h index 463fc4b12f..b3c3da54d1 100644 --- a/paddle/fluid/inference/tests/api/tester_helper.h +++ b/paddle/fluid/inference/tests/api/tester_helper.h @@ -92,6 +92,14 @@ void PrintConfig(const PaddlePredictor::Config *config, bool use_analysis) { LOG(INFO) << analysis_config->ToNativeConfig(); } +void CheckError(float data_ref, float data) { + if (std::abs(data_ref) > 1) { + CHECK_LE(std::abs((data_ref - data) / data_ref), FLAGS_accuracy); + } else { + CHECK_LE(std::abs(data_ref - data), FLAGS_accuracy); + } +} + // Compare result between two PaddleTensor void CompareResult(const std::vector &outputs, const std::vector &ref_outputs) { @@ -118,7 +126,7 @@ void CompareResult(const std::vector &outputs, float *pdata = static_cast(out.data.data()); float *pdata_ref = static_cast(ref_out.data.data()); for (size_t j = 0; j < size; ++j) { - CHECK_LE(std::abs(pdata_ref[j] - pdata[j]), FLAGS_accuracy); + CheckError(pdata_ref[j], pdata[j]); } break; } @@ -169,7 +177,7 @@ void CompareResult(const std::vector &outputs, float *pdata_ref = ref_out.data(&place, &ref_size); EXPECT_EQ(size, ref_size); for (size_t j = 0; j < size; ++j) { - CHECK_LE(std::abs(pdata_ref[j] - pdata[j]), FLAGS_accuracy); + CheckError(pdata_ref[j], pdata[j]); } break; }