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
Merge requests
!21
Resolve "Adopt to the Estimators API"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Adopt to the Estimators API"
40-adopt-to-the-estimators-api
into
master
Overview
21
Commits
23
Pipelines
11
Changes
1
Merged
Tiago de Freitas Pereira
requested to merge
40-adopt-to-the-estimators-api
into
master
7 years ago
Overview
17
Commits
23
Pipelines
11
Changes
1
Expand
Closes
#40 (closed)
Edited
7 years ago
by
Tiago de Freitas Pereira
0
0
Merge request reports
Viewing commit
bbd87082
Prev
Next
Show latest version
1 file
+
31
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
bbd87082
Hacked a hook. Still to be fixed
· bbd87082
Tiago de Freitas Pereira
authored
7 years ago
bob/learn/tensorflow/utils/hooks.py
+
31
−
0
Options
@@ -33,3 +33,34 @@ class LoggerHook(tf.train.SessionRunHook):
@@ -33,3 +33,34 @@ class LoggerHook(tf.train.SessionRunHook):
'
sec/batch)
'
)
'
sec/batch)
'
)
print
(
format_str
%
(
datetime
.
now
(),
self
.
_step
,
loss_value
,
print
(
format_str
%
(
datetime
.
now
(),
self
.
_step
,
loss_value
,
examples_per_sec
,
sec_per_batch
))
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
))
Loading