From 8e012919fa301bd95d8c3c3d691b794fdac15110 Mon Sep 17 00:00:00 2001 From: gedoensmax Date: Fri, 6 Sep 2019 16:48:34 +0300 Subject: [PATCH 1/9] remove timestamp from save path --- delira/training/base_experiment.py | 11 ++++------- delira/training/utils.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index 1e5797c1..342ce0e2 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -3,7 +3,6 @@ import logging import pickle import os -from datetime import datetime import copy @@ -13,7 +12,7 @@ from delira.data_loading import BaseDataManager from delira.models import AbstractNetwork - +from delira.training.utils import check_save_path from delira.training.parameters import Parameters from delira.training.base_trainer import BaseNetworkTrainer from delira.training.predictor import Predictor @@ -109,12 +108,10 @@ def __init__(self, if save_path is None: save_path = os.path.abspath(".") - self.save_path = os.path.join(save_path, name, - str(datetime.now().strftime( - "%y-%m-%d_%H-%M-%S"))) + duplicate_number, self.save_path = check_save_path(os.path.join(save_path, name)) - if os.path.isdir(self.save_path): - logger.warning("Save Path %s already exists") + if duplicate_number: + print('Save path is a duplicate and got changed to {}'.format(save_path)) os.makedirs(self.save_path, exist_ok=True) diff --git a/delira/training/utils.py b/delira/training/utils.py index 23dd02eb..6403330e 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -1,6 +1,6 @@ import collections import numpy as np - +import os def recursively_convert_elements(element, check_type, conversion_fn): """ @@ -98,3 +98,13 @@ def convert_to_numpy_identity(*args, **kwargs): _correct_zero_shape) return args, kwargs + +def check_save_path(save_path): + i = 0 + new_path = save_path + run_name = os.path.basename(save_path) + dir_name = os.path.dirname(save_path) + while os.path.isdir(new_path): + i +=1 + new_path = os.path.join(dir_name,run_name + '_{:02d}'.format(i)) + return i , new_path From 08c77d316a07125dbaad6f1376b341950451c550 Mon Sep 17 00:00:00 2001 From: gedoensmax Date: Fri, 6 Sep 2019 17:13:59 +0300 Subject: [PATCH 2/9] apply improvements --- delira/training/base_experiment.py | 5 +---- delira/training/utils.py | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index 342ce0e2..5b07f28d 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -108,10 +108,7 @@ def __init__(self, if save_path is None: save_path = os.path.abspath(".") - duplicate_number, self.save_path = check_save_path(os.path.join(save_path, name)) - - if duplicate_number: - print('Save path is a duplicate and got changed to {}'.format(save_path)) + self.save_path = check_save_path(os.path.join(save_path, name)) os.makedirs(self.save_path, exist_ok=True) diff --git a/delira/training/utils.py b/delira/training/utils.py index 6403330e..666babb7 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -99,7 +99,7 @@ def convert_to_numpy_identity(*args, **kwargs): return args, kwargs -def check_save_path(save_path): +def generate_save_path(save_path): i = 0 new_path = save_path run_name = os.path.basename(save_path) @@ -107,4 +107,6 @@ def check_save_path(save_path): while os.path.isdir(new_path): i +=1 new_path = os.path.join(dir_name,run_name + '_{:02d}'.format(i)) - return i , new_path + if i: + print('Save path is a duplicate and got changed to {}'.format(new_path)) + return new_path From 881624394fd4df16adced2a1c6c3abf0b3a7e079 Mon Sep 17 00:00:00 2001 From: gedoensmax Date: Fri, 6 Sep 2019 18:24:02 +0300 Subject: [PATCH 3/9] bug fix --- delira/training/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/delira/training/utils.py b/delira/training/utils.py index 666babb7..9c32cd4e 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -2,6 +2,7 @@ import numpy as np import os + def recursively_convert_elements(element, check_type, conversion_fn): """ Function to recursively convert all elements @@ -99,14 +100,15 @@ def convert_to_numpy_identity(*args, **kwargs): return args, kwargs -def generate_save_path(save_path): + +def check_save_path(save_path): i = 0 new_path = save_path run_name = os.path.basename(save_path) dir_name = os.path.dirname(save_path) while os.path.isdir(new_path): - i +=1 - new_path = os.path.join(dir_name,run_name + '_{:02d}'.format(i)) + i += 1 + new_path = os.path.join(dir_name, run_name + '_{:02d}'.format(i)) if i: print('Save path is a duplicate and got changed to {}'.format(new_path)) return new_path From bb5caca14c7ab36333719f77c58d2a2973667f40 Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Wed, 2 Oct 2019 00:14:37 +0300 Subject: [PATCH 4/9] New naming convention --- delira/training/base_experiment.py | 4 ++-- delira/training/utils.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index 5b07f28d..15be741f 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -12,7 +12,7 @@ from delira.data_loading import BaseDataManager from delira.models import AbstractNetwork -from delira.training.utils import check_save_path +from delira.training.utils import generate_save_path from delira.training.parameters import Parameters from delira.training.base_trainer import BaseNetworkTrainer from delira.training.predictor import Predictor @@ -108,7 +108,7 @@ def __init__(self, if save_path is None: save_path = os.path.abspath(".") - self.save_path = check_save_path(os.path.join(save_path, name)) + self.save_path = generate_save_path(os.path.join(save_path, name)) os.makedirs(self.save_path, exist_ok=True) diff --git a/delira/training/utils.py b/delira/training/utils.py index 9c32cd4e..5ebe2b21 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -1,6 +1,7 @@ import collections import numpy as np import os +from datetime import datetime def recursively_convert_elements(element, check_type, conversion_fn): @@ -101,14 +102,14 @@ def convert_to_numpy_identity(*args, **kwargs): return args, kwargs -def check_save_path(save_path): +def generate_save_path(save_path): i = 0 - new_path = save_path - run_name = os.path.basename(save_path) - dir_name = os.path.dirname(save_path) - while os.path.isdir(new_path): + now = datetime.now() + while True: + new_path = os.path.join(save_path, '{}_{:02d}_{:02d}_{:03d}'.format(now.year, now.month, now.day, i)) i += 1 - new_path = os.path.join(dir_name, run_name + '_{:02d}'.format(i)) + if not os.path.isdir(new_path): + break if i: print('Save path is a duplicate and got changed to {}'.format(new_path)) return new_path From db653e85589ef1f771f52dfbf66dce92e9825aab Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Wed, 2 Oct 2019 01:40:47 +0000 Subject: [PATCH 5/9] PEP-8 Auto-Fix --- delira/training/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/delira/training/utils.py b/delira/training/utils.py index 5ebe2b21..eeb92408 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -106,7 +106,9 @@ def generate_save_path(save_path): i = 0 now = datetime.now() while True: - new_path = os.path.join(save_path, '{}_{:02d}_{:02d}_{:03d}'.format(now.year, now.month, now.day, i)) + new_path = os.path.join( + save_path, '{}_{:02d}_{:02d}_{:03d}'.format( + now.year, now.month, now.day, i)) i += 1 if not os.path.isdir(new_path): break From 259a50eda13dd877a7defb534d8e8104d80b4ba1 Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Tue, 8 Oct 2019 18:51:18 +0300 Subject: [PATCH 6/9] style cheks fixed --- delira/training/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/delira/training/utils.py b/delira/training/utils.py index eeb92408..d2615a8f 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -113,5 +113,6 @@ def generate_save_path(save_path): if not os.path.isdir(new_path): break if i: - print('Save path is a duplicate and got changed to {}'.format(new_path)) + print('Save path is a duplicate and got changed to {}' + .format(new_path)) return new_path From 0b08706cdd2bdab20aa2e23e617c3d45403ee314 Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Tue, 15 Oct 2019 18:59:26 +0300 Subject: [PATCH 7/9] import fix --- delira/training/base_experiment.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index 423a1f33..e86093ae 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -15,7 +15,8 @@ from delira.data_loading import DataManager from delira.models import AbstractNetwork -from delira.utils import DeliraConfig, generate_save_path +from delira.utils import DeliraConfig +from delira.training.utils import generate_save_path from delira.training.base_trainer import BaseNetworkTrainer from delira.training.predictor import Predictor From f027f7be50c8863df75a64b9d80356b99d063c82 Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Fri, 25 Oct 2019 23:08:52 +0300 Subject: [PATCH 8/9] save path dependent on training continuation --- delira/training/base_experiment.py | 4 +++- delira/training/utils.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index e86093ae..a5a449b8 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -50,6 +50,7 @@ def __init__(self, checkpoint_freq=1, trainer_cls=BaseNetworkTrainer, predictor_cls=Predictor, + continue_training=False, **kwargs): """ @@ -109,7 +110,8 @@ def __init__(self, if save_path is None: save_path = os.path.abspath(".") - self.save_path = generate_save_path(os.path.join(save_path, name)) + self.save_path = generate_save_path( + os.path.join(save_path, name), not continue_training) os.makedirs(self.save_path, exist_ok=True) diff --git a/delira/training/utils.py b/delira/training/utils.py index d2615a8f..bc21bd17 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -102,13 +102,13 @@ def convert_to_numpy_identity(*args, **kwargs): return args, kwargs -def generate_save_path(save_path): +def generate_save_path(save_path, timestamp: bool): i = 0 now = datetime.now() + date_str = '{}_{:02d}_{:02d}_'.format( + now.year, now.month, now.day) if timestamp else '' while True: - new_path = os.path.join( - save_path, '{}_{:02d}_{:02d}_{:03d}'.format( - now.year, now.month, now.day, i)) + new_path = os.path.join(save_path, '{}{:03d}'.format(date_str, i)) i += 1 if not os.path.isdir(new_path): break From 7ac916e7c57ddb75304428a8adc6cc6a9365cdd4 Mon Sep 17 00:00:00 2001 From: Travis AutoPEP8 Fixes Date: Tue, 29 Oct 2019 18:37:12 +0200 Subject: [PATCH 9/9] unique name --- delira/training/base_experiment.py | 12 +++++++++--- delira/training/utils.py | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/delira/training/base_experiment.py b/delira/training/base_experiment.py index a5a449b8..e672d77b 100644 --- a/delira/training/base_experiment.py +++ b/delira/training/base_experiment.py @@ -50,7 +50,7 @@ def __init__(self, checkpoint_freq=1, trainer_cls=BaseNetworkTrainer, predictor_cls=Predictor, - continue_training=False, + unique_name=True, **kwargs): """ @@ -88,6 +88,9 @@ def __init__(self, the trainer class to use for training the model predictor_cls : subclass of :class:`Predictor` the predictor class to use for testing the model + unique_name : boolean + if the name is not unique an experiment with the same + name will be continued **kwargs : additional keyword arguments @@ -110,8 +113,11 @@ def __init__(self, if save_path is None: save_path = os.path.abspath(".") - self.save_path = generate_save_path( - os.path.join(save_path, name), not continue_training) + if unique_name: + self.save_path = generate_save_path( + os.path.join(save_path, name)) + else: + self.save_path = os.path.join(save_path, name) os.makedirs(self.save_path, exist_ok=True) diff --git a/delira/training/utils.py b/delira/training/utils.py index bc21bd17..5d608c11 100644 --- a/delira/training/utils.py +++ b/delira/training/utils.py @@ -102,11 +102,11 @@ def convert_to_numpy_identity(*args, **kwargs): return args, kwargs -def generate_save_path(save_path, timestamp: bool): +def generate_save_path(save_path): i = 0 now = datetime.now() date_str = '{}_{:02d}_{:02d}_'.format( - now.year, now.month, now.day) if timestamp else '' + now.year, now.month, now.day) while True: new_path = os.path.join(save_path, '{}{:03d}'.format(date_str, i)) i += 1