From fe0957303f62a87b736050c32f45270df5b4e1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= <1671644+arrufat@users.noreply.github.com> Date: Fri, 6 Aug 2021 20:32:53 +0900 Subject: [PATCH] Add progress information to console_progress_indicator (#2411) * add progress information (current/total and percent) * print a new line instead of overwritting with spaces * check if target_val is an integer with std::trunc --- dlib/console_progress_indicator.h | 16 +++++++++++++--- dlib/image_processing/shape_predictor_trainer.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dlib/console_progress_indicator.h b/dlib/console_progress_indicator.h index e03b68632..464a5e02c 100644 --- a/dlib/console_progress_indicator.h +++ b/dlib/console_progress_indicator.h @@ -30,7 +30,8 @@ namespace dlib } The above code will print a message to the console each iteration - which shows how much time is remaining until the loop terminates. + which shows the current progress and how much time is remaining until + the loop terminates. !*/ public: @@ -72,8 +73,8 @@ namespace dlib /*! ensures - print_status() assumes it is called with values which are linearly - approaching target(). It will attempt to predict how much time is - remaining until cur becomes equal to target(). + approaching target(). It will display the current progress and attempt + to predict how much time is remaining until cur becomes equal to target(). - prints a status message to out which indicates how much more time is left until cur is equal to target() - if (always_print) then @@ -156,6 +157,15 @@ namespace dlib out.setf(std::ios::fixed,std::ios::floatfield); std::streamsize ss; + if (std::trunc(target_val) == target_val) + ss = out.precision(0); + else + ss = out.precision(2); + + out << "Progress: " << cur << "/" << target_val; + ss = out.precision(2); + out << " (" << cur / target_val * 100. << "%). "; + if (seconds < 60) { ss = out.precision(0); diff --git a/dlib/image_processing/shape_predictor_trainer.h b/dlib/image_processing/shape_predictor_trainer.h index 01a3403ca..e5aa88110 100644 --- a/dlib/image_processing/shape_predictor_trainer.h +++ b/dlib/image_processing/shape_predictor_trainer.h @@ -346,7 +346,7 @@ namespace dlib } if (_verbose) - std::cout << "Training complete " << std::endl; + std::cout << "\nTraining complete" << std::endl; return shape_predictor(initial_shape, forests, pixel_coordinates); }