Skip to content

Commit

Permalink
optim c++ code
Browse files Browse the repository at this point in the history
add warmup
  • Loading branch information
Linaom1214 authored Aug 15, 2022
1 parent 1307522 commit e3d6b73
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cpp/end2end/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,23 @@ 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<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;

yolo.draw_objects(img, Boxes, ClassIndexs, BboxNum);

} else {
std::cerr << "--> arguments not right!" << std::endl;
std::cerr << "--> yolo -model_path ./output.trt -image_path ./demo.jpg" << std::endl;
return -1;
}
}
}

0 comments on commit e3d6b73

Please sign in to comment.