From 6faa33d1596589e6bb1cbc87719d124351f99931 Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Thu, 30 Jul 2020 16:47:11 +0200
Subject: [PATCH] Included option to validate model on training set

---
 pysegcnn/main/config.py | 18 ++++++++++--------
 pysegcnn/main/eval.py   | 10 +++++++---
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/pysegcnn/main/config.py b/pysegcnn/main/config.py
index 61bdaaa..c03abc1 100644
--- a/pysegcnn/main/config.py
+++ b/pysegcnn/main/config.py
@@ -98,7 +98,7 @@ config = {
     # (ttratio * tvratio) * 100 % will be used as for training
     # (1 - ttratio * tvratio) * 100 % will be used for validation
     # used if split_mode='random' and split_mode='scene'
-    'tvratio': 0.95,
+    'tvratio': 0.8,
 
     # the date to split the scenes
     # format: 'yyyymmdd'
@@ -106,6 +106,7 @@ config = {
     # the validation set, the test set is empty
     # used if split_mode='date'
     'date': 'yyyymmdd',
+    'dateformat': '%Y%m%d',
 
     # define the batch size
     # determines how many samples of the dataset are processed until the
@@ -216,14 +217,14 @@ config = {
 
     # whether to early stop training if the accuracy on the validation set
     # does not increase more than delta over patience epochs
-    'early_stop': False,
+    'early_stop': True,
     'mode': 'max',
     'delta': 0,
     'patience': 10,
 
     # define the number of epochs: the number of maximum iterations over
     # the whole training dataset
-    'epochs': 10,
+    'epochs': 200,
 
     # define the number of threads
     'nthreads': os.cpu_count(),
@@ -244,9 +245,10 @@ config = {
     # these options are only used for evaluating a trained model using
     # main.eval.py
 
-    # whether to evaluate the model on the validation set or test set
+    # the dataset to evaluate the model on
     # test=False means evaluating on the validation set
-    # test=True means evaluationg on the test set
+    # test=True means evaluating on the test set
+    # test=None means evaluating on the training set
     'test': False,
 
     # whether to compute and plot the confusion matrix
@@ -261,13 +263,13 @@ config = {
     #       split_mode="date"
     'predict_scene': True,
 
-    # whether to save plots of (input, ground truth, prediction) of the
-    # samples from the validation/test dataset to disk
+    # whether to save plots of (input, ground truth, prediction) of the samples
+    # from the validation/test dataset to disk, applies if predict_scene=False
     # output path is: pysegcnn/main/_samples/
     'plot_samples': False,
 
     # whether to save plots of (input, ground truth, prediction) for each scene
-    # to disk
+    # in the validation/test dataset to disk, applies if predict_scene=True
     # output path is: pysegcnn/main/_samples/
     'plot_scenes': True,
 
diff --git a/pysegcnn/main/eval.py b/pysegcnn/main/eval.py
index 85a5351..73faa10 100644
--- a/pysegcnn/main/eval.py
+++ b/pysegcnn/main/eval.py
@@ -10,7 +10,7 @@ import os
 # locals
 from pysegcnn.core.trainer import NetworkTrainer
 from pysegcnn.core.predict import predict_samples, predict_scenes
-from pysegcnn.core.config import config, HERE
+from pysegcnn.main.config import config, HERE
 from pysegcnn.core.graphics import plot_confusion_matrix, plot_loss
 
 
@@ -23,8 +23,12 @@ if __name__ == '__main__':
     # plot loss and accuracy
     plot_loss(trainer.loss_state, outpath=os.path.join(HERE, '_graphics/'))
 
-    # check whether to evaluate the model on the validation set or the test set
-    ds = trainer.test_ds if trainer.test else trainer.valid_ds
+    # check whether to evaluate the model on the training set, validation set
+    # or the test set
+    if trainer.test is None:
+        ds = trainer.train_ds
+    else:
+        ds = trainer.test_ds if trainer.test else trainer.valid_ds
 
     # whether to predict each sample or each scene individually
     if trainer.predict_scene:
-- 
GitLab