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
59788849
"git@developer.sourcefind.cn:modelzoo/chatglm.git" did not exist on "3392f1874b2fe372c1f4fda728bfba2d8f709a72"
Commit
59788849
authored
Dec 05, 2018
by
Priya Gupta
Browse files
Add option to run eager; make 1 GPU case run without DS
parent
b9d2b1bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
official/resnet/keras/keras_cifar_main.py
official/resnet/keras/keras_cifar_main.py
+17
-6
No files found.
official/resnet/keras/keras_cifar_main.py
View file @
59788849
...
@@ -190,6 +190,9 @@ def run_cifar_with_keras(flags_obj):
...
@@ -190,6 +190,9 @@ def run_cifar_with_keras(flags_obj):
Raises:
Raises:
ValueError: If fp16 is passed as it is not currently supported.
ValueError: If fp16 is passed as it is not currently supported.
"""
"""
if
flags_obj
.
enable_eager
:
tf
.
enable_eager_execution
()
dtype
=
flags_core
.
get_tf_dtype
(
flags_obj
)
dtype
=
flags_core
.
get_tf_dtype
(
flags_obj
)
if
dtype
==
'fp16'
:
if
dtype
==
'fp16'
:
raise
ValueError
(
'dtype fp16 is not supported in Keras. Use the default '
raise
ValueError
(
'dtype fp16 is not supported in Keras. Use the default '
...
@@ -262,11 +265,16 @@ def run_cifar_with_keras(flags_obj):
...
@@ -262,11 +265,16 @@ def run_cifar_with_keras(flags_obj):
loss
=
'categorical_crossentropy'
loss
=
'categorical_crossentropy'
accuracy
=
'categorical_accuracy'
accuracy
=
'categorical_accuracy'
model
.
compile
(
loss
=
loss
,
if
flags_obj
.
num_gpus
==
1
:
optimizer
=
opt
,
model
.
compile
(
loss
=
loss
,
metrics
=
[
accuracy
],
optimizer
=
opt
,
distribute
=
strategy
)
metrics
=
[
accuracy
])
else
:
model
.
compile
(
loss
=
loss
,
optimizer
=
opt
,
metrics
=
[
accuracy
],
distribute
=
strategy
)
steps_per_epoch
=
cifar_main
.
_NUM_IMAGES
[
'train'
]
//
flags_obj
.
batch_size
steps_per_epoch
=
cifar_main
.
_NUM_IMAGES
[
'train'
]
//
flags_obj
.
batch_size
...
@@ -283,7 +291,8 @@ def run_cifar_with_keras(flags_obj):
...
@@ -283,7 +291,8 @@ def run_cifar_with_keras(flags_obj):
num_eval_steps
=
(
cifar_main
.
_NUM_IMAGES
[
'validation'
]
//
num_eval_steps
=
(
cifar_main
.
_NUM_IMAGES
[
'validation'
]
//
flags_obj
.
batch_size
)
flags_obj
.
batch_size
)
print
(
"Executing eagerly?:"
,
tf
.
executing_eagerly
())
model
.
fit
(
train_input_dataset
,
model
.
fit
(
train_input_dataset
,
epochs
=
flags_obj
.
train_epochs
,
epochs
=
flags_obj
.
train_epochs
,
steps_per_epoch
=
steps_per_epoch
,
steps_per_epoch
=
steps_per_epoch
,
...
@@ -300,6 +309,7 @@ def run_cifar_with_keras(flags_obj):
...
@@ -300,6 +309,7 @@ def run_cifar_with_keras(flags_obj):
print
(
'Test loss:'
,
eval_output
[
0
])
print
(
'Test loss:'
,
eval_output
[
0
])
def
main
(
_
):
def
main
(
_
):
with
logger
.
benchmark_context
(
flags
.
FLAGS
):
with
logger
.
benchmark_context
(
flags
.
FLAGS
):
run_cifar_with_keras
(
flags
.
FLAGS
)
run_cifar_with_keras
(
flags
.
FLAGS
)
...
@@ -307,4 +317,5 @@ def main(_):
...
@@ -307,4 +317,5 @@ def main(_):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
tf
.
logging
.
set_verbosity
(
tf
.
logging
.
DEBUG
)
tf
.
logging
.
set_verbosity
(
tf
.
logging
.
DEBUG
)
cifar_main
.
define_cifar_flags
()
cifar_main
.
define_cifar_flags
()
flags
.
DEFINE_boolean
(
name
=
'enable_eager'
,
default
=
False
,
help
=
'Enable eager?'
)
absl_app
.
run
(
main
)
absl_app
.
run
(
main
)
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