Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
d3610769
Unverified
Commit
d3610769
authored
Jun 19, 2019
by
Toby Boyd
Committed by
GitHub
Jun 19, 2019
Browse files
Use PerfZeroBenchmark and log Flags. (#7052)
parent
d62ddcaa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
36 deletions
+13
-36
official/resnet/keras/keras_benchmark.py
official/resnet/keras/keras_benchmark.py
+13
-36
No files found.
official/resnet/keras/keras_benchmark.py
View file @
d3610769
...
@@ -18,45 +18,18 @@ from __future__ import absolute_import
...
@@ -18,45 +18,18 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
print_function
import
os
from
official.utils.flags
import
core
as
flags_core
from
official.utils.testing.perfzero_benchmark
import
PerfZeroBenchmark
from
absl
import
flags
from
absl.testing
import
flagsaver
import
tensorflow
as
tf
# pylint: disable=g-bad-import-order
FLAGS
=
flags
.
FLAGS
class
KerasBenchmark
(
PerfZeroBenchmark
):
class
KerasBenchmark
(
tf
.
test
.
Benchmark
):
"""Base benchmark class with methods to simplify testing."""
"""Base benchmark class with methods to simplify testing."""
local_flags
=
None
def
__init__
(
self
,
output_dir
=
None
,
default_flags
=
None
,
flag_methods
=
None
):
def
__init__
(
self
,
output_dir
=
None
,
default_flags
=
None
,
flag_methods
=
None
):
self
.
output_dir
=
output_dir
super
(
KerasBenchmark
,
self
).
__init__
(
self
.
default_flags
=
default_flags
or
{}
output_dir
=
output_dir
,
self
.
flag_methods
=
flag_methods
or
{}
default_flags
=
default_flags
,
flag_methods
=
flag_methods
)
if
not
output_dir
:
self
.
output_dir
=
'/tmp/'
def
_get_model_dir
(
self
,
folder_name
):
return
os
.
path
.
join
(
self
.
output_dir
,
folder_name
)
def
_setup
(
self
):
"""Sets up and resets flags before each test."""
tf
.
compat
.
v1
.
logging
.
set_verbosity
(
tf
.
compat
.
v1
.
logging
.
DEBUG
)
if
KerasBenchmark
.
local_flags
is
None
:
for
flag_method
in
self
.
flag_methods
:
flag_method
()
# Loads flags to get defaults to then override. List cannot be empty.
flags
.
FLAGS
([
'foo'
])
# Overrides flag values with defaults for the class of tests.
for
k
,
v
in
self
.
default_flags
.
items
():
setattr
(
FLAGS
,
k
,
v
)
saved_flag_values
=
flagsaver
.
save_flag_values
()
KerasBenchmark
.
local_flags
=
saved_flag_values
else
:
flagsaver
.
restore_flag_values
(
KerasBenchmark
.
local_flags
)
def
_report_benchmark
(
self
,
def
_report_benchmark
(
self
,
stats
,
stats
,
...
@@ -102,5 +75,9 @@ class KerasBenchmark(tf.test.Benchmark):
...
@@ -102,5 +75,9 @@ class KerasBenchmark(tf.test.Benchmark):
if
'avg_exp_per_second'
in
stats
:
if
'avg_exp_per_second'
in
stats
:
metrics
.
append
({
'name'
:
'avg_exp_per_second'
,
metrics
.
append
({
'name'
:
'avg_exp_per_second'
,
'value'
:
stats
[
'avg_exp_per_second'
]})
'value'
:
stats
[
'avg_exp_per_second'
]})
flags_str
=
flags_core
.
get_nondefault_flags_as_str
()
self
.
report_benchmark
(
iters
=-
1
,
wall_time
=
wall_time_sec
,
metrics
=
metrics
)
self
.
report_benchmark
(
iters
=-
1
,
wall_time
=
wall_time_sec
,
metrics
=
metrics
,
extras
=
{
'flags'
:
flags_str
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment