diff --git a/src/model_modules/model_class.py b/src/model_modules/model_class.py index a240507ce962230e3818d746c2a682cf82364b95..7e76145e0445df0384462974c88bdf797880ce43 100644 --- a/src/model_modules/model_class.py +++ b/src/model_modules/model_class.py @@ -107,8 +107,44 @@ class AbstractModelClass(ABC): @property def compile_options(self) -> Callable: """ - The compile options property allows the user to use all keras.compile() arguments which are not already covered - by __loss and optimizer + The compile options property allows the user to use all keras.compile() arguments. They can ether be passed as + dictionary (1), as attribute, with compile_options=None (2) or as mixture of both of them (3). + The method will raise an Error when the same parameter is set differently. + + Example (1) + .. code-block:: python + def set_compile_options(self): + self.compile_options = {"optimizer": keras.optimizers.SGD(), + "loss": keras.losses.mean_squared_error, + "metrics": ["mse", "mae"]} + + Example (2) + .. code-block:: python + def set_compile_options(self): + self.optimizer = keras.optimizers.SGD() + self.loss = keras.losses.mean_squared_error + self.metrics = ["mse", "mae"] + self.compile_options = None # make sure to use this line + + Example (3) + Correct: + .. code-block:: python + def set_compile_options(self): + self.optimizer = keras.optimizers.SGD() + self.loss = keras.losses.mean_squared_error + self.compile_options = {"metrics": ["mse", "mae"]} + + Incorrect: (Will raise an error) + .. code-block:: python + def set_compile_options(self): + self.optimizer = keras.optimizers.SGD() + self.loss = keras.losses.mean_squared_error + self.compile_options = {"optimizer" = keras.optimizers.Adam(), "metrics": ["mse", "mae"]} + + Note: As long as the attribute and the dict value have exactly the same values, the setter method will not raise + an error + + :return: """ return self.__compile_options @@ -135,15 +171,6 @@ class AbstractModelClass(ABC): raise SyntaxError( f"Got different values for same argument: self.{allow_k}={new_v_attr} and '{allow_k}': {new_v_dic}") - # if not isinstance(value, dict): - # raise TypeError(f"`value' has to be a dictionary. But it is {type(value)}") - # for new_k, new_v in value.items(): - # if new_k in self.__allowed_compile_options.keys(): - # self.__compile_options[new_k] = new_v - # else: - # logging.warning( - # f"`{new_k}' is not a valid additional compile option. Will be ignored in keras.compile()") - def get_settings(self) -> Dict: """ Get all class attributes that are not protected in the AbstractModelClass as dictionary.