Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
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
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
1e552b18
Commit
1e552b18
authored
7 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Create a checkpoint file for eval
parent
29236312
No related branches found
No related tags found
1 merge request
!52
Implement model saving in bob tf eval. Fixes #54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/script/eval.py
+21
-2
21 additions, 2 deletions
bob/learn/tensorflow/script/eval.py
bob/learn/tensorflow/script/predict_bio.py
+2
-2
2 additions, 2 deletions
bob/learn/tensorflow/script/predict_bio.py
with
23 additions
and
4 deletions
bob/learn/tensorflow/script/eval.py
+
21
−
2
View file @
1e552b18
...
...
@@ -13,7 +13,7 @@ import sys
import
tensorflow
as
tf
import
time
from
glob
import
glob
from
collections
import
defaultdict
from
collections
import
defaultdict
,
OrderedDict
from
..utils.eval
import
get_global_step
from
bob.extension.scripts.click_helper
import
(
verbosity_option
,
ConfigCommand
,
ResourceOption
)
...
...
@@ -33,7 +33,7 @@ def save_n_best_models(train_dir, save_dir, evaluated_file,
lo
=
x
.
get
(
'
loss
'
)
or
0
return
ac
*
-
1
if
ac
is
not
None
else
lo
best_models
=
d
ict
(
sorted
(
best_models
=
OrderedD
ict
(
sorted
(
evaluated
.
items
(),
key
=
_key
)[:
keep_n_best_models
])
# delete the old saved models that are not in top N best anymore
...
...
@@ -57,6 +57,21 @@ def save_n_best_models(train_dir, save_dir, evaluated_file,
logger
.
info
(
"
Copying `%s
'
over to `%s
'"
,
path
,
dst
)
shutil
.
copy
(
path
,
dst
)
# create a checkpoint file indicating to the best existing model:
# 1. filter non-existing models first
def
_filter
(
x
):
return
len
(
glob
(
'
{}/model.ckpt-{}.*
'
.
format
(
save_dir
,
x
[
0
])))
>
0
best_models
=
OrderedDict
(
filter
(
_filter
,
best_models
.
items
()))
# 2. create the checkpoint file
with
open
(
os
.
path
.
join
(
save_dir
,
'
checkpoint
'
),
'
wt
'
)
as
f
:
for
i
,
global_step
in
enumerate
(
best_models
):
if
i
==
0
:
f
.
write
(
'
model_checkpoint_path:
"
model.ckpt-{}
"
\n
'
.
format
(
global_step
))
f
.
write
(
'
all_model_checkpoint_paths:
"
model.ckpt-{}
"
\n
'
.
format
(
global_step
))
def
read_evaluated_file
(
path
):
evaluated
=
{}
...
...
@@ -155,6 +170,10 @@ def eval(estimator, eval_input_fn, hooks, run_once, eval_interval_secs, name,
if
os
.
path
.
exists
(
evaluated_file
):
evaluated_steps
=
read_evaluated_file
(
evaluated_file
)
# Save the best N models into the eval directory
save_n_best_models
(
estimator
.
model_dir
,
eval_dir
,
evaluated_file
,
keep_n_best_models
)
ckpt
=
tf
.
train
.
get_checkpoint_state
(
estimator
.
model_dir
)
if
(
not
ckpt
)
or
(
not
ckpt
.
model_checkpoint_path
):
time
.
sleep
(
eval_interval_secs
)
...
...
This diff is collapsed.
Click to expand it.
bob/learn/tensorflow/script/predict_bio.py
+
2
−
2
View file @
1e552b18
...
...
@@ -74,8 +74,8 @@ def save_predictions(pool, output_dir, key, pred_buffer):
entry_point_group
=
'
bob.learn.tensorflow.hook
'
)
@click.option
(
'
--predict-keys
'
,
'
-k
'
,
multiple
=
True
,
default
=
None
,
cls
=
ResourceOption
)
@click.option
(
'
--checkpoint-path
'
,
cls
=
ResourceOption
)
@click.option
(
'
--multiple-samples
'
,
is_flag
=
True
,
cls
=
ResourceOption
)
@click.option
(
'
--checkpoint-path
'
,
'
-c
'
,
cls
=
ResourceOption
)
@click.option
(
'
--multiple-samples
'
,
'
-m
'
,
is_flag
=
True
,
cls
=
ResourceOption
)
@click.option
(
'
--array
'
,
'
-t
'
,
type
=
click
.
INT
,
default
=
1
,
cls
=
ResourceOption
)
@click.option
(
'
--force
'
,
'
-f
'
,
is_flag
=
True
,
cls
=
ResourceOption
)
@verbosity_option
(
cls
=
ResourceOption
)
...
...
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