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
2fbba5ff
Commit
2fbba5ff
authored
Jan 03, 2019
by
Shining Sun
Browse files
Bug fix: None check on strategy
parent
82b56ca7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
official/resnet/keras/keras_cifar_main.py
official/resnet/keras/keras_cifar_main.py
+3
-1
official/resnet/keras/keras_common.py
official/resnet/keras/keras_common.py
+19
-0
official/resnet/keras/keras_imagenet_main.py
official/resnet/keras/keras_imagenet_main.py
+4
-1
No files found.
official/resnet/keras/keras_cifar_main.py
View file @
2fbba5ff
...
...
@@ -135,7 +135,9 @@ def run(flags_obj):
strategy
=
distribution_utils
.
get_distribution_strategy
(
flags_obj
.
num_gpus
,
flags_obj
.
turn_off_distribution_strategy
)
with
strategy
.
scope
():
strategy_scope
=
keras_common
.
get_strategy_scope
(
strategy
)
with
strategy_scope
:
optimizer
=
keras_common
.
get_optimizer
()
model
=
resnet_cifar_model
.
resnet56
(
classes
=
cifar_main
.
NUM_CLASSES
)
...
...
official/resnet/keras/keras_common.py
View file @
2fbba5ff
...
...
@@ -210,3 +210,22 @@ def get_synth_input_fn(height, width, num_channels, num_classes,
return
data
return
input_fn
def
get_strategy_scope
(
strategy
):
if
strategy
:
strategy_scope
=
strategy
.
scope
()
else
:
strategy_scope
=
keras_common
.
DummyContextManager
()
return
strategy_scope
class
DummyContextManager
(
object
):
def
__enter__
(
self
):
pass
def
__exit__
(
self
,
*
args
):
pass
official/resnet/keras/keras_imagenet_main.py
View file @
2fbba5ff
...
...
@@ -124,9 +124,12 @@ def run(flags_obj):
strategy
=
distribution_utils
.
get_distribution_strategy
(
flags_obj
.
num_gpus
,
flags_obj
.
turn_off_distribution_strategy
)
with
strategy
.
scope
():
strategy_scope
=
keras_common
.
get_strategy_scope
(
strategy
)
with
strategy_scope
:
optimizer
=
keras_common
.
get_optimizer
()
model
=
resnet_model
.
resnet50
(
num_classes
=
imagenet_main
.
NUM_CLASSES
)
model
.
compile
(
loss
=
'sparse_categorical_crossentropy'
,
optimizer
=
optimizer
,
metrics
=
[
'sparse_categorical_accuracy'
])
...
...
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