Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
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
19da59e
Remove all the code, API and doc of MKL-DNN INT8v1 (#18347)
zhaify Jun 27, 2019
6adb535
fix input_slot_all memory leak
luotao1 Jun 27, 2019
9931bc6
add dependecy of collective_helper (#18365)
LLMHao Jun 27, 2019
fd6631e
Fix dygraph show style (#18297)
junjun315 Jun 27, 2019
8ed819d
Call the test_slim_int8_* tests through absolute path (#18386)
Jun 27, 2019
871cc15
Add is_compiled_with_cuda (#18356)
Jun 28, 2019
af874a1
test=develop, fix multigpu hang on latest docker (#18379)
JiabinYang Jun 28, 2019
43f64a1
Fix/program doc (#17908)
JiabinYang Jun 28, 2019
f564100
Add a unittest to inplace elementwise_add (#18385)
sneaxiy Jun 28, 2019
052b044
Fix mac build nproc command not found (#18362)
tianshuo78520a Jun 28, 2019
681d355
Fix potential mkldnn concat/pool/conv kernel issues (#18393)
LeoZhao-Intel Jun 28, 2019
e83f902
add MultiSlotStringDataGenerator for speedup of string based user inp…
guru4elephant Jun 28, 2019
b963079
fix ci document_preview job error (#18399)
tianshuo78520a Jun 28, 2019
2b4ef50
init custom black white list (#18377)
Jie-Fang Jun 28, 2019
ce7a024
fix py-cpuinfo mac random fail (#18383)
tensor-tang Jun 28, 2019
ef81ff7
update pslib library path (#18415)
guru4elephant Jun 29, 2019
93a2b31
fix data feed ptr error (#18419)
xjqbest Jun 29, 2019
8a39e5c
update api format (#18413)
hutuxian Jun 30, 2019
92ecb30
test=develop (#18426)
tianshuo78520a Jul 1, 2019
47e2ef3
add "import paddle.fluid as fluid" to examples lack of it
xsrobin Jul 1, 2019
dd3f9d1
replace mnist dataset url, test=develop (#18429)
tink2123 Jul 1, 2019
4bc2987
Fix bug in quantize kernel which cause crash in vgg16/19 model (#17964)
liujianhang-design Jul 1, 2019
7023a86
Fix Pooling output scale (#18186)
Sand3r- Jul 1, 2019
a3bc804
fix mac ci random fail (#18430)
tensor-tang Jul 1, 2019
2246f7c
Update README.md with latest version
XiaoguangHu01 Jul 1, 2019
99659a9
update README_cn.md with latest version
XiaoguangHu01 Jul 1, 2019
449c7a9
Make roi_perspective_transform op return mask and transform matrix (#…
LielinJiang Jul 1, 2019
e0d8c6a
Add find_no_grad_vars in backward.py (#17942)
Jul 2, 2019
357311f
make fleet support mpi job submit directly (#18441)
guru4elephant Jul 2, 2019
85b49d8
fix the api.spec file does not get the class comment problem (#18439)
tianshuo78520a Jul 2, 2019
a873fa8
supports collective training with programs (#18392)
gavin1332 Jul 2, 2019
3123d18
remove unused AnalysisPredictor::SetMkldnnThreadID() (#18444)
luotao1 Jul 2, 2019
823ab5e
fix load attr error. test=develop (#18447)
heavengate Jul 2, 2019
41ab76e
add friendly error msg to py_reader (#18316)
sneaxiy Jul 2, 2019
8f5fffc
rename mkldnn set/get_cur_thread_id() to set/get_cur_mkldnn_session_i…
LeoZhao-Intel Jul 2, 2019
d30fe34
Merge branch 'detect_model' of https://github.com/luotao1/Paddle into…
luotao1 Jul 3, 2019
510d442
add bert test for transfer_scope_cache
luotao1 Jul 3, 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
3 changes: 3 additions & 0 deletions paddle/fluid/inference/tests/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ 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)

### 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
137 changes: 137 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,137 @@
/* 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 <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.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();
Copy link
Contributor

Choose a reason for hiding this comment

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

this place, the clear method should be same with input_slots_all.

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