From 2610f728f02f17e7a5987ab8e1b1ec655cadd77d Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Fri, 8 Nov 2019 17:07:59 +0200 Subject: [PATCH] Revert "Revert some of the earlier change" This reverts commit 6c852124efe6473a5c962de0091709129d6fcde3. --- dlib/dnn/trainer.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dlib/dnn/trainer.h b/dlib/dnn/trainer.h index 95980980d..7ef94d31a 100644 --- a/dlib/dnn/trainer.h +++ b/dlib/dnn/trainer.h @@ -1099,15 +1099,18 @@ namespace dlib return true; } - // if we haven't seen much data yet then just say false. Or, alternatively, if - // it's been too long since the last sync then don't reload either. - if (gradient_updates_since_last_sync < 30 || previous_loss_values.size() < 2*gradient_updates_since_last_sync) + // if we haven't seen much data yet then just say false. + if (gradient_updates_since_last_sync < 30) return false; // Now look at the data since a little before the last disk sync. We will // check if the loss is getting better or worse. running_gradient g; - for (size_t i = previous_loss_values.size() - 2*gradient_updates_since_last_sync; i < previous_loss_values.size(); ++i) + const size_t first_index + = previous_loss_values.size() < 2 * gradient_updates_since_last_sync + ? 0 + : previous_loss_values.size() - 2 * gradient_updates_since_last_sync; + for (size_t i = first_index; i < previous_loss_values.size(); ++i) g.add(previous_loss_values[i]); // if the loss is very likely to be increasing then return true