Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FreeForestML
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CERN
fsauerbu
FreeForestML
Merge requests
!52
Resolve "Saving NN with TF 2.x fails"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Saving NN with TF 2.x fails"
56-saving-nn-with-tf-2-x-fails
into
master
Overview
0
Commits
3
Pipelines
1
Changes
1
Merged
Frank Sauerburger
requested to merge
56-saving-nn-with-tf-2-x-fails
into
master
4 years ago
Overview
0
Commits
3
Pipelines
1
Changes
1
Expand
Closes
#56 (closed)
Edited
4 years ago
by
Frank Sauerburger
0
0
Merge request reports
Viewing commit
82e1049d
Prev
Next
Show latest version
1 file
+
14
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Unverified
82e1049d
Store fold models in separate h5 files
· 82e1049d
Frank Sauerburger
authored
4 years ago
nnfwtbn/model.py
+
14
−
10
Options
@@ -636,18 +636,21 @@ class HepNet:
Save the model and all associated components to a hdf5 file.
"""
# save model architecture and weights (only if already trained)
if
len
(
self
.
models
)
==
self
.
cv
.
k
:
for
fold_i
in
range
(
self
.
cv
.
k
):
path_token
=
path
.
rsplit
(
"
.
"
,
1
)
path_token
.
insert
(
-
1
,
f
"
fold_
{
fold_i
}
"
)
# this is the built-in save function from keras
self
.
models
[
fold_i
].
save
(
"
.
"
.
join
(
path_token
))
with
h5py
.
File
(
path
,
"
w
"
)
as
output_file
:
# save default model class
# since this is a arbitrary piece of python code we need to use the python_to_str function
group
=
output_file
.
create_group
(
"
models/default
"
)
group
.
attrs
[
"
model_cls
"
]
=
np
.
string_
(
python_to_str
(
self
.
model_cls
))
# save model architecture and weights (only if already trained)
if
len
(
self
.
models
)
==
self
.
cv
.
k
:
for
fold_i
in
range
(
self
.
cv
.
k
):
group
=
output_file
.
create_group
(
"
models/fold_{}
"
.
format
(
fold_i
))
# this is the built-in save function from keras
self
.
models
[
fold_i
].
save
(
group
)
# save class name of default normalizer as string
group
=
output_file
.
create_group
(
"
normalizers/default
"
)
@@ -696,10 +699,11 @@ class HepNet:
# load trained models (if existing)
with
h5py
.
File
(
path
,
"
r
"
)
as
input_file
:
for
fold_i
in
range
(
cv
.
k
):
key
=
"
models/fold_{}
"
.
format
(
fold_i
)
if
key
in
input_file
:
model
=
keras
.
models
.
load_model
(
input_file
[
key
])
instance
.
models
.
append
(
model
)
path_token
=
path
.
rsplit
(
"
.
"
,
1
)
path_token
.
insert
(
-
1
,
f
"
fold_
{
fold_i
}
"
)
model
=
keras
.
models
.
load_model
(
"
.
"
.
join
(
path_token
))
instance
.
models
.
append
(
model
)
# load normalizer
for
fold_i
in
range
(
cv
.
k
):
Loading