Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resnet56 short tests. #6101

Merged
merged 7 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move flag_methods to init
- Address setting default flags repeatedly.
  • Loading branch information
tfboyd committed Jan 30, 2019
commit 2c1d7a55f4ebf2654538416546e17e39f447f058
18 changes: 8 additions & 10 deletions official/resnet/keras/keras_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class KerasBenchmark(object):
"""Base benchmark class with methods to simplify testing."""
local_flags = None

def __init__(self, output_dir=None, default_flags=None):
def __init__(self, output_dir=None, default_flags=None, flag_methods=None):
self.oss_report_object = None
self.output_dir = output_dir
self.default_flags = {}
if default_flags:
self.default_flags = default_flags
self.default_flags = default_flags or {}
self.flag_methods = flag_methods or {}

def _get_model_dir(self, folder_name):
return os.path.join(self.output_dir, folder_name)
Expand All @@ -50,19 +50,17 @@ def _setup(self, flag_methods=None):
"""
tf.logging.set_verbosity(tf.logging.DEBUG)
if KerasBenchmark.local_flags is None:
# TODO(tobyboyd): Move to init and initialize to empty object if None.
if flag_methods:
for flag_method in flag_methods:
flag_method()
for flag_method in 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)
# Overrides flag values with defaults for the class of tests.
for k, v in self.default_flags.items():
setattr(FLAGS, k, v)

def fill_report_object(self, stats, top_1_max=None, top_1_min=None,
log_steps=None, total_batch_size=None, warmup=1):
Expand Down
16 changes: 16 additions & 0 deletions official/resnet/keras/keras_cifar_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
class Resnet56KerasAccuracy(keras_benchmark.KerasBenchmark):
"""Accuracy tests for ResNet56 Keras CIFAR-10."""

def __init__(self, output_dir=None):
flag_methods = [keras_common.define_keras_flags,
cifar_main.define_cifar_flags]

super(Resnet56KerasAccuracy, self).__init__(output_dir=output_dir,
flag_methods=flag_methods)

def keras_resnet56_1_gpu(self):
"""Test keras based model with Keras fit and distribution strategies."""
self._setup()
Expand Down Expand Up @@ -117,6 +124,15 @@ def _setup(self):
class Resnet56KerasBenchmarkBase(keras_benchmark.KerasBenchmark):
"""Short performance tests for ResNet56 via Keras and CIFAR-10."""

def __init__(self, output_dir=None, default_flags=None):
flag_methods = [keras_common.define_keras_flags,
cifar_main.define_cifar_flags]

super(Resnet56KerasBenchmarkBase, self).__init__(
output_dir=output_dir,
flag_methods=flag_methods,
default_flags=default_flags)

def _run_benchmark(self):
stats = keras_cifar_main.run(FLAGS)
self.fill_report_object(stats)
Expand Down