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
db80d57a
Commit
db80d57a
authored
Dec 20, 2018
by
Shining Sun
Browse files
Added some alternative code. About to do dataset
parent
51fc02ae
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
official/resnet/keras/keras_common.py
official/resnet/keras/keras_common.py
+2
-1
official/resnet/keras/keras_imagenet_main.py
official/resnet/keras/keras_imagenet_main.py
+17
-0
No files found.
official/resnet/keras/keras_common.py
View file @
db80d57a
...
...
@@ -105,7 +105,8 @@ def get_optimizer():
learning_rate
=
BASE_LEARNING_RATE
*
FLAGS
.
batch_size
/
256
optimizer
=
tf
.
train
.
MomentumOptimizer
(
learning_rate
=
learning_rate
,
momentum
=
0.9
)
else
:
optimizer
=
tf
.
keras
.
optimizers
.
SGD
(
learning_rate
=
0.1
,
momentum
=
0.9
)
# optimizer = tf.keras.optimizers.SGD(learning_rate=0.1, momentum=0.9)
optimizer
=
gradient_descent_v2
.
SGD
(
learning_rate
=
0.1
,
momentum
=
0.9
)
return
optimizer
...
...
official/resnet/keras/keras_imagenet_main.py
View file @
db80d57a
...
...
@@ -23,6 +23,7 @@ from absl import flags
import
tensorflow
as
tf
# pylint: disable=g-bad-import-order
from
official.resnet
import
imagenet_main
from
official.resnet
import
imagenet_preprocessing
from
official.resnet
import
resnet_run_loop
from
official.resnet.keras
import
keras_common
from
official.resnet.keras
import
resnet50
...
...
@@ -30,6 +31,8 @@ from official.utils.flags import core as flags_core
from
official.utils.logs
import
logger
from
official.utils.misc
import
distribution_utils
# import os
# os.environ['TF2_BEHAVIOR'] = 'enabled'
LR_SCHEDULE
=
[
# (multiplier, epoch to start) tuples
(
1.0
,
5
),
(
0.1
,
30
),
(
0.01
,
60
),
(
0.001
,
80
)
...
...
@@ -69,11 +72,25 @@ def learning_rate_schedule(current_epoch, current_batch, batches_per_epoch, batc
def
parse_record_keras
(
raw_record
,
is_training
,
dtype
):
"""Adjust the shape of label."""
image_buffer
,
label
,
bbox
=
imagenet_main
.
_parse_example_proto
(
raw_record
)
image
=
imagenet_preprocessing
.
preprocess_image
(
image_buffer
=
image_buffer
,
bbox
=
bbox
,
output_height
=
imagenet_main
.
DEFAULT_IMAGE_SIZE
,
output_width
=
imagenet_main
.
DEFAULT_IMAGE_SIZE
,
num_channels
=
imagenet_main
.
NUM_CHANNELS
,
is_training
=
is_training
)
image
=
tf
.
cast
(
image
,
dtype
)
label
=
tf
.
sparse_to_dense
(
label
,
(
imagenet_main
.
NUM_CLASSES
,),
1
)
"""
image, label = imagenet_main.parse_record(raw_record, is_training, dtype)
# Subtract one so that labels are in [0, 1000), and cast to float32 for
# Keras model.
label = tf.cast(tf.cast(tf.reshape(label, shape=[1]), dtype=tf.int32) - 1,
dtype=tf.float32)
"""
return
image
,
label
...
...
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