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
ec55d7da
Commit
ec55d7da
authored
Mar 28, 2022
by
Luke Wood
Committed by
A. Unique TensorFlower
Mar 28, 2022
Browse files
Internal change
PiperOrigin-RevId: 437812893
parent
74582325
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
15 deletions
+18
-15
official/nlp/modeling/layers/text_layers_test.py
official/nlp/modeling/layers/text_layers_test.py
+7
-6
official/nlp/tools/export_tfhub_lib_test.py
official/nlp/tools/export_tfhub_lib_test.py
+3
-2
official/recommendation/neumf_model.py
official/recommendation/neumf_model.py
+8
-7
No files found.
official/nlp/modeling/layers/text_layers_test.py
View file @
ec55d7da
...
...
@@ -19,6 +19,7 @@ import tempfile
import
numpy
as
np
import
tensorflow
as
tf
from
tensorflow
import
estimator
as
tf_estimator
from
sentencepiece
import
SentencePieceTrainer
from
official.nlp.modeling.layers
import
text_layers
...
...
@@ -120,10 +121,10 @@ class BertTokenizerTest(tf.test.TestCase):
def
model_fn
(
features
,
labels
,
mode
):
del
labels
# Unused.
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
features
[
"input_word_ids"
])
estimator
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
)
estimator
=
tf
_
estimator
.
Estimator
(
model_fn
=
model_fn
)
outputs
=
list
(
estimator
.
predict
(
input_fn
))
self
.
assertAllEqual
(
outputs
,
np
.
array
([[
2
,
6
,
3
,
0
],
[
2
,
4
,
5
,
3
]]))
...
...
@@ -231,10 +232,10 @@ class SentencepieceTokenizerTest(tf.test.TestCase):
def
model_fn
(
features
,
labels
,
mode
):
del
labels
# Unused.
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
features
[
"input_word_ids"
])
estimator
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
)
estimator
=
tf
_
estimator
.
Estimator
(
model_fn
=
model_fn
)
outputs
=
list
(
estimator
.
predict
(
input_fn
))
self
.
assertAllEqual
(
outputs
,
np
.
array
([[
2
,
8
,
3
,
0
],
[
2
,
12
,
3
,
0
]]))
...
...
@@ -537,10 +538,10 @@ class FastWordPieceBertTokenizerTest(tf.test.TestCase):
def
model_fn
(
features
,
labels
,
mode
):
del
labels
# Unused.
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
features
[
"input_word_ids"
])
estimator
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
)
estimator
=
tf
_
estimator
.
Estimator
(
model_fn
=
model_fn
)
outputs
=
list
(
estimator
.
predict
(
input_fn
))
self
.
assertAllEqual
(
outputs
,
np
.
array
([[
2
,
6
,
3
,
0
],
[
2
,
4
,
5
,
3
]]))
...
...
official/nlp/tools/export_tfhub_lib_test.py
View file @
ec55d7da
...
...
@@ -20,6 +20,7 @@ import tempfile
from
absl.testing
import
parameterized
import
numpy
as
np
import
tensorflow
as
tf
from
tensorflow
import
estimator
as
tf_estimator
import
tensorflow_hub
as
hub
import
tensorflow_text
as
text
...
...
@@ -1024,10 +1025,10 @@ class ExportPreprocessingTest(tf.test.TestCase, parameterized.TestCase):
def
model_fn
(
features
,
labels
,
mode
):
del
labels
# Unused.
return
tf
.
estimator
.
EstimatorSpec
(
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
features
[
"input_word_ids"
])
estimator
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
)
estimator
=
tf
_
estimator
.
Estimator
(
model_fn
=
model_fn
)
outputs
=
list
(
estimator
.
predict
(
input_fn
))
self
.
assertAllEqual
(
outputs
,
np
.
array
([[
2
,
6
,
3
,
0
],
[
2
,
4
,
5
,
3
]]))
...
...
official/recommendation/neumf_model.py
View file @
ec55d7da
...
...
@@ -37,6 +37,7 @@ import sys
from
six.moves
import
xrange
# pylint: disable=redefined-builtin
import
tensorflow
as
tf
from
tensorflow
import
estimator
as
tf_estimator
from
typing
import
Any
,
Dict
,
Text
from
official.recommendation
import
constants
as
rconst
...
...
@@ -85,7 +86,7 @@ def neumf_model_fn(features, labels, mode, params):
# Softmax with the first column of zeros is equivalent to sigmoid.
softmax_logits
=
ncf_common
.
convert_to_softmax_logits
(
logits
)
if
mode
==
tf
.
estimator
.
ModeKeys
.
EVAL
:
if
mode
==
tf
_
estimator
.
ModeKeys
.
EVAL
:
duplicate_mask
=
tf
.
cast
(
features
[
rconst
.
DUPLICATE_MASK
],
tf
.
float32
)
return
_get_estimator_spec_with_metrics
(
logits
,
...
...
@@ -95,7 +96,7 @@ def neumf_model_fn(features, labels, mode, params):
params
[
"match_mlperf"
],
use_tpu_spec
=
params
[
"use_tpu"
])
elif
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
:
elif
mode
==
tf
_
estimator
.
ModeKeys
.
TRAIN
:
labels
=
tf
.
cast
(
labels
,
tf
.
int32
)
valid_pt_mask
=
features
[
rconst
.
VALID_POINT_MASK
]
...
...
@@ -124,7 +125,7 @@ def neumf_model_fn(features, labels, mode, params):
update_ops
=
tf
.
compat
.
v1
.
get_collection
(
tf
.
compat
.
v1
.
GraphKeys
.
UPDATE_OPS
)
train_op
=
tf
.
group
(
minimize_op
,
update_ops
)
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
train_op
=
train_op
)
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
train_op
=
train_op
)
else
:
raise
NotImplementedError
...
...
@@ -260,13 +261,13 @@ def _get_estimator_spec_with_metrics(logits: tf.Tensor,
match_mlperf
)
if
use_tpu_spec
:
return
tf
.
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
=
tf
.
estimator
.
ModeKeys
.
EVAL
,
return
tf
_
estimator
.
tpu
.
TPUEstimatorSpec
(
mode
=
tf
_
estimator
.
ModeKeys
.
EVAL
,
loss
=
cross_entropy
,
eval_metrics
=
(
metric_fn
,
[
in_top_k
,
ndcg
,
metric_weights
]))
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
tf
.
estimator
.
ModeKeys
.
EVAL
,
return
tf
_
estimator
.
EstimatorSpec
(
mode
=
tf
_
estimator
.
ModeKeys
.
EVAL
,
loss
=
cross_entropy
,
eval_metric_ops
=
metric_fn
(
in_top_k
,
ndcg
,
metric_weights
))
...
...
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