Skip to content
Snippets Groups Projects
Commit 3b39b07e authored by lukas leufen's avatar lukas leufen
Browse files

was already solved, just updated documentation

parent 771e2f47
No related branches found
No related tags found
4 merge requests!125Release v0.10.0,!124Update Master to new version v0.10.0,!121Resolve "REFAC: set model / loss",!119Resolve "Include advanced data handling in workflow"
Checking pipeline status
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Module for neural models to use during experiment. Module for neural models to use during experiment.
To work properly, each customised model needs to inherit from AbstractModelClass and needs an implementation of the To work properly, each customised model needs to inherit from AbstractModelClass and needs an implementation of the
set_model and set_loss method. set_model method.
In this module, you can find some exemplary model classes that have been build and were running in a experiment. In this module, you can find some exemplary model classes that have been build and were running in a experiment.
...@@ -33,10 +33,11 @@ How to create a customised model? ...@@ -33,10 +33,11 @@ How to create a customised model?
# apply to model # apply to model
self.set_model() self.set_model()
self.set_loss() self.set_compile_options()
self.set_custom_objects(loss=self.loss) self.set_custom_objects(loss=self.compile_options['loss'])
* Make sure to add the `super().__init__()` and at least `set_model()` and `set_loss()` to your custom init method. * Make sure to add the `super().__init__()` and at least `set_model()` and `set_compile_options()` to your custom init
method.
* If you have custom objects in your model, that are not part of keras, you need to add them to custom objects. To do * If you have custom objects in your model, that are not part of keras, you need to add them to custom objects. To do
this, call `set_custom_objects` with arbitrarily kwargs. In the shown example, the loss has been added, because it this, call `set_custom_objects` with arbitrarily kwargs. In the shown example, the loss has been added, because it
wasn't a standard loss. Apart from this, we always encourage you to add the loss as custom object, to prevent wasn't a standard loss. Apart from this, we always encourage you to add the loss as custom object, to prevent
...@@ -60,14 +61,20 @@ How to create a customised model? ...@@ -60,14 +61,20 @@ How to create a customised model?
self.model = keras.Model(inputs=x_input, outputs=[out_main]) self.model = keras.Model(inputs=x_input, outputs=[out_main])
* Your are free, how to design your model. Just make sure to save it in the class attribute model. * Your are free, how to design your model. Just make sure to save it in the class attribute model.
* Finally, set your custom loss. * Additionally, set your custom compile options including the loss.
.. code-block:: python .. code-block:: python
class MyCustomisedModel(AbstractModelClass): class MyCustomisedModel(AbstractModelClass):
def set_loss(self): def set_compile_options(self):
self.initial_lr = 1e-2
self.optimizer = keras.optimizers.SGD(lr=self.initial_lr, momentum=0.9)
self.lr_decay = mlair.model_modules.keras_extensions.LearningRateDecay(base_lr=self.initial_lr,
drop=.94,
epochs_drop=10)
self.loss = keras.losses.mean_squared_error self.loss = keras.losses.mean_squared_error
self.compile_options = {"metrics": ["mse", "mae"]}
* If you have a branched model with multiple outputs, you need either set only a single loss for all branch outputs or * If you have a branched model with multiple outputs, you need either set only a single loss for all branch outputs or
to provide the same number of loss functions considering the right order. E.g. to provide the same number of loss functions considering the right order. E.g.
...@@ -80,7 +87,7 @@ How to create a customised model? ...@@ -80,7 +87,7 @@ How to create a customised model?
... ...
self.model = keras.Model(inputs=x_input, outputs=[out_minor_1, out_minor_2, out_main]) self.model = keras.Model(inputs=x_input, outputs=[out_minor_1, out_minor_2, out_main])
def set_loss(self): def set_compile_options(self):
self.loss = [keras.losses.mean_absolute_error] + # for out_minor_1 self.loss = [keras.losses.mean_absolute_error] + # for out_minor_1
[keras.losses.mean_squared_error] + # for out_minor_2 [keras.losses.mean_squared_error] + # for out_minor_2
[keras.losses.mean_squared_error] # for out_main [keras.losses.mean_squared_error] # for out_main
...@@ -111,7 +118,6 @@ True ...@@ -111,7 +118,6 @@ True
import mlair.model_modules.keras_extensions import mlair.model_modules.keras_extensions
__author__ = "Lukas Leufen, Felix Kleinert" __author__ = "Lukas Leufen, Felix Kleinert"
# __date__ = '2019-12-12'
__date__ = '2020-05-12' __date__ = '2020-05-12'
from abc import ABC from abc import ABC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment