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
82b56ca7
Commit
82b56ca7
authored
Jan 03, 2019
by
Shining Sun
Browse files
Use strategy.scope()
parent
2c4762d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
+12
-13
official/resnet/keras/keras_cifar_main.py
official/resnet/keras/keras_cifar_main.py
+6
-6
official/resnet/keras/keras_imagenet_main.py
official/resnet/keras/keras_imagenet_main.py
+6
-7
No files found.
official/resnet/keras/keras_cifar_main.py
View file @
82b56ca7
...
...
@@ -132,16 +132,16 @@ def run(flags_obj):
num_epochs
=
flags_obj
.
train_epochs
,
parse_record_fn
=
parse_record_keras
)
optimizer
=
keras_common
.
get_optimizer
()
strategy
=
distribution_utils
.
get_distribution_strategy
(
flags_obj
.
num_gpus
,
flags_obj
.
turn_off_distribution_strategy
)
model
=
resnet_cifar_model
.
resnet56
(
classes
=
cifar_main
.
NUM_CLASSES
)
with
strategy
.
scope
():
optimizer
=
keras_common
.
get_optimizer
()
model
=
resnet_cifar_model
.
resnet56
(
classes
=
cifar_main
.
NUM_CLASSES
)
model
.
compile
(
loss
=
'categorical_crossentropy'
,
optimizer
=
optimizer
,
metrics
=
[
'categorical_accuracy'
],
distribute
=
strategy
)
model
.
compile
(
loss
=
'categorical_crossentropy'
,
optimizer
=
optimizer
,
metrics
=
[
'categorical_accuracy'
])
time_callback
,
tensorboard_callback
,
lr_callback
=
keras_common
.
get_callbacks
(
learning_rate_schedule
,
cifar_main
.
NUM_IMAGES
[
'train'
])
...
...
official/resnet/keras/keras_imagenet_main.py
View file @
82b56ca7
...
...
@@ -121,16 +121,15 @@ def run(flags_obj):
num_epochs
=
flags_obj
.
train_epochs
,
parse_record_fn
=
parse_record_keras
)
optimizer
=
keras_common
.
get_optimizer
()
strategy
=
distribution_utils
.
get_distribution_strategy
(
flags_obj
.
num_gpus
,
flags_obj
.
turn_off_distribution_strategy
)
model
=
resnet_model
.
resnet50
(
num_classes
=
imagenet_main
.
NUM_CLASSES
)
model
.
compile
(
loss
=
'sparse_categorical_crossentropy'
,
optimizer
=
optimizer
,
metrics
=
[
'sparse_categorical_accuracy'
]
,
distribute
=
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'
]
)
time_callback
,
tensorboard_callback
,
lr_callback
=
keras_common
.
get_callbacks
(
learning_rate_schedule
,
imagenet_main
.
NUM_IMAGES
[
'train'
])
...
...
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