From 5fd68ac1542c9e59137a6ce2e402aa27f74ef47d Mon Sep 17 00:00:00 2001 From: lidanqing Date: Thu, 27 Jun 2019 04:09:40 +0200 Subject: [PATCH] some fixes for int8 mobilenet_ssd tester (#18112) * some fixes for int8 mobilenet_ssd tester test=develop * change wrong data file name test=develop * change test images bin file from 200 images to 100 images * change directory existence to file existence during downloading test=develop * reuse download_data test=develop * run full dataset when iterations=0 test=develop --- .../fluid/inference/tests/api/CMakeLists.txt | 14 +++--- ...alyzer_int8_image_classification_tester.cc | 10 ++-- .../analyzer_int8_object_detection_tester.cc | 49 ++++++++++--------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/paddle/fluid/inference/tests/api/CMakeLists.txt b/paddle/fluid/inference/tests/api/CMakeLists.txt index 243f5cef00..89e843a716 100644 --- a/paddle/fluid/inference/tests/api/CMakeLists.txt +++ b/paddle/fluid/inference/tests/api/CMakeLists.txt @@ -5,22 +5,20 @@ if(WITH_GPU AND TENSORRT_FOUND) endif() function(download_data install_dir data_file) - if (NOT EXISTS ${install_dir}) + if (NOT EXISTS ${install_dir}/${data_file}) inference_download_and_uncompress(${install_dir} ${INFERENCE_URL} ${data_file}) endif() endfunction() function(download_int8_data install_dir data_file) - if (NOT EXISTS ${install_dir}) + if (NOT EXISTS ${install_dir}/${data_file}) inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8 ${data_file}) endif() endfunction() function(download_model_and_data install_dir model_name data_name) - if (NOT EXISTS ${install_dir}) - inference_download_and_uncompress(${install_dir} ${INFERENCE_URL} ${model_name}) - inference_download_and_uncompress(${install_dir} ${INFERENCE_URL} ${data_name}) - endif() + download_data(${install_dir} ${model_name}) + download_data(${install_dir} ${data_name}) endfunction() function(inference_analysis_api_test target install_dir filename) @@ -234,12 +232,12 @@ if(WITH_MKLDNN) inference_analysis_api_int8_test_run(test_analyzer_int8_googlenet ${INT8_IMG_CLASS_TEST_APP} ${INT8_GOOGLENET_MODEL_DIR} ${IMAGENET_DATA_PATH}) ### Object detection models - set(PASCALVOC_DATA_PATH "${INT8_DATA_DIR}/pascalvoc_data.bin") + set(PASCALVOC_DATA_PATH "${INT8_DATA_DIR}/pascalvoc_val_head_100.bin") set(INT8_OBJ_DETECT_TEST_APP "test_analyzer_int8_object_detection") set(INT8_OBJ_DETECT_TEST_APP_SRC "analyzer_int8_object_detection_tester.cc") # download dataset if necessary - download_int8_data(${INT8_DATA_DIR} "pascalvoc_val_100_head.tar.gz") + download_int8_data(${INT8_DATA_DIR} "pascalvoc_val_head_100.tar.gz") # build test binary to be used in subsequent tests inference_analysis_api_int8_test_build(${INT8_OBJ_DETECT_TEST_APP} ${INT8_OBJ_DETECT_TEST_APP_SRC}) diff --git a/paddle/fluid/inference/tests/api/analyzer_int8_image_classification_tester.cc b/paddle/fluid/inference/tests/api/analyzer_int8_image_classification_tester.cc index ae78e07304..3e4a8f3ff3 100644 --- a/paddle/fluid/inference/tests/api/analyzer_int8_image_classification_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_int8_image_classification_tester.cc @@ -70,9 +70,9 @@ std::shared_ptr> GetWarmupData( const std::vector> &test_data, int num_images = FLAGS_warmup_batch_size) { int test_data_batch_size = test_data[0][0].shape[0]; - auto iterations_max = test_data.size(); + auto iterations = test_data.size(); PADDLE_ENFORCE( - static_cast(num_images) <= iterations_max * test_data_batch_size, + static_cast(num_images) <= iterations * test_data_batch_size, "The requested quantization warmup data size " + std::to_string(num_images) + " is bigger than all test data size."); @@ -130,7 +130,11 @@ void SetInput(std::vector> *inputs, label_batch_shape, "label"); auto iterations_max = total_images / batch_size; - for (auto i = 0; i < iterations_max; i++) { + auto iterations = iterations_max; + if (FLAGS_iterations > 0 && FLAGS_iterations < iterations_max) { + iterations = FLAGS_iterations; + } + for (auto i = 0; i < iterations; i++) { auto images = image_reader.NextBatch(); auto labels = label_reader.NextBatch(); inputs->emplace_back( diff --git a/paddle/fluid/inference/tests/api/analyzer_int8_object_detection_tester.cc b/paddle/fluid/inference/tests/api/analyzer_int8_object_detection_tester.cc index 3c86f32bf7..19c38270b7 100644 --- a/paddle/fluid/inference/tests/api/analyzer_int8_object_detection_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_int8_object_detection_tester.cc @@ -79,7 +79,7 @@ class TensorReader { }; void SetInput(std::vector> *inputs, - int32_t batch_size = FLAGS_batch_size, int process_images = 0) { + int32_t batch_size = FLAGS_batch_size) { std::ifstream file(FLAGS_infer_data, std::ios::binary); if (!file) { FAIL() << "Couldn't open file: " << FLAGS_infer_data; @@ -110,9 +110,12 @@ void SetInput(std::vector> *inputs, TensorReader bbox_reader(file, bbox_beginning_offset, "gt_bbox"); TensorReader difficult_reader(file, difficult_beginning_offset, "gt_difficult"); - if (process_images == 0) process_images = total_images; - auto iterations_max = process_images / batch_size; - for (auto i = 0; i < iterations_max; i++) { + auto iterations_max = total_images / batch_size; + auto iterations = iterations_max; + if (FLAGS_iterations > 0 && FLAGS_iterations < iterations_max) { + iterations = FLAGS_iterations; + } + for (auto i = 0; i < iterations; i++) { auto images_tensor = image_reader.NextBatch({batch_size, 3, 300, 300}, {}); std::vector batch_lod(lod_full.begin() + i * batch_size, lod_full.begin() + batch_size * (i + 1)); @@ -139,9 +142,9 @@ std::shared_ptr> GetWarmupData( const std::vector> &test_data, int32_t num_images = FLAGS_warmup_batch_size) { int test_data_batch_size = test_data[0][0].shape[0]; - auto iterations_max = test_data.size(); + auto iterations = test_data.size(); PADDLE_ENFORCE( - static_cast(num_images) <= iterations_max * test_data_batch_size, + static_cast(num_images) <= iterations * test_data_batch_size, "The requested quantization warmup data size " + std::to_string(num_images) + " is bigger than all test data size."); @@ -214,23 +217,23 @@ std::shared_ptr> GetWarmupData( static_cast(difficult.data.data()) + objects_accum); objects_accum = objects_accum + objects_in_batch; } - - size_t objects_remain = test_data[batches][1].lod[0][batch_remain]; - std::copy_n( - static_cast(test_data[batches][0].data.data()), - batch_remain * 3 * 300 * 300, - static_cast(images.data.data()) + objects_accum * 3 * 300 * 300); - std::copy_n(static_cast(test_data[batches][1].data.data()), - objects_remain, - static_cast(labels.data.data()) + objects_accum); - std::copy_n(static_cast(test_data[batches][2].data.data()), - objects_remain * 4, - static_cast(bbox.data.data()) + objects_accum * 4); - std::copy_n(static_cast(test_data[batches][3].data.data()), - objects_remain, - static_cast(difficult.data.data()) + objects_accum); - - objects_accum = objects_accum + objects_remain; + if (batch_remain > 0) { + size_t objects_remain = test_data[batches][1].lod[0][batch_remain]; + std::copy_n(static_cast(test_data[batches][0].data.data()), + batch_remain * 3 * 300 * 300, + static_cast(images.data.data()) + + objects_accum * 3 * 300 * 300); + std::copy_n(static_cast(test_data[batches][1].data.data()), + objects_remain, + static_cast(labels.data.data()) + objects_accum); + std::copy_n(static_cast(test_data[batches][2].data.data()), + objects_remain * 4, + static_cast(bbox.data.data()) + objects_accum * 4); + std::copy_n(static_cast(test_data[batches][3].data.data()), + objects_remain, + static_cast(difficult.data.data()) + objects_accum); + objects_accum = objects_accum + objects_remain; + } PADDLE_ENFORCE( static_cast(num_objects) == static_cast(objects_accum), "The requested num of objects " + std::to_string(num_objects) + -- GitLab