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
bbd87082
Commit
bbd87082
authored
7 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Hacked a hook. Still to be fixed
parent
2ab444c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!21
Resolve "Adopt to the Estimators API"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/tensorflow/utils/hooks.py
+31
-0
31 additions, 0 deletions
bob/learn/tensorflow/utils/hooks.py
with
31 additions
and
0 deletions
bob/learn/tensorflow/utils/hooks.py
+
31
−
0
View file @
bbd87082
...
...
@@ -33,3 +33,34 @@ class LoggerHook(tf.train.SessionRunHook):
'
sec/batch)
'
)
print
(
format_str
%
(
datetime
.
now
(),
self
.
_step
,
loss_value
,
examples_per_sec
,
sec_per_batch
))
class
LoggerHookEstimator
(
tf
.
train
.
SessionRunHook
):
"""
Logs loss and runtime.
"""
def
__init__
(
self
,
estimator
,
batch_size
,
log_frequency
):
self
.
estimator
=
estimator
self
.
batch_size
=
batch_size
self
.
log_frequency
=
log_frequency
def
begin
(
self
):
self
.
_step
=
-
1
self
.
_start_time
=
time
.
time
()
def
before_run
(
self
,
run_context
):
self
.
_step
+=
1
return
tf
.
train
.
SessionRunArgs
(
self
.
estimator
.
loss
)
# Asks for loss value.
def
after_run
(
self
,
run_context
,
run_values
):
if
self
.
_step
%
self
.
log_frequency
==
0
:
current_time
=
time
.
time
()
duration
=
current_time
-
self
.
_start_time
self
.
_start_time
=
current_time
loss_value
=
run_values
.
results
examples_per_sec
=
self
.
log_frequency
*
self
.
batch_size
/
duration
sec_per_batch
=
float
(
duration
/
self
.
log_frequency
)
format_str
=
(
'
%s: step %d, loss = %.2f (%.1f examples/sec; %.3f
'
'
sec/batch)
'
)
print
(
format_str
%
(
datetime
.
now
(),
self
.
_step
,
loss_value
,
examples_per_sec
,
sec_per_batch
))
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