Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
3b39b07e
Commit
3b39b07e
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
was already solved, just updated documentation
parent
771e2f47
No related branches found
No related tags found
4 merge requests
!125
Release v0.10.0
,
!124
Update Master to new version v0.10.0
,
!121
Resolve "REFAC: set model / loss"
,
!119
Resolve "Include advanced data handling in workflow"
Checking pipeline status
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlair/model_modules/model_class.py
+14
-8
14 additions, 8 deletions
mlair/model_modules/model_class.py
with
14 additions
and
8 deletions
mlair/model_modules/model_class.py
+
14
−
8
View file @
3b39b07e
...
@@ -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_
los
s()
self.set_
compile_option
s()
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.
*
Fi
nally, set your custom loss.
*
Additio
nally, 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_
los
s(self):
def set_
compile_option
s(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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment