diff --git a/conftest.py b/conftest.py index d8f0897ff8096e30f4b7f7e06f709eda11a629e2..207606e6ec111459302360f5f2c4f917771bf80d 100644 --- a/conftest.py +++ b/conftest.py @@ -27,7 +27,7 @@ def execute_removing(path): if "data" in list_dir and path != os.path.dirname(__file__): # do not delete data folder in src shutil.rmtree(os.path.join(path, "data"), ignore_errors=True) # remove TestExperiment folders - remove_files_from_regex(list_dir, path, re.compile(r"TestExperiment_.*")) + remove_files_from_regex(list_dir, path, re.compile(r"TestExperiment.*")) # remove all tracking json remove_files_from_regex(list_dir, path, re.compile(r"tracking_\d*\.json")) # remove all tracking pdf diff --git a/src/model_modules/model_class.py b/src/model_modules/model_class.py index 5dd69608e0ad6e66b250505c3fffa037bba212a4..dab2e168c5a9f87d4aee42fc94489fd0fa67772a 100644 --- a/src/model_modules/model_class.py +++ b/src/model_modules/model_class.py @@ -119,7 +119,6 @@ from typing import Any, Callable, Dict import keras import tensorflow as tf -import logging from src.model_modules.inception_model import InceptionModelBase from src.model_modules.flatten import flatten_tail from src.model_modules.advanced_paddings import PadUtils, Padding2D @@ -355,7 +354,6 @@ class MyLittleModel(AbstractModelClass): self.channels = channels self.dropout_rate = 0.1 self.regularizer = keras.regularizers.l2(0.1) - self.batch_size = int(256) self.activation = keras.layers.PReLU # apply to model @@ -428,7 +426,6 @@ class MyBranchedModel(AbstractModelClass): self.channels = channels self.dropout_rate = 0.1 self.regularizer = keras.regularizers.l2(0.1) - self.batch_size = int(256) self.activation = keras.layers.PReLU # apply to model @@ -502,7 +499,6 @@ class MyTowerModel(AbstractModelClass): self.initial_lr = 1e-2 self.lr_decay = src.model_modules.keras_extensions.LearningRateDecay(base_lr=self.initial_lr, drop=.94, epochs_drop=10) - self.batch_size = int(256 * 4) self.activation = keras.layers.PReLU # apply to model @@ -615,7 +611,6 @@ class MyPaperModel(AbstractModelClass): self.initial_lr = 1e-3 self.lr_decay = src.model_modules.keras_extensions.LearningRateDecay(base_lr=self.initial_lr, drop=.94, epochs_drop=10) - self.batch_size = int(256 * 2) self.activation = keras.layers.ELU self.padding = "SymPad2D" diff --git a/src/run.py b/src/run.py index ac1d27b8a05a544bd623bcfd7fca5884986abf2a..eda0373c1e609e0818e98358d00a00beddb63cdf 100644 --- a/src/run.py +++ b/src/run.py @@ -25,7 +25,8 @@ def run(stations=['DEBW107', 'DEBY081', 'DEBW013', 'DEBW076', 'DEBW087', 'DEBW00 train_min_length=None, val_min_length=None, test_min_length=None, evaluate_bootstraps=True, number_of_bootstraps=None, create_new_bootstraps=False, plot_list=None, - model=None): + model=None, + batch_size=None): params = inspect.getfullargspec(ExperimentSetup).args kwargs = {k: v for k, v in locals().items() if k in params} diff --git a/src/run_modules/experiment_setup.py b/src/run_modules/experiment_setup.py index 1f4c063415efc8adae088c965c33d41c36a08bc4..ff6fec842714d599696b8726e9d25aa22e55583f 100644 --- a/src/run_modules/experiment_setup.py +++ b/src/run_modules/experiment_setup.py @@ -233,12 +233,13 @@ class ExperimentSetup(RunEnvironment): create_new_model: bool = None, bootstrap_path=None, permute_data_on_training: bool = None, transformation=None, train_min_length=None, val_min_length=None, test_min_length=None, extreme_values: list = None, extremes_on_right_tail_only: bool = None, evaluate_bootstraps=True, plot_list=None, number_of_bootstraps=None, - create_new_bootstraps=None, data_path: str = None, login_nodes=None, hpc_hosts=None, model=None, epochs=None): + create_new_bootstraps=None, data_path: str = None, login_nodes=None, hpc_hosts=None, model=None, + batch_size=None, epochs=None): # create run framework super().__init__() - # experiment setup + # experiment setup, hyperparameters self._set_param("data_path", path_config.prepare_host(data_path=data_path, sampling=sampling)) self._set_param("hostname", path_config.get_host()) self._set_param("hpc_hosts", hpc_hosts, default=DEFAULT_HPC_HOST_LIST + DEFAULT_HPC_LOGIN_LIST) @@ -257,6 +258,7 @@ class ExperimentSetup(RunEnvironment): upsampling = self.data_store.get("upsampling", "train") permute_data = False if permute_data_on_training is None else permute_data_on_training self._set_param("permute_data", permute_data or upsampling, scope="train") + self._set_param("batch_size", batch_size, default=int(256 * 2)) self._set_param("epochs", epochs, default=20) # set experiment name diff --git a/src/run_modules/model_setup.py b/src/run_modules/model_setup.py index 13a13bb72fd634b6ebbec20f46a3a08a9f0afa8e..f9683b953d85bacf6e452e0a1922e85dfe946cd1 100644 --- a/src/run_modules/model_setup.py +++ b/src/run_modules/model_setup.py @@ -33,6 +33,7 @@ class ModelSetup(RunEnvironment): * `generator` [train] * `window_lead_time` [.] * `window_history_size` [.] + * `model_class` [.] Optional objects * `lr_decay` [model] @@ -43,7 +44,7 @@ class ModelSetup(RunEnvironment): * `hist` [model] * `callbacks` [model] * `model_name` [model] - * all settings from model class like `dropout_rate`, `initial_lr`, `batch_size`, and `optimizer` [model] + * all settings from model class like `dropout_rate`, `initial_lr`, and `optimizer` [model] Creates * plot of model architecture `<model_name>.pdf` diff --git a/src/run_modules/training.py b/src/run_modules/training.py index 5df8a15c6e0beae8ea9b1504c654e18df46e7b00..1a0d7beb1ec37bb5e59a4129da58572d79a73636 100644 --- a/src/run_modules/training.py +++ b/src/run_modules/training.py @@ -33,8 +33,8 @@ class Training(RunEnvironment): Required objects [scope] from data store: * `model` [model] - * `batch_size` [model] - * `epochs` [model] + * `batch_size` [.] + * `epochs` [.] * `callbacks` [model] * `model_name` [model] * `experiment_name` [.] @@ -67,7 +67,7 @@ class Training(RunEnvironment): self.train_set: Union[Distributor, None] = None self.val_set: Union[Distributor, None] = None self.test_set: Union[Distributor, None] = None - self.batch_size = self.data_store.get("batch_size", "model") + self.batch_size = self.data_store.get("batch_size") self.epochs = self.data_store.get("epochs") self.callbacks: CallbackHandler = self.data_store.get("callbacks", "model") self.experiment_name = self.data_store.get("experiment_name") diff --git a/test/test_modules/test_model_setup.py b/test/test_modules/test_model_setup.py index 541f8d17c8084a34a75b1907c5ff89b08bea9e03..60d140f8845b25432184de1f3890b3ee4d0b034e 100644 --- a/test/test_modules/test_model_setup.py +++ b/test/test_modules/test_model_setup.py @@ -88,7 +88,7 @@ class TestModelSetup: setup_with_gen.build_model() assert isinstance(setup_with_gen.model, AbstractModelClass) expected = {"window_history_size", "window_lead_time", "channels", "dropout_rate", "regularizer", "initial_lr", - "optimizer", "batch_size", "activation"} + "optimizer", "activation"} assert expected <= self.current_scope_as_set(setup_with_gen) def test_set_channels(self, setup_with_gen_tiny): diff --git a/test/test_modules/test_training.py b/test/test_modules/test_training.py index a26bd18c75ae34d200669141578b5fa3ea2bb7c8..66ba0709c21b105bd798cd35f20715e6c0a83177 100644 --- a/test/test_modules/test_training.py +++ b/test/test_modules/test_training.py @@ -155,7 +155,7 @@ class TestTraining: obj.data_store.set("model", model, "general.model") obj.data_store.set("model_path", model_path, "general") obj.data_store.set("model_name", os.path.join(model_path, "test_model.h5"), "general.model") - obj.data_store.set("batch_size", 256, "general.model") + obj.data_store.set("batch_size", 256, "general") obj.data_store.set("epochs", 2, "general.model") clbk, hist, lr = callbacks obj.data_store.set("callbacks", clbk, "general.model")