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
8f28cb91
Commit
8f28cb91
authored
Aug 27, 2020
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 328773294
parent
1ebff962
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
official/nlp/transformer/transformer_test.py
official/nlp/transformer/transformer_test.py
+34
-0
No files found.
official/nlp/transformer/transformer_test.py
View file @
8f28cb91
...
@@ -27,6 +27,7 @@ from official.nlp.transformer import transformer
...
@@ -27,6 +27,7 @@ from official.nlp.transformer import transformer
class
TransformerV2Test
(
tf
.
test
.
TestCase
):
class
TransformerV2Test
(
tf
.
test
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
super
().
setUp
()
self
.
params
=
params
=
model_params
.
TINY_PARAMS
self
.
params
=
params
=
model_params
.
TINY_PARAMS
params
[
"batch_size"
]
=
params
[
"default_batch_size"
]
=
16
params
[
"batch_size"
]
=
params
[
"default_batch_size"
]
=
16
params
[
"use_synthetic_data"
]
=
True
params
[
"use_synthetic_data"
]
=
True
...
@@ -63,6 +64,39 @@ class TransformerV2Test(tf.test.TestCase):
...
@@ -63,6 +64,39 @@ class TransformerV2Test(tf.test.TestCase):
self
.
assertEqual
(
outputs
[
1
].
shape
.
as_list
(),
[
None
])
self
.
assertEqual
(
outputs
[
1
].
shape
.
as_list
(),
[
None
])
self
.
assertEqual
(
outputs
[
1
].
dtype
,
tf
.
float32
)
self
.
assertEqual
(
outputs
[
1
].
dtype
,
tf
.
float32
)
def
test_export
(
self
):
model
=
transformer
.
Transformer
(
self
.
params
,
name
=
"transformer_v2"
)
export_dir
=
self
.
get_temp_dir
()
batch_size
=
5
max_length
=
6
class
SaveModule
(
tf
.
Module
):
def
__init__
(
self
,
model
):
super
(
SaveModule
,
self
).
__init__
()
self
.
model
=
model
@
tf
.
function
def
serve
(
self
,
x
):
return
self
.
model
.
call
([
x
],
training
=
False
)
save_module
=
SaveModule
(
model
)
tensor_shape
=
(
None
,
None
)
sample_input
=
tf
.
zeros
((
batch_size
,
max_length
),
dtype
=
tf
.
int64
)
_
=
save_module
.
serve
(
sample_input
)
signatures
=
dict
(
serving_default
=
save_module
.
serve
.
get_concrete_function
(
tf
.
TensorSpec
(
shape
=
tensor_shape
,
dtype
=
tf
.
int64
,
name
=
"x"
)))
tf
.
saved_model
.
save
(
save_module
,
export_dir
,
signatures
=
signatures
)
imported
=
tf
.
saved_model
.
load
(
export_dir
)
serving_fn
=
imported
.
signatures
[
"serving_default"
]
all_outputs
=
serving_fn
(
sample_input
)
output
=
all_outputs
[
"outputs"
]
output_shapes
=
output
.
shape
.
as_list
()
self
.
assertEqual
(
output_shapes
[
0
],
batch_size
)
self
.
assertEqual
(
output_shapes
[
1
],
max_length
+
model
.
params
[
"extra_decode_length"
])
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
tf
.
test
.
main
()
tf
.
test
.
main
()
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