From 3029bacb4d985821afb5a90f9a708a805a1fbfe5 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Wed, 13 May 2020 17:51:48 +0200
Subject: [PATCH] [script.experiment] Use, preferably, the model with lowest
 validation error

---
 bob/ip/binseg/script/experiment.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bob/ip/binseg/script/experiment.py b/bob/ip/binseg/script/experiment.py
index 30d14e2c..f43fe5fc 100644
--- a/bob/ip/binseg/script/experiment.py
+++ b/bob/ip/binseg/script/experiment.py
@@ -326,7 +326,11 @@ def experiment(
 
     from .analyze import analyze
 
-    model_file = os.path.join(train_output_folder, "model_final.pth")
+    # preferably, we use the best model on the validation set
+    # otherwise, we get the last saved model
+    model_file = os.path.join(train_output_folder, "model_lowest_valid_loss.pth")
+    if not os.path.exists(model_file):
+        model_file = os.path.join(train_output_folder, "model_final.pth")
 
     ctx.invoke(
             analyze,
-- 
GitLab