Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] detect model test2 for dynamic shape #18372

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4ea200e
clear cache when tid == 1 and cache size exceeds max capacity
LeoZhao-Intel Jun 24, 2019
2088f4c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
LeoZhao-Intel Jun 24, 2019
3d2e563
add more logs to print blob status
LeoZhao-Intel Jun 24, 2019
14c5b2e
1. Add new interface in AnalysisConfig to set mkldnn thread id
LeoZhao-Intel Jun 25, 2019
29ca760
change to use VLOG(2)
LeoZhao-Intel Jun 25, 2019
76db898
detect model test for dynamic shape
luotao1 Jun 25, 2019
6a97049
load input data one by one
luotao1 Jun 26, 2019
1a47373
each iteration use new threads
luotao1 Jun 26, 2019
c0419de
Merge branch 'develop' into detect_model
luotao1 Jun 27, 2019
d27c757
fix input_slot_all memory leak
luotao1 Jun 27, 2019
f6ed3d1
Merge branch 'cache_clearing' of https://github.com/LeoZhao-Intel/Pad…
luotao1 Jun 27, 2019
634d8c6
change KeyBlob from vector to map for speedup
luotao1 Jun 27, 2019
2de7f41
PaddlePaddle memory leak test=develop
pawelpiotrowicz Jun 27, 2019
4826196
use input_shape to setBlob
luotao1 Jun 27, 2019
29af2e3
Merge branch 'develop' into detect_model_test
luotao1 Jun 28, 2019
725f451
refine device_context, make blobMap etc more cleaner
luotao1 Jun 28, 2019
e8305ea
add MkldnnPreRun and MkldnnPostRun interface
luotao1 Jun 28, 2019
266a201
add EnableMKLDNN(int mkldnn_input_shape_cache_size = 1) inferace
luotao1 Jun 28, 2019
0d8f70a
Merge branch 'develop' into detect_model_test
luotao1 Jun 28, 2019
0e9aec9
Merge branch 'pawepiot/paddlepaddle_memory_leak' of https://github.co…
luotao1 Jun 28, 2019
086f347
Revert "PaddlePaddle memory leak test=develop"
luotao1 Jun 28, 2019
6d5a841
make unit-test support head-checker
luotao1 Jun 29, 2019
d91c910
use static variable to do cache instead of tread local in thread freq…
LeoZhao-Intel Jul 1, 2019
1008c2a
Merge branch 'develop' into detect_model_test
luotao1 Jul 1, 2019
d6597b9
use marco to control code given it is specific for mkldnn
LeoZhao-Intel Jul 1, 2019
7251426
Merge branch 'mt_memoryleak' of https://github.com/LeoZhao-Intel/Padd…
luotao1 Jul 1, 2019
b03d25a
Merge branch 'develop' into detect_model_test
luotao1 Jul 2, 2019
91dec55
Merge branch 'develop' into detect_model_test
luotao1 Jul 3, 2019
3a5cdc4
Merge branch 'develop' into detect_model_test
luotao1 Jul 3, 2019
be64967
Merge branch 'develop' into detect_model_test
luotao1 Jul 8, 2019
5480edf
fix conflict with develop
luotao1 Jul 8, 2019
1f9ca7d
Merge branch 'develop' into detect_model_test
luotao1 Jul 8, 2019
1ba6599
Merge branch 'develop' into detect_model_test
luotao1 Jul 11, 2019
65e3865
checkout develop paddle/fluid/operators/mkldnn/pool_mkldnn_op.cc
luotao1 Jul 11, 2019
330207c
clean detect unit-test
luotao1 Jul 11, 2019
d4997de
Merge branch 'develop' into detect_model_test
luotao1 Oct 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions paddle/fluid/inference/tests/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ if (NOT EXISTS ${MOBILENET_INSTALL_DIR})
endif()
inference_analysis_api_test_with_refer_result(test_analyzer_mobilenet_transpose ${MOBILENET_INSTALL_DIR} analyzer_vis_tester.cc)

# detect
inference_analysis_api_test_with_refer_result(test_analyzer_detect ${OCR_INSTALL_DIR} analyzer_detect_tester.cc)
#target_link_libraries(test_analyzer_detect tcmalloc)

### Image classification tests with fake data
set(IMG_CLASS_TEST_APP "test_analyzer_image_classification")
set(IMG_CLASS_TEST_APP_SRC "analyzer_image_classification_tester.cc")
Expand Down
154 changes: 154 additions & 0 deletions paddle/fluid/inference/tests/api/analyzer_detect_tester.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

// #include <gperftools/heap-checker.h>
#include <gtest/gtest.h>
#include <fstream>
#include <iostream>
#include "paddle/fluid/inference/tests/api/tester_helper.h"
DEFINE_string(infer_shape, "", "data shape file");
DEFINE_int32(sample, 1, "number of sample");

namespace paddle {
namespace inference {
namespace analysis {

struct Record {
std::vector<float> data;
std::vector<int32_t> shape;
};

Record ProcessALine(const std::string &line, const std::string &shape_line) {
VLOG(3) << "process a line";
std::vector<std::string> columns;

Record record;
std::vector<std::string> data_strs;
split(line, ' ', &data_strs);
for (auto &d : data_strs) {
record.data.push_back(std::stof(d));
}

std::vector<std::string> shape_strs;
split(shape_line, ' ', &shape_strs);
for (auto &s : shape_strs) {
record.shape.push_back(std::stoi(s));
}
// VLOG(3) << "data size " << record.data.size();
// VLOG(3) << "data shape size " << record.shape.size();
// LOG(INFO) << "data shape size " << record.shape[3];
return record;
}

void SetConfig(AnalysisConfig *cfg) {
cfg->SetModel(FLAGS_infer_model + "/model", FLAGS_infer_model + "/params");
cfg->DisableGpu();
cfg->SwitchIrDebug();
cfg->SwitchSpecifyInputNames(false);
cfg->SetCpuMathLibraryNumThreads(FLAGS_paddle_num_threads);
}

void SetInput(std::vector<std::vector<PaddleTensor>> *inputs,
const std::string &line, const std::string &shape_line) {
auto record = ProcessALine(line, shape_line);

PaddleTensor input;
input.shape = record.shape;
input.dtype = PaddleDType::FLOAT32;
size_t input_size = record.data.size() * sizeof(float);
input.data.Resize(input_size);
memcpy(input.data.data(), record.data.data(), input_size);
std::vector<PaddleTensor> input_slots;
input_slots.assign({input});
(*inputs).emplace_back(input_slots);
}

// Easy for profiling independently.
// ocr, mobilenet and se_resnext50
void profile(bool use_mkldnn = false) {
AnalysisConfig cfg;
SetConfig(&cfg);
if (use_mkldnn) {
cfg.EnableMKLDNN();
cfg.SetMkldnnCacheCapacity(10);
}
// cfg.pass_builder()->TurnOnDebug();
std::vector<std::vector<PaddleTensor>> outputs;
std::vector<std::vector<PaddleTensor>> input_slots_all;

Timer run_timer;
double elapsed_time = 0;

int iterations = FLAGS_sample;
int num_times = FLAGS_repeat;
auto predictor = CreatePaddlePredictor<AnalysisConfig>(cfg);
outputs.resize(iterations);

std::vector<std::thread> threads;

for (int j = 0; j < num_times; j++) {
std::ifstream file(FLAGS_infer_data);
std::ifstream infer_file(FLAGS_infer_shape);
std::string line;
std::string shape_line;

for (int i = 0; i < iterations; i++) {
threads.emplace_back([&, i]() {
std::getline(file, line);
std::getline(infer_file, shape_line);
SetInput(&input_slots_all, line, shape_line);

run_timer.tic();
predictor->Run(input_slots_all[0], &outputs[0], FLAGS_batch_size);
elapsed_time += run_timer.toc();
});
threads[0].join();
threads.clear();
if (i % 100 == 0) LOG(INFO) << i << " samples";
std::vector<std::vector<PaddleTensor>>().swap(input_slots_all);
}

file.close();
infer_file.close();
}

auto batch_latency = elapsed_time / (iterations * num_times);
PrintTime(FLAGS_batch_size, num_times, FLAGS_num_threads, 0, batch_latency,
iterations, VarType::FP32);
}

TEST(Analyzer_vis, profile) { profile(); }

#ifdef PADDLE_WITH_MKLDNN
TEST(Analyzer_vis, profile_mkldnn) { profile(true /* use_mkldnn */); }
#endif

} // namespace analysis
} // namespace inference
} // namespace paddle

// following lines are used for pprof
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove followings main function if you do not want to use pprof.

// int main(int argc, char **argv) {
// HeapLeakChecker heap_checker("test_foo");
// FLAGS_infer_model = "third_party/inference_demo/face_model/densebox";
// FLAGS_infer_data =
// "third_party/inference_demo/face_model/detect_input.txt";
// FLAGS_infer_shape = "third_party/inference_demo/face_model/shape.txt";
// FLAGS_paddle_num_threads = 4;
// FLAGS_repeat = 1;
// FLAGS_batch_size = 1;
// FLAGS_sample = 10;
// paddle::inference::analysis::profile(true);
// std::cout << heap_checker.NoLeaks() << std::endl;
// }