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
1e2ceffd
Unverified
Commit
1e2ceffd
authored
Mar 12, 2020
by
Ayushman Kumar
Committed by
GitHub
Mar 12, 2020
Browse files
Merge pull request #4 from tensorflow/master
Updating
parents
51e60bab
c7adbbe4
Changes
65
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
47 additions
and
44 deletions
+47
-44
official/nlp/xlnet/run_squad.py
official/nlp/xlnet/run_squad.py
+0
-1
official/nlp/xlnet/xlnet_modeling_test.py
official/nlp/xlnet/xlnet_modeling_test.py
+0
-1
official/r1/mnist/mnist_tpu.py
official/r1/mnist/mnist_tpu.py
+10
-10
official/r1/resnet/cifar10_main.py
official/r1/resnet/cifar10_main.py
+1
-0
official/r1/resnet/imagenet_main.py
official/r1/resnet/imagenet_main.py
+2
-1
official/r1/transformer/attention_layer.py
official/r1/transformer/attention_layer.py
+1
-1
official/r1/transformer/dataset.py
official/r1/transformer/dataset.py
+1
-1
official/r1/transformer/embedding_layer.py
official/r1/transformer/embedding_layer.py
+1
-1
official/r1/transformer/ffn_layer.py
official/r1/transformer/ffn_layer.py
+1
-1
official/r1/transformer/schedule.py
official/r1/transformer/schedule.py
+1
-1
official/r1/transformer/schedule_test.py
official/r1/transformer/schedule_test.py
+1
-1
official/r1/transformer/transformer.py
official/r1/transformer/transformer.py
+1
-1
official/r1/transformer/transformer_main.py
official/r1/transformer/transformer_main.py
+1
-1
official/r1/transformer/translate.py
official/r1/transformer/translate.py
+1
-1
official/staging/training/controller.py
official/staging/training/controller.py
+9
-7
official/staging/training/utils.py
official/staging/training/utils.py
+10
-6
official/utils/misc/keras_utils.py
official/utils/misc/keras_utils.py
+3
-2
official/vision/detection/modeling/losses.py
official/vision/detection/modeling/losses.py
+3
-1
official/vision/image_classification/common.py
official/vision/image_classification/common.py
+0
-6
official/vision/image_classification/resnet/__init__.py
official/vision/image_classification/resnet/__init__.py
+0
-0
No files found.
official/nlp/xlnet/run_squad.py
View file @
1e2ceffd
...
...
@@ -301,5 +301,4 @@ def main(unused_argv):
if
__name__
==
"__main__"
:
assert
tf
.
version
.
VERSION
.
startswith
(
'2.'
)
app
.
run
(
main
)
official/nlp/xlnet/xlnet_modeling_test.py
View file @
1e2ceffd
...
...
@@ -49,5 +49,4 @@ class PositionalEmbeddingLayerTest(tf.test.TestCase):
self
.
assertAllClose
(
pos_emb
,
target
)
if
__name__
==
"__main__"
:
assert
tf
.
version
.
VERSION
.
startswith
(
'2.'
)
tf
.
test
.
main
()
official/r1/mnist/mnist_tpu.py
View file @
1e2ceffd
...
...
@@ -28,7 +28,7 @@ import sys
# pylint: disable=g-bad-import-order
from
absl
import
app
as
absl_app
# pylint: disable=unused-import
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
# pylint: enable=g-bad-import-order
# For open source environment, add grandparent directory for import
...
...
@@ -98,7 +98,7 @@ def model_fn(features, labels, mode, params):
'class_ids'
:
tf
.
argmax
(
logits
,
axis
=
1
),
'probabilities'
:
tf
.
nn
.
softmax
(
logits
),
}
return
tf
.
compat
.
v1
.
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
,
predictions
=
predictions
)
return
tf
.
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
,
predictions
=
predictions
)
logits
=
model
(
image
,
training
=
(
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
))
loss
=
tf
.
losses
.
sparse_softmax_cross_entropy
(
labels
=
labels
,
logits
=
logits
)
...
...
@@ -111,14 +111,14 @@ def model_fn(features, labels, mode, params):
decay_rate
=
0.96
)
optimizer
=
tf
.
train
.
GradientDescentOptimizer
(
learning_rate
=
learning_rate
)
if
FLAGS
.
use_tpu
:
optimizer
=
tf
.
compat
.
v1
.
tpu
.
CrossShardOptimizer
(
optimizer
)
return
tf
.
compat
.
v1
.
estimator
.
tpu
.
TPUEstimatorSpec
(
optimizer
=
tf
.
tpu
.
CrossShardOptimizer
(
optimizer
)
return
tf
.
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
train_op
=
optimizer
.
minimize
(
loss
,
tf
.
train
.
get_global_step
()))
if
mode
==
tf
.
estimator
.
ModeKeys
.
EVAL
:
return
tf
.
compat
.
v1
.
estimator
.
tpu
.
TPUEstimatorSpec
(
return
tf
.
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
eval_metrics
=
(
metric_fn
,
[
labels
,
logits
]))
...
...
@@ -128,7 +128,7 @@ def train_input_fn(params):
data_dir
=
params
[
"data_dir"
]
# Retrieves the batch size for the current shard. The # of shards is
# computed according to the input pipeline deployment. See
# `tf.
compat.v1.
estimator.tpu.RunConfig` for details.
# `tf.estimator.tpu.RunConfig` for details.
ds
=
dataset
.
train
(
data_dir
).
cache
().
repeat
().
shuffle
(
buffer_size
=
50000
).
batch
(
batch_size
,
drop_remainder
=
True
)
return
ds
...
...
@@ -159,16 +159,15 @@ def main(argv):
project
=
FLAGS
.
gcp_project
)
run_config
=
tf
.
compat
.
v1
.
estimator
.
tpu
.
RunConfig
(
run_config
=
tf
.
estimator
.
tpu
.
RunConfig
(
cluster
=
tpu_cluster_resolver
,
model_dir
=
FLAGS
.
model_dir
,
session_config
=
tf
.
ConfigProto
(
allow_soft_placement
=
True
,
log_device_placement
=
True
),
tpu_config
=
tf
.
compat
.
v1
.
estimator
.
tpu
.
TPUConfig
(
FLAGS
.
iterations
,
FLAGS
.
num_shards
),
tpu_config
=
tf
.
estimator
.
tpu
.
TPUConfig
(
FLAGS
.
iterations
,
FLAGS
.
num_shards
),
)
estimator
=
tf
.
compat
.
v1
.
estimator
.
tpu
.
TPUEstimator
(
estimator
=
tf
.
estimator
.
tpu
.
TPUEstimator
(
model_fn
=
model_fn
,
use_tpu
=
FLAGS
.
use_tpu
,
train_batch_size
=
FLAGS
.
batch_size
,
...
...
@@ -199,4 +198,5 @@ def main(argv):
if
__name__
==
"__main__"
:
tf
.
disable_v2_behavior
()
absl_app
.
run
(
main
)
official/r1/resnet/cifar10_main.py
View file @
1e2ceffd
...
...
@@ -22,6 +22,7 @@ import os
from
absl
import
app
as
absl_app
from
absl
import
flags
from
six.moves
import
range
import
tensorflow
as
tf
# pylint: disable=g-bad-import-order
from
official.r1.resnet
import
resnet_model
...
...
official/r1/resnet/imagenet_main.py
View file @
1e2ceffd
...
...
@@ -22,6 +22,7 @@ import os
from
absl
import
app
as
absl_app
from
absl
import
flags
from
six.moves
import
range
import
tensorflow
as
tf
from
official.r1.resnet
import
imagenet_preprocessing
...
...
@@ -307,7 +308,7 @@ def _get_block_sizes(resnet_size):
except
KeyError
:
err
=
(
'Could not find layers for selected Resnet size.
\n
'
'Size received: {}; sizes allowed: {}.'
.
format
(
resnet_size
,
choices
.
keys
()))
resnet_size
,
list
(
choices
.
keys
()))
)
raise
ValueError
(
err
)
...
...
official/r1/transformer/attention_layer.py
View file @
1e2ceffd
...
...
@@ -18,7 +18,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
class
Attention
(
tf
.
layers
.
Layer
):
...
...
official/r1/transformer/dataset.py
View file @
1e2ceffd
...
...
@@ -54,7 +54,7 @@ from __future__ import print_function
import
math
import
os
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
from
official.utils.misc
import
model_helpers
...
...
official/r1/transformer/embedding_layer.py
View file @
1e2ceffd
...
...
@@ -18,7 +18,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
tensorflow
as
tf
# pylint: disable=g-bad-import-order
import
tensorflow
.compat.v1
as
tf
# pylint: disable=g-bad-import-order
from
official.r1.utils
import
tpu
as
tpu_utils
...
...
official/r1/transformer/ffn_layer.py
View file @
1e2ceffd
...
...
@@ -18,7 +18,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
class
FeedFowardNetwork
(
tf
.
layers
.
Layer
):
...
...
official/r1/transformer/schedule.py
View file @
1e2ceffd
...
...
@@ -20,7 +20,7 @@ from __future__ import print_function
import
math
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
_TRAIN
,
_EVAL
=
tf
.
estimator
.
ModeKeys
.
TRAIN
,
tf
.
estimator
.
ModeKeys
.
EVAL
...
...
official/r1/transformer/schedule_test.py
View file @
1e2ceffd
...
...
@@ -14,7 +14,7 @@
# ==============================================================================
"""Test Transformer's schedule manager."""
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
from
official.r1.transformer
import
schedule
...
...
official/r1/transformer/transformer.py
View file @
1e2ceffd
...
...
@@ -22,7 +22,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
from
official.nlp.transformer
import
beam_search_v1
as
beam_search
from
official.nlp.transformer
import
model_utils
...
...
official/r1/transformer/transformer_main.py
View file @
1e2ceffd
...
...
@@ -29,7 +29,7 @@ import tempfile
from
six.moves
import
xrange
# pylint: disable=redefined-builtin
from
absl
import
app
as
absl_app
from
absl
import
flags
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
# pylint: enable=g-bad-import-order
from
official.nlp.transformer
import
model_params
...
...
official/r1/transformer/translate.py
View file @
1e2ceffd
...
...
@@ -23,7 +23,7 @@ import os
# pylint: disable=g-bad-import-order
from
absl
import
app
as
absl_app
from
absl
import
flags
import
tensorflow
as
tf
import
tensorflow
.compat.v1
as
tf
# pylint: enable=g-bad-import-order
from
official.nlp.transformer.utils
import
tokenizer
...
...
official/staging/training/controller.py
View file @
1e2ceffd
...
...
@@ -94,13 +94,15 @@ class Controller(object):
# TODO(rxsang): Support training until exhaustion by passing
# `train_steps=-1`. Currently it cannot be supported with a host training
# loop because break statements are not supported with distributed dataset.
if
train_fn
is
not
None
and
train_steps
is
None
:
raise
ValueError
(
"`train_steps` is required when `train_fn` is provided."
)
if
train_fn
is
not
None
and
steps_per_loop
is
None
:
raise
ValueError
(
"`steps_per_loop` is required when `train_fn is "
"provided."
)
if
not
isinstance
(
steps_per_loop
,
int
)
or
steps_per_loop
<
1
:
raise
ValueError
(
"`steps_per_loop` should be a positive integer"
)
if
train_fn
is
not
None
:
if
train_steps
is
None
:
raise
ValueError
(
"`train_steps` is required when `train_fn` is "
"provided."
)
if
steps_per_loop
is
None
:
raise
ValueError
(
"`steps_per_loop` is required when `train_fn is "
"provided."
)
if
not
isinstance
(
steps_per_loop
,
int
)
or
steps_per_loop
<
1
:
raise
ValueError
(
"`steps_per_loop` should be a positive integer"
)
if
summary_interval
is
not
None
and
summary_interval
<=
0
:
raise
ValueError
(
"`summary_interval` should be larger than 0"
)
...
...
official/staging/training/utils.py
View file @
1e2ceffd
...
...
@@ -53,13 +53,17 @@ def create_loop_fn(step_fn):
"""
try
:
step
=
0
while
(
num_steps
==
-
1
or
step
<
num_steps
):
outputs
=
step_fn
(
iterator
)
if
reduce_fn
is
not
None
:
state
=
reduce_fn
(
state
,
outputs
)
step
+=
1
return
state
# To make sure the OutOfRangeError exception can be handled well with
# async remote eager, we need to wrap the loop body in a `async_scope`.
with
tf
.
experimental
.
async_scope
():
while
(
num_steps
==
-
1
or
step
<
num_steps
):
outputs
=
step_fn
(
iterator
)
if
reduce_fn
is
not
None
:
state
=
reduce_fn
(
state
,
outputs
)
step
+=
1
return
state
except
(
StopIteration
,
tf
.
errors
.
OutOfRangeError
):
tf
.
experimental
.
async_clear_error
()
return
state
return
loop_fn
...
...
official/utils/misc/keras_utils.py
View file @
1e2ceffd
...
...
@@ -117,8 +117,9 @@ class TimeHistory(tf.keras.callbacks.Callback):
self
.
timestamp_log
.
append
(
BatchTimestamp
(
self
.
global_steps
,
now
))
logging
.
info
(
'TimeHistory: %.2f examples/second between steps %d and %d'
,
examples_per_second
,
self
.
last_log_step
,
self
.
global_steps
)
'TimeHistory: %.2f seconds, %.2f examples/second between steps %d '
'and %d'
,
elapsed_time
,
examples_per_second
,
self
.
last_log_step
,
self
.
global_steps
)
if
self
.
summary_writer
:
with
self
.
summary_writer
.
as_default
():
...
...
official/vision/detection/modeling/losses.py
View file @
1e2ceffd
...
...
@@ -465,7 +465,9 @@ class RetinanetBoxLoss(object):
# for instances, the regression targets of 512x512 input with 6 anchors on
# P3-P7 pyramid is about [0.1, 0.1, 0.2, 0.2].
normalizer
=
num_positives
*
4.0
mask
=
tf
.
not_equal
(
box_targets
,
0.0
)
mask
=
tf
.
cast
(
tf
.
not_equal
(
box_targets
,
0.0
),
dtype
=
tf
.
float32
)
box_targets
=
tf
.
expand_dims
(
box_targets
,
axis
=-
1
)
box_outputs
=
tf
.
expand_dims
(
box_outputs
,
axis
=-
1
)
box_loss
=
self
.
_huber_loss
(
box_targets
,
box_outputs
,
sample_weight
=
mask
)
box_loss
/=
normalizer
return
box_loss
...
...
official/vision/image_classification/common.py
View file @
1e2ceffd
...
...
@@ -275,12 +275,6 @@ def define_keras_flags(
help
=
'Whether to build a tf.while_loop inside the training loop on the '
'host. Setting it to True is critical to have peak performance on '
'TPU.'
)
flags
.
DEFINE_boolean
(
name
=
'use_tf_keras_layers'
,
default
=
False
,
help
=
'Whether to use tf.keras.layers instead of tf.python.keras.layers.'
'It only changes imagenet resnet model layers for now. This flag is '
'a temporal flag during transition to tf.keras.layers. Do not use this '
'flag for external usage. this will be removed shortly.'
)
if
model
:
flags
.
DEFINE_string
(
'model'
,
'resnet50_v1.5'
,
...
...
official/vision/image_classification/resnet/__init__.py
0 → 100644
View file @
1e2ceffd
Prev
1
2
3
4
Next
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