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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
f6ad4736
Commit
f6ad4736
authored
3 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
update model load fkts
parent
ce8616af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#86987
failed
3 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mlair/model_modules/abstract_model_class.py
+7
-1
7 additions, 1 deletion
mlair/model_modules/abstract_model_class.py
mlair/model_modules/model_class.py
+11
-6
11 additions, 6 deletions
mlair/model_modules/model_class.py
mlair/run_modules/model_setup.py
+6
-6
6 additions, 6 deletions
mlair/run_modules/model_setup.py
with
24 additions
and
13 deletions
mlair/model_modules/abstract_model_class.py
+
7
−
1
View file @
f6ad4736
...
...
@@ -37,7 +37,13 @@ class AbstractModelClass(ABC):
self
.
__compile_options_is_set
=
False
self
.
_input_shape
=
input_shape
self
.
_output_shape
=
self
.
__extract_from_tuple
(
output_shape
)
# self.avail_gpus = len(K.tensorflow_backend._get_available_gpus())
def
load_model
(
self
,
name
:
str
,
compile
:
bool
=
False
)
->
None
:
hist
=
self
.
model
.
history
self
.
model
.
load_weights
(
name
)
self
.
model
.
history
=
hist
if
compile
is
True
:
self
.
model
.
compile
(
**
self
.
compile_options
)
def
__getattr__
(
self
,
name
:
str
)
->
Any
:
"""
...
...
This diff is collapsed.
Click to expand it.
mlair/model_modules/model_class.py
+
11
−
6
View file @
f6ad4736
...
...
@@ -454,12 +454,12 @@ class IntelliO3TsArchitecture(AbstractModelClass):
kernel_regularizer
=
self
.
regularizer
)
model
=
keras
.
Model
(
inputs
=
X_input
,
outputs
=
[
out_minor1
,
out_main
])
if
self
.
avail_gpus
<=
1
:
self
.
model
=
model
else
:
self
.
model
=
keras
.
utils
.
multi_gpu_model
(
model
,
self
.
avail_gpus
)
print
(
f
"
Set multi_gpu model with
{
self
.
avail_gpus
}
GPUs
"
)
self
.
model
=
keras
.
Model
(
inputs
=
X_input
,
outputs
=
[
out_minor1
,
out_main
])
#
if self.avail_gpus <= 1:
#
self.model = model
#
else:
#
self.model = keras.utils.multi_gpu_model(model, self.avail_gpus)
#
print(f"Set multi_gpu model with {self.avail_gpus} GPUs")
def
set_compile_options
(
self
):
self
.
compile_options
=
{
"
optimizer
"
:
keras
.
optimizers
.
Adam
(
lr
=
self
.
initial_lr
,
amsgrad
=
True
),
...
...
@@ -762,6 +762,11 @@ class MyUnet(AbstractModelClass):
self
.
compile_options
=
{
"
metrics
"
:
[
"
mse
"
,
"
mae
"
]}
class
NN3s
(
MyUnet
):
def
__init__
(
self
,
input_shape
:
list
,
output_shape
:
list
):
super
().
__init__
(
input_shape
,
output_shape
)
class
MySimpleConv2D
(
AbstractModelClass
):
"""
Example adopted from https://www.kaggle.com/dimitreoliveira/deep-learning-for-time-series-forecasting
...
...
This diff is collapsed.
Click to expand it.
mlair/run_modules/model_setup.py
+
6
−
6
View file @
f6ad4736
...
...
@@ -84,7 +84,7 @@ class ModelSetup(RunEnvironment):
# load weights if no training shall be performed
if
not
self
.
_train_model
and
not
self
.
_create_new_model
:
self
.
load_
weights
()
self
.
load_
model
()
# create checkpoint
self
.
_set_callbacks
()
...
...
@@ -131,13 +131,13 @@ class ModelSetup(RunEnvironment):
save_best_only
=
True
,
mode
=
'
auto
'
)
self
.
data_store
.
set
(
"
callbacks
"
,
callbacks
,
self
.
scope
)
def
load_
weights
(
self
):
"""
Try to load
weights from existing model
or skip if not possible.
"""
def
load_
model
(
self
):
"""
Try to load
model from disk
or skip if not possible.
"""
try
:
self
.
model
.
load_
weights
(
self
.
model_name
)
logging
.
info
(
f
"
reload
weights from
model
{
self
.
model_name
}
...
"
)
self
.
model
.
load_
model
(
self
.
model_name
)
logging
.
info
(
f
"
reload model
{
self
.
model_name
}
from disk
...
"
)
except
OSError
:
logging
.
info
(
'
no
weights
to
re
load...
'
)
logging
.
info
(
'
no
local model
to load...
'
)
def
build_model
(
self
):
"""
Build model using input and output shapes from data store.
"""
...
...
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