From e3d6b73f7759f8234089afb6a538e72074be81d6 Mon Sep 17 00:00:00 2001 From: Linaom1214 Date: Mon, 15 Aug 2022 19:46:51 +0800 Subject: [PATCH] optim c++ code add warmup --- cpp/end2end/main.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cpp/end2end/main.cpp b/cpp/end2end/main.cpp index c8f1040..8bacd7b 100644 --- a/cpp/end2end/main.cpp +++ b/cpp/end2end/main.cpp @@ -337,20 +337,18 @@ int main(int argc, char** argv) { int* BboxNum = new int[1]; int* ClassIndexs = new int[1000]; Yolo yolo(model_path); - clock_t startTime, endTime; - int num = 0; - double total_time = 0; cv::Mat img; - while (num != 1000) { - startTime = clock(); - img = cv::imread(image_path); + img = cv::imread(image_path); + // warmup + for (int num =0; num < 10; num++) { yolo.Infer(img.cols, img.rows, img.channels(), img.data, Boxes, ClassIndexs, BboxNum); - endTime = clock(); - double cur_timae = (double)(endTime - startTime) / CLOCKS_PER_SEC; - total_time += cur_timae; - num += 1; } - cout << "The run time is:" << total_time / 1000 << "s" << endl; + // run inference + auto start = std::chrono::system_clock::now(); + yolo.Infer(img.cols, img.rows, img.channels(), img.data, Boxes, ClassIndexs, BboxNum); + auto end = std::chrono::system_clock::now(); + std::cout << std::chrono::duration_cast(end - start).count() << "ms" << std::endl; + yolo.draw_objects(img, Boxes, ClassIndexs, BboxNum); } else { @@ -358,4 +356,4 @@ int main(int argc, char** argv) { std::cerr << "--> yolo -model_path ./output.trt -image_path ./demo.jpg" << std::endl; return -1; } -} \ No newline at end of file +}