Refactor generate_examples_lib.py to split each op to separate files.
PiperOrigin-RevId: 275117423 Change-Id: I4ee19a6c388187fa231373eeaa4b14339e328680
This commit is contained in:
parent
1c88fff548
commit
e3be9bbcad
tensorflow/lite/testing
BUILDgenerate_examples_lib.py
op_tests
abs.pyadd_n.pyarg_min_max.pybatch_to_space_nd.pybinary_op.pycast.pyceil.pyconcat.pyconstant.pycontrol_dep.pyconv.pyconv2d_transpose.pyconv_to_depthwiseconv_with_shared_weights.pyconv_with_shared_weights.pycos.pydepth_to_space.pydepthwiseconv.pyelementwise.pyelu.pyembedding_lookup.pyequal.pyexp.pyexpand_dims.pyeye.pyfill.pyfloor.pyfully_connected.pyfused_batch_norm.pygather.pygather_nd.pygather_with_constant.pyglobal_batch_norm.pygreater.pygreater_equal.pyhardswish.pyidentity.pyl2norm.pyl2norm_shared_epsilon.pyleaky_relu.pyless.pyless_equal.pylocal_response_norm.pylog_softmax.pylogic.pylstm.pymatrix_diag.pymatrix_set_diag.pymaximum.pyminimum.pymirror_pad.pyneg.pynot_equal.pyone_hot.pypack.pypad.pypadv2.pyplaceholder_with_default.pypool.pyprelu.pyrange.pyrank.pyreduce.pyrelu.pyrelu1.pyrelu6.pyreshape.pyresize_bilinear.pyresize_nearest_neighbor.pyresolve_constant_strided_slice.pyreverse_sequence.pyreverse_v2.pyrfft2d.pyround.pyshape.pysigmoid.pyslice.pysoftmax.pyspace_to_batch_nd.pyspace_to_depth.pysparse_to_dense.pysplit.pysplitv.pysqueeze.pysqueeze_transpose.pystrided_slice.pystrided_slice_np_style.pytile.pytopk.pytranspose.pytranspose_conv.pyunfused_gru.pyunidirectional_sequence_lstm.pyunidirectional_sequence_rnn.pyunique.pyunpack.pyunroll_batch_matmul.pywhere.pyzeros_like.py
@ -90,7 +90,18 @@ py_library(
|
||||
"//tensorflow/lite/toco",
|
||||
],
|
||||
deps = [
|
||||
":generate_examples_lib",
|
||||
":zip_test_utils",
|
||||
"//tensorflow:tensorflow_py",
|
||||
"//third_party/py/numpy",
|
||||
],
|
||||
)
|
||||
|
||||
py_library(
|
||||
name = "op_tests",
|
||||
srcs = glob(["op_tests/*.py"]),
|
||||
srcs_version = "PY2AND3",
|
||||
deps = [
|
||||
":zip_test_utils",
|
||||
"//tensorflow:tensorflow_py",
|
||||
"//third_party/py/numpy",
|
||||
],
|
||||
@ -100,13 +111,22 @@ py_library(
|
||||
name = "generate_examples_lib",
|
||||
srcs = ["generate_examples_lib.py"],
|
||||
srcs_version = "PY2AND3",
|
||||
deps = [
|
||||
":op_tests",
|
||||
":zip_test_utils",
|
||||
"//tensorflow:tensorflow_py",
|
||||
],
|
||||
)
|
||||
|
||||
py_library(
|
||||
name = "zip_test_utils",
|
||||
srcs = ["zip_test_utils.py"],
|
||||
srcs_version = "PY2AND3",
|
||||
deps = [
|
||||
":generate_examples_report",
|
||||
":string_util_wrapper",
|
||||
"//tensorflow:tensorflow_py",
|
||||
"//tensorflow/python:framework",
|
||||
"//third_party/py/numpy",
|
||||
"@six_archive//:six",
|
||||
],
|
||||
)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
49
tensorflow/lite/testing/op_tests/abs.py
Normal file
49
tensorflow/lite/testing/op_tests/abs.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for abs."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_abs_tests(options):
|
||||
"""Make a set of tests to do abs."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3],
|
||||
[3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.abs(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-10, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
69
tensorflow/lite/testing/op_tests/add_n.py
Normal file
69
tensorflow/lite/testing/op_tests/add_n.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for add_n."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_add_n_tests(options):
|
||||
"""Make a set of tests for AddN op."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[2, 5, 3, 1]],
|
||||
"num_inputs": [2, 3, 4, 5],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[5]],
|
||||
"num_inputs": [2, 3, 4, 5],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[]],
|
||||
"num_inputs": [2, 3, 4, 5],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Builds the graph given the current parameters."""
|
||||
input_tensors = []
|
||||
for i in range(parameters["num_inputs"]):
|
||||
input_tensors.append(
|
||||
tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input_{}".format(i),
|
||||
shape=parameters["input_shape"]))
|
||||
out = tf.add_n(input_tensors)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Builds operand inputs for op."""
|
||||
input_data = []
|
||||
for _ in range(parameters["num_inputs"]):
|
||||
input_data.append(
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"]))
|
||||
return input_data, sess.run(
|
||||
outputs, feed_dict={i: d for i, d in zip(inputs, input_data)})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
64
tensorflow/lite/testing/op_tests/arg_min_max.py
Normal file
64
tensorflow/lite/testing/op_tests/arg_min_max.py
Normal file
@ -0,0 +1,64 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for arg_min_max."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import random
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_arg_min_max_tests(options):
|
||||
"""Make a set of tests to do arg_max."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[], [1, 1, 1, 3], [2, 3, 4, 5], [2, 3, 3], [5, 5], [10]],
|
||||
"output_type": [tf.int32, tf.int64],
|
||||
"is_arg_max": [True],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the topk op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
axis = random.randint(0, max(len(parameters["input_shape"]) - 1, 0))
|
||||
if parameters["is_arg_max"]:
|
||||
out = tf.arg_max(input_value, axis, output_type=parameters["output_type"])
|
||||
else:
|
||||
out = tf.arg_min(input_value, axis, output_type=parameters["output_type"])
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=4)
|
97
tensorflow/lite/testing/op_tests/batch_to_space_nd.py
Normal file
97
tensorflow/lite/testing/op_tests/batch_to_space_nd.py
Normal file
@ -0,0 +1,97 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for batch_to_space_nd."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_batch_to_space_nd_tests(options):
|
||||
"""Make a set of tests to do batch_to_space_nd."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"dtype": [tf.float32, tf.int64, tf.int32],
|
||||
"input_shape": [[12, 3, 3, 1]],
|
||||
"block_shape": [[1, 4], [2, 2], [3, 4]],
|
||||
"crops": [[[0, 0], [0, 0]], [[1, 1], [1, 1]]],
|
||||
"constant_block_shape": [True, False],
|
||||
"constant_crops": [True, False],
|
||||
},
|
||||
# Single batch (no-op)
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 3, 3, 1]],
|
||||
"block_shape": [[1, 1]],
|
||||
"crops": [[[0, 0], [0, 0]], [[1, 1], [1, 1]]],
|
||||
"constant_block_shape": [True],
|
||||
"constant_crops": [True],
|
||||
},
|
||||
# Non-4D use case: 1 batch dimension, 3 spatial dimensions, 2 others.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[8, 2, 2, 2, 1, 1]],
|
||||
"block_shape": [[2, 2, 2]],
|
||||
"crops": [[[0, 0], [0, 0], [0, 0]]],
|
||||
"constant_block_shape": [True, False],
|
||||
"constant_crops": [True, False],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a batch_to_space graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
input_tensors = [input_tensor]
|
||||
|
||||
# Get block_shape either as a const or as a placeholder (tensor).
|
||||
if parameters["constant_block_shape"]:
|
||||
block_shape = parameters["block_shape"]
|
||||
else:
|
||||
shape = [len(parameters["block_shape"])]
|
||||
block_shape = tf.placeholder(dtype=tf.int32, name="shape", shape=shape)
|
||||
input_tensors.append(block_shape)
|
||||
|
||||
# Get crops either as a const or as a placeholder (tensor).
|
||||
if parameters["constant_crops"]:
|
||||
crops = parameters["crops"]
|
||||
else:
|
||||
shape = [len(parameters["crops"]), 2]
|
||||
crops = tf.placeholder(dtype=tf.int32, name="crops", shape=shape)
|
||||
input_tensors.append(crops)
|
||||
|
||||
out = tf.batch_to_space_nd(input_tensor, block_shape, crops)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_block_shape"]:
|
||||
values.append(np.array(parameters["block_shape"]))
|
||||
if not parameters["constant_crops"]:
|
||||
values.append(np.array(parameters["crops"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
146
tensorflow/lite/testing/op_tests/binary_op.py
Normal file
146
tensorflow/lite/testing/op_tests/binary_op.py
Normal file
@ -0,0 +1,146 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for binary_op."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def make_binary_op_tests(options, binary_operator, expected_tf_failures=0):
|
||||
"""Make a set of tests to do binary ops with and without broadcast."""
|
||||
|
||||
test_parameters = [
|
||||
# Avoid creating all combinations to keep the test size small.
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape_1": [[1, 3, 4, 3]],
|
||||
"input_shape_2": [[1, 3, 4, 3]],
|
||||
"activation": [True],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape_1": [[5]],
|
||||
"input_shape_2": [[5]],
|
||||
"activation": [False, True],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_1": [[1, 3, 4, 3]],
|
||||
"input_shape_2": [[3]],
|
||||
"activation": [True, False],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape_1": [[3]],
|
||||
"input_shape_2": [[1, 3, 4, 3]],
|
||||
"activation": [True, False],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape_1": [[]],
|
||||
"input_shape_2": [[]],
|
||||
"activation": [False],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape_1": [[0]],
|
||||
"input_shape_2": [[1]],
|
||||
"activation": [False],
|
||||
}
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Builds the graph given the current parameters."""
|
||||
input1 = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_1"])
|
||||
input2 = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_2"])
|
||||
out = binary_operator(input1, input2)
|
||||
if parameters["activation"]:
|
||||
out = tf.nn.relu(out)
|
||||
return [input1, input2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Builds operand inputs for op."""
|
||||
input1 = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape_1"])
|
||||
input2 = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape_2"])
|
||||
return [input1, input2], sess.run(
|
||||
outputs, feed_dict={
|
||||
inputs[0]: input1,
|
||||
inputs[1]: input2
|
||||
})
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=expected_tf_failures)
|
||||
|
||||
|
||||
def make_binary_op_tests_func(binary_operator):
|
||||
"""Return a function that does a test on a binary operator."""
|
||||
return lambda options: make_binary_op_tests(options, binary_operator)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_add_tests(options):
|
||||
make_binary_op_tests(options, tf.add)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_div_tests(options):
|
||||
make_binary_op_tests(options, tf.div)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sub_tests(options):
|
||||
make_binary_op_tests(options, tf.subtract)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_mul_tests(options):
|
||||
make_binary_op_tests(options, tf.multiply)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_pow_tests(options):
|
||||
make_binary_op_tests(options, tf.pow, expected_tf_failures=7)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_floor_div_tests(options):
|
||||
make_binary_op_tests(options, tf.floor_div)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_floor_mod_tests(options):
|
||||
make_binary_op_tests(options, tf.floormod)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_squared_difference_tests(options):
|
||||
make_binary_op_tests(options, tf.squared_difference)
|
50
tensorflow/lite/testing/op_tests/cast.py
Normal file
50
tensorflow/lite/testing/op_tests/cast.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for cast."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_cast_tests(options):
|
||||
"""Generate examples for cast."""
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.int32],
|
||||
"output_dtype": [tf.float32],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the cast testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.cast(input_value, parameters["output_dtype"])
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
49
tensorflow/lite/testing/op_tests/ceil.py
Normal file
49
tensorflow/lite/testing/op_tests/ceil.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for ceil."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_ceil_tests(options):
|
||||
"""Make a set of tests to do ceil."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the ceil op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.ceil(input_value)
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(outputs, feed_dict={inputs[0]: input_value})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
72
tensorflow/lite/testing/op_tests/concat.py
Normal file
72
tensorflow/lite/testing/op_tests/concat.py
Normal file
@ -0,0 +1,72 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for concat."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_concat_tests(options):
|
||||
"""Make a set of tests to do concatenation."""
|
||||
|
||||
test_parameters = [{
|
||||
"base_shape": [[1, 3, 4, 3], [3, 4]],
|
||||
"num_tensors": [1, 2, 3, 4, 5, 6],
|
||||
"axis": [0, 1, 2, 3, -3, -2, -1],
|
||||
"type": [tf.float32, tf.uint8, tf.int32, tf.int64],
|
||||
}]
|
||||
|
||||
def get_shape(parameters, delta):
|
||||
"""Return a tweaked version of 'base_shape'."""
|
||||
axis = parameters["axis"]
|
||||
shape = parameters["base_shape"][:]
|
||||
if axis < 0:
|
||||
axis += len(shape)
|
||||
if axis < len(shape):
|
||||
shape[axis] += delta
|
||||
return shape
|
||||
|
||||
def build_graph(parameters):
|
||||
all_tensors = []
|
||||
for n in range(0, parameters["num_tensors"]):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["type"],
|
||||
name=("input%d" % n),
|
||||
shape=get_shape(parameters, n))
|
||||
all_tensors.append(input_tensor)
|
||||
out = tf.concat(all_tensors, parameters["axis"])
|
||||
return all_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
all_values = []
|
||||
for n in range(0, parameters["num_tensors"]):
|
||||
input_values = create_tensor_data(parameters["type"],
|
||||
get_shape(parameters, n))
|
||||
all_values.append(input_values)
|
||||
return all_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, all_values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=60)
|
69
tensorflow/lite/testing/op_tests/constant.py
Normal file
69
tensorflow/lite/testing/op_tests/constant.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for constant ops."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.lite.testing.zip_test_utils import TF_TYPE_INFO
|
||||
|
||||
|
||||
# This function tests various TensorFLow functions that generates Const op,
|
||||
# including `tf.ones`, `tf.zeros` and random functions.
|
||||
@register_make_test_function()
|
||||
def make_constant_tests(options):
|
||||
"""Make a set of tests to do constant ops."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[], [1], [2], [1, 1, 1, 1], [2, 2, 2, 2]],
|
||||
"constant_is_also_output": [True, False],
|
||||
# This is a regression test for a bug where Toco rejects models with
|
||||
# unread inputs.
|
||||
"has_unread_input": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a constant graph given `parameters`."""
|
||||
dummy_input = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape"])
|
||||
constant = tf.constant(
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"]))
|
||||
outputs = [tf.maximum(dummy_input, constant)]
|
||||
if parameters["constant_is_also_output"]:
|
||||
outputs.append(constant)
|
||||
inputs = [dummy_input]
|
||||
if parameters["has_unread_input"]:
|
||||
unread_input = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="unread_input",
|
||||
shape=parameters["input_shape"])
|
||||
inputs.append(unread_input)
|
||||
|
||||
return inputs, outputs
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
dummy_input = np.zeros(
|
||||
parameters["input_shape"], dtype=TF_TYPE_INFO[parameters["dtype"]][0])
|
||||
return [dummy_input], sess.run(outputs, feed_dict={inputs[0]: dummy_input})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
60
tensorflow/lite/testing/op_tests/control_dep.py
Normal file
60
tensorflow/lite/testing/op_tests/control_dep.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for control_dep."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
TEST_INPUT_DEPTH = 3
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_control_dep_tests(options):
|
||||
"""Make a set of tests that use control dependencies."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1, 1, 1, 1], [1, 15, 14, 1], [3, 15, 14, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
filter_value = tf.zeros((3, 3, TEST_INPUT_DEPTH, 8), tf.float32)
|
||||
assert_op = tf.assert_greater_equal(input_tensor, input_tensor - 1)
|
||||
with tf.control_dependencies([assert_op]):
|
||||
out = tf.nn.conv2d(
|
||||
input_tensor, filter_value, strides=(1, 1, 1, 1), padding="SAME")
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(tf.float32, parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
extra_toco_options = ExtraTocoOptions()
|
||||
extra_toco_options.drop_control_dependency = True
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
extra_toco_options,
|
||||
expected_tf_failures=3)
|
109
tensorflow/lite/testing/op_tests/conv.py
Normal file
109
tensorflow/lite/testing/op_tests/conv.py
Normal file
@ -0,0 +1,109 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for conv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_conv_tests(options):
|
||||
"""Make a set of tests to do convolution."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[1, 3, 4, 3], [4, 6, 6, 1]],
|
||||
"filter_shape": [[1, 1], [2, 3], [3, 3]],
|
||||
"strides": [[1, 1, 1, 1], [1, 2, 3, 1]],
|
||||
"dilations": [[1, 1, 1, 1], [1, 3, 2, 1], [1, 2, 2, 1]],
|
||||
"padding": ["SAME", "VALID"],
|
||||
"data_format": ["NHWC"], # TODO(aselle): NCHW would be good
|
||||
"constant_filter": [True, False],
|
||||
"channel_multiplier": [1, 2],
|
||||
"fully_quantize": [False],
|
||||
},
|
||||
# TODO(b/134702301): The fully_quantize param is just ignored by the MLIR
|
||||
# testing path now, resulting in duplicate tests. Either ignore these
|
||||
# tests or handle it properly in the mlir_convert() function.
|
||||
{
|
||||
"input_shape": [[1, 3, 4, 3], [4, 6, 6, 1]],
|
||||
"filter_shape": [[1, 1], [2, 3], [3, 3]],
|
||||
"strides": [[1, 1, 1, 1], [1, 2, 3, 1]],
|
||||
"dilations": [[1, 1, 1, 1], [1, 3, 2, 1], [1, 2, 2, 1]],
|
||||
"padding": ["SAME", "VALID"],
|
||||
"data_format": ["NHWC"], # TODO(aselle): NCHW would be good
|
||||
"constant_filter": [True],
|
||||
"channel_multiplier": [1, 2],
|
||||
"fully_quantize": [True],
|
||||
}
|
||||
]
|
||||
|
||||
def get_tensor_shapes(parameters):
|
||||
input_shape = parameters["input_shape"]
|
||||
filter_size = parameters["filter_shape"]
|
||||
filter_shape = filter_size + [
|
||||
input_shape[3], parameters["channel_multiplier"]
|
||||
]
|
||||
return [input_shape, filter_shape]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a conv graph given `parameters`."""
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=input_shape)
|
||||
|
||||
# Get filter input either as a placeholder or constants. Also get a list of
|
||||
# the input tensors that are represented as placeholders.
|
||||
if parameters["constant_filter"]:
|
||||
filter_input = create_tensor_data(
|
||||
np.float32, filter_shape, min_value=-10, max_value=10)
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
filter_input = tf.placeholder(
|
||||
dtype=tf.float32, name="filter", shape=filter_shape)
|
||||
input_tensors = [input_tensor, filter_input]
|
||||
|
||||
out = tf.nn.conv2d(
|
||||
input_tensor,
|
||||
filter_input,
|
||||
strides=parameters["strides"],
|
||||
dilations=parameters["dilations"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
# Build list of input values either containing 1 tensor (input) or 2 tensors
|
||||
# (input, filter) based on whether filter is constant or variable input.
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
values = [
|
||||
create_tensor_data(np.float32, input_shape, min_value=-1, max_value=1)
|
||||
]
|
||||
if not parameters["constant_filter"]:
|
||||
values.append(create_tensor_data(np.float32, filter_shape))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=60)
|
83
tensorflow/lite/testing/op_tests/conv2d_transpose.py
Normal file
83
tensorflow/lite/testing/op_tests/conv2d_transpose.py
Normal file
@ -0,0 +1,83 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for conv2d_transpose."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_conv2d_transpose_tests(options):
|
||||
"""Make a set of tests to do transpose_conv."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 50, 54, 3]],
|
||||
"filter_shape": [[1, 1, 8, 3], [1, 2, 8, 3], [1, 3, 8, 3], [1, 4, 8, 3]],
|
||||
"output_shape": [[1, 100, 108, 8]],
|
||||
"dynamic_output_shape": [True, False],
|
||||
}, {
|
||||
"input_shape": [[1, 16, 1, 512]],
|
||||
"filter_shape": [[4, 1, 512, 512]],
|
||||
"output_shape": [[1, 32, 1, 512]],
|
||||
"dynamic_output_shape": [True, False],
|
||||
}, {
|
||||
"input_shape": [[1, 128, 128, 1]],
|
||||
"filter_shape": [[4, 4, 1, 1]],
|
||||
"output_shape": [[1, 256, 256, 1]],
|
||||
"dynamic_output_shape": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a transpose_conv graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
|
||||
filter_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="filter", shape=parameters["filter_shape"])
|
||||
|
||||
input_tensors = [input_tensor, filter_tensor]
|
||||
|
||||
if parameters["dynamic_output_shape"]:
|
||||
output_shape = tf.placeholder(dtype=tf.int32, shape=[4])
|
||||
input_tensors.append(output_shape)
|
||||
else:
|
||||
output_shape = parameters["output_shape"]
|
||||
|
||||
out = tf.nn.conv2d_transpose(
|
||||
input_tensor,
|
||||
filter_tensor,
|
||||
output_shape=output_shape,
|
||||
padding="SAME",
|
||||
strides=(1, 2, 2, 1))
|
||||
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(np.float32, parameters["input_shape"]),
|
||||
create_tensor_data(np.float32, parameters["filter_shape"])
|
||||
]
|
||||
if parameters["dynamic_output_shape"]:
|
||||
values.append(np.array(parameters["output_shape"]))
|
||||
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
@ -0,0 +1,87 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for conv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_conv_to_depthwiseconv_with_shared_weights_tests(options):
|
||||
"""Make a test where 2 Conv ops shared the same constant weight tensor."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 10, 10, 1]],
|
||||
"filter_shape": [[3, 3]],
|
||||
"strides": [[1, 1, 1, 1]],
|
||||
"dilations": [[1, 1, 1, 1]],
|
||||
"padding": ["SAME"],
|
||||
"data_format": ["NHWC"],
|
||||
"channel_multiplier": [3],
|
||||
}]
|
||||
|
||||
def get_tensor_shapes(parameters):
|
||||
input_shape = parameters["input_shape"]
|
||||
filter_size = parameters["filter_shape"]
|
||||
filter_shape = filter_size + [
|
||||
input_shape[3], parameters["channel_multiplier"]
|
||||
]
|
||||
return [input_shape, filter_shape]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a conv graph given `parameters`."""
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=input_shape)
|
||||
|
||||
# Construct a constant weights tensor which will be used by both Conv2D.
|
||||
filter_tensor = tf.constant(
|
||||
create_tensor_data(np.float32, filter_shape), dtype=tf.float32)
|
||||
input_tensors = [input_tensor]
|
||||
|
||||
# Construct 2 Conv2D operations which use exactly the same input and
|
||||
# weights.
|
||||
result1 = tf.nn.conv2d(
|
||||
input_tensor,
|
||||
filter_tensor,
|
||||
strides=parameters["strides"],
|
||||
dilations=parameters["dilations"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
result2 = tf.nn.conv2d(
|
||||
input_tensor,
|
||||
filter_tensor,
|
||||
strides=parameters["strides"],
|
||||
dilations=parameters["dilations"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
# Add the 2 results up.
|
||||
out = result1 + result2
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
# Build list of input values either containing 1 tensor (input) or 2 tensors
|
||||
# (input, filter) based on whether filter is constant or variable input.
|
||||
input_shape, unused_filter_shape = get_tensor_shapes(parameters)
|
||||
values = [create_tensor_data(np.float32, input_shape)]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
95
tensorflow/lite/testing/op_tests/conv_with_shared_weights.py
Normal file
95
tensorflow/lite/testing/op_tests/conv_with_shared_weights.py
Normal file
@ -0,0 +1,95 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for conv_with_shared_weights."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_conv_with_shared_weights_tests(options):
|
||||
"""Make a test where 2 Conv ops shared the same constant weight tensor."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 10, 10, 3]],
|
||||
"filter_shape": [[3, 3]],
|
||||
"strides": [[1, 1, 1, 1]],
|
||||
"dilations": [[1, 1, 1, 1]],
|
||||
"padding": ["SAME"],
|
||||
"data_format": ["NHWC"],
|
||||
"channel_multiplier": [1],
|
||||
}]
|
||||
|
||||
def get_tensor_shapes(parameters):
|
||||
input_shape = parameters["input_shape"]
|
||||
filter_size = parameters["filter_shape"]
|
||||
filter_shape = filter_size + [
|
||||
input_shape[3], parameters["channel_multiplier"]
|
||||
]
|
||||
return [input_shape, filter_shape]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a conv graph given `parameters`."""
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=input_shape)
|
||||
input_tensors = [input_tensor]
|
||||
|
||||
# Construct a constant weights tensor which will be used by both Conv2D.
|
||||
filter_tensor = tf.constant(
|
||||
create_tensor_data(np.float32, filter_shape), dtype=tf.float32)
|
||||
|
||||
# Ensure that FuseBinaryIntoFollowingAffine works with an input which
|
||||
# is shared by multiple affine ops.
|
||||
conv_input = input_tensor + 0.1
|
||||
|
||||
# Construct 2 Conv2D operations which use exactly the same input and
|
||||
# weights.
|
||||
result1 = tf.nn.conv2d(
|
||||
conv_input,
|
||||
filter_tensor,
|
||||
strides=parameters["strides"],
|
||||
dilations=parameters["dilations"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
result2 = tf.nn.conv2d(
|
||||
conv_input,
|
||||
filter_tensor,
|
||||
strides=parameters["strides"],
|
||||
dilations=parameters["dilations"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
# Add MUL ops after Conv2D ops. These MUL ops should be fused into the
|
||||
# weights of Conv2D.
|
||||
result1 = result1 * 2
|
||||
result2 = result2 * 3
|
||||
# Add the 2 results up.
|
||||
out = result1 + result2
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
# Build list of input values either containing 1 tensor (input) or 2 tensors
|
||||
# (input, filter) based on whether filter is constant or variable input.
|
||||
input_shape, unused_filter_shape = get_tensor_shapes(parameters)
|
||||
values = [create_tensor_data(np.float32, input_shape)]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
56
tensorflow/lite/testing/op_tests/cos.py
Normal file
56
tensorflow/lite/testing/op_tests/cos.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for cos."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_cos_tests(options):
|
||||
"""Make a set of tests to do cos."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the cos op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
out = tf.cos(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(
|
||||
parameters["input_dtype"],
|
||||
parameters["input_shape"],
|
||||
min_value=-np.pi,
|
||||
max_value=np.pi)
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
50
tensorflow/lite/testing/op_tests/depth_to_space.py
Normal file
50
tensorflow/lite/testing/op_tests/depth_to_space.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for depth_to_space."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_depth_to_space_tests(options):
|
||||
"""Make a set of tests to do depth_to_space."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32, tf.uint8, tf.int64],
|
||||
"input_shape": [[2, 3, 4, 16]],
|
||||
"block_size": [2, 4],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.depth_to_space(input_tensor, block_size=parameters["block_size"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
104
tensorflow/lite/testing/op_tests/depthwiseconv.py
Normal file
104
tensorflow/lite/testing/op_tests/depthwiseconv.py
Normal file
@ -0,0 +1,104 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for depthwiseconv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_depthwiseconv_tests(options):
|
||||
"""Make a set of tests to do convolution."""
|
||||
|
||||
# Tensorflow only supports equal strides
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[1, 3, 4, 3], [1, 10, 10, 3]],
|
||||
"filter_size": [[1, 1], [1, 2], [3, 3]],
|
||||
"strides": [[1, 1, 1, 1], [1, 3, 3, 1]],
|
||||
"dilations": [[1, 1, 1, 1], [1, 3, 2, 1], [1, 2, 2, 1]],
|
||||
"channel_multiplier": [1, 2],
|
||||
"rate": [[1, 1]],
|
||||
"padding": ["SAME", "VALID"],
|
||||
"data_format": ["NHWC"],
|
||||
"constant_filter": [True, False],
|
||||
},
|
||||
{
|
||||
"input_shape": [[1, 3, 4, 3]],
|
||||
"filter_size": [[1, 1]],
|
||||
"strides": [[1, 1, 2, 1]], # TF needs [1, x, x, 1]
|
||||
"dilations": [[1, 1, 1, 1], [1, 2, 2, 1]],
|
||||
"channel_multiplier": [2],
|
||||
"rate": [[2, 2]], # Only [1, 1] is supported
|
||||
"padding": ["SAME"],
|
||||
"data_format": ["NHWC"],
|
||||
"constant_filter": [True, False],
|
||||
}
|
||||
]
|
||||
|
||||
def get_tensor_shapes(parameters):
|
||||
input_shape = parameters["input_shape"]
|
||||
filter_size = parameters["filter_size"]
|
||||
filter_shape = filter_size + [
|
||||
input_shape[3], parameters["channel_multiplier"]
|
||||
]
|
||||
return [input_shape, filter_shape]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a depthwise conv graph given `parameters`."""
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=input_shape)
|
||||
|
||||
# Get filter input either as a placeholder or constants. Also get a list of
|
||||
# the input tensors that are represented as placeholders.
|
||||
if parameters["constant_filter"]:
|
||||
filter_input = create_tensor_data(np.float32, filter_shape)
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
filter_input = tf.placeholder(
|
||||
dtype=tf.float32, name="filter", shape=filter_shape)
|
||||
input_tensors = [input_tensor, filter_input]
|
||||
|
||||
out = tf.nn.depthwise_conv2d(
|
||||
input_tensor,
|
||||
filter_input,
|
||||
strides=parameters["strides"],
|
||||
rate=parameters["rate"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
# Build list of input values either containing 1 tensor (input) or 2 tensors
|
||||
# (input, filter) based on whether filter is constant or variable input.
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
values = [create_tensor_data(np.float32, input_shape)]
|
||||
if not parameters["constant_filter"]:
|
||||
values.append(create_tensor_data(np.float32, filter_shape))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=4)
|
83
tensorflow/lite/testing/op_tests/elementwise.py
Normal file
83
tensorflow/lite/testing/op_tests/elementwise.py
Normal file
@ -0,0 +1,83 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for elementwise ops."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def _make_elementwise_tests(op):
|
||||
"""Make a set of tests to do element-wise operations."""
|
||||
|
||||
def f(options):
|
||||
"""Actual function that generates examples."""
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the unary op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape"])
|
||||
out = op(input_value)
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict={inputs[0]: input_value})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sin_tests(options):
|
||||
"""Make a set of tests to do sin."""
|
||||
return _make_elementwise_tests(tf.sin)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_log_tests(options):
|
||||
"""Make a set of tests to do log."""
|
||||
return _make_elementwise_tests(tf.log)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sqrt_tests(options):
|
||||
"""Make a set of tests to do sqrt."""
|
||||
return _make_elementwise_tests(tf.sqrt)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_rsqrt_tests(options):
|
||||
"""Make a set of tests to do 1/sqrt."""
|
||||
return _make_elementwise_tests(tf.rsqrt)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_square_tests(options):
|
||||
"""Make a set of tests to do square."""
|
||||
return _make_elementwise_tests(tf.square)(options)
|
53
tensorflow/lite/testing/op_tests/elu.py
Normal file
53
tensorflow/lite/testing/op_tests/elu.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for elu."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_elu_tests(options):
|
||||
"""Make a set of tests to do (float) tf.nn.elu."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3],
|
||||
[3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for the test case."""
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.nn.elu(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for the test case."""
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
60
tensorflow/lite/testing/op_tests/embedding_lookup.py
Normal file
60
tensorflow/lite/testing/op_tests/embedding_lookup.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for embedding_lookup."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_embedding_lookup_tests(options):
|
||||
"""Make a set of tests to do gather."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"params_dtype": [tf.float32],
|
||||
"params_shape": [[10], [10, 10]],
|
||||
"ids_dtype": [tf.int32],
|
||||
"ids_shape": [[3], [5]],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the gather op testing graph."""
|
||||
params = tf.placeholder(
|
||||
dtype=parameters["params_dtype"],
|
||||
name="params",
|
||||
shape=parameters["params_shape"])
|
||||
ids = tf.placeholder(
|
||||
dtype=parameters["ids_dtype"],
|
||||
name="ids",
|
||||
shape=parameters["ids_shape"])
|
||||
out = tf.nn.embedding_lookup(params, ids)
|
||||
return [params, ids], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
params = create_tensor_data(parameters["params_dtype"],
|
||||
parameters["params_shape"])
|
||||
ids = create_tensor_data(parameters["ids_dtype"], parameters["ids_shape"],
|
||||
0, parameters["params_shape"][0] - 1)
|
||||
return [params, ids], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [params, ids])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/equal.py
Normal file
63
tensorflow/lite/testing/op_tests/equal.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for equal."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_equal_tests(options):
|
||||
"""Make a set of tests to do equal."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([], []), ([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the equal op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.equal(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
55
tensorflow/lite/testing/op_tests/exp.py
Normal file
55
tensorflow/lite/testing/op_tests/exp.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for exp."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_exp_tests(options):
|
||||
"""Make a set of tests to do exp."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the exp op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
out = tf.exp(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(
|
||||
parameters["input_dtype"],
|
||||
parameters["input_shape"],
|
||||
min_value=-100,
|
||||
max_value=9)
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
66
tensorflow/lite/testing/op_tests/expand_dims.py
Normal file
66
tensorflow/lite/testing/op_tests/expand_dims.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for expand_dims."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_expand_dims_tests(options):
|
||||
"""Make a set of tests to do expand_dims."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_type": [tf.float32, tf.int32],
|
||||
"input_shape": [[5, 4]],
|
||||
"axis_value": [0, 1, 2, -1, -2, -3],
|
||||
"constant_axis": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the where op testing graph."""
|
||||
inputs = []
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_type"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
inputs.append(input_value)
|
||||
|
||||
if parameters["constant_axis"]:
|
||||
axis_value = tf.constant(
|
||||
parameters["axis_value"], dtype=tf.int32, shape=[1])
|
||||
else:
|
||||
axis_value = tf.placeholder(dtype=tf.int32, name="axis", shape=[1])
|
||||
inputs.append(axis_value)
|
||||
|
||||
out = tf.expand_dims(input_value, axis=axis_value)
|
||||
return inputs, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = []
|
||||
input_values.append(
|
||||
create_tensor_data(parameters["input_type"], parameters["input_shape"]))
|
||||
if not parameters["constant_axis"]:
|
||||
input_values.append(np.array([parameters["axis_value"]], dtype=np.int32))
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
67
tensorflow/lite/testing/op_tests/eye.py
Normal file
67
tensorflow/lite/testing/op_tests/eye.py
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for eye."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_scalar_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_eye_tests(options):
|
||||
"""Make a set of tests for tf.eye op."""
|
||||
|
||||
test_parameters = [{
|
||||
"num_rows_shape": [[]],
|
||||
"num_cols_shape": [[]],
|
||||
"batch_shape": [[3], [2, 4], [4, 5, 6], None],
|
||||
"use_num_cols": [True, False],
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Make a set of tests to do eye."""
|
||||
|
||||
input_tensor0 = tf.placeholder(
|
||||
dtype=tf.int32, name="num_rows", shape=parameters["num_rows_shape"])
|
||||
input_tensor1 = tf.placeholder(
|
||||
dtype=tf.int32, name="num_columns", shape=parameters["num_cols_shape"])
|
||||
if parameters["use_num_cols"]:
|
||||
outs = tf.eye(
|
||||
num_rows=input_tensor0,
|
||||
num_columns=input_tensor1,
|
||||
batch_shape=parameters["batch_shape"],
|
||||
dtype=parameters["dtype"])
|
||||
return [input_tensor0, input_tensor1], [outs]
|
||||
else:
|
||||
outs = tf.eye(num_rows=input_tensor0, dtype=parameters["dtype"])
|
||||
return [input_tensor0], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value0 = create_scalar_data(dtype=np.int32, min_value=1)
|
||||
input_value1 = create_scalar_data(dtype=np.int32, min_value=1)
|
||||
if parameters["use_num_cols"]:
|
||||
return [input_value0, input_value1], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value0, input_value1])))
|
||||
else:
|
||||
return [input_value0], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value0])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
60
tensorflow/lite/testing/op_tests/fill.py
Normal file
60
tensorflow/lite/testing/op_tests/fill.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for fill."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_scalar_data
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_fill_tests(options):
|
||||
"""Make a set of tests to do fill."""
|
||||
|
||||
test_parameters = [{
|
||||
"dims_dtype": [tf.int32, tf.int64],
|
||||
"dims_shape": [[], [1], [3], [3, 3]],
|
||||
"value_dtype": [tf.int32, tf.int64, tf.float32],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the fill op testing graph."""
|
||||
input1 = tf.placeholder(
|
||||
dtype=parameters["dims_dtype"],
|
||||
name="dims",
|
||||
shape=parameters["dims_shape"])
|
||||
input2 = tf.placeholder(
|
||||
dtype=parameters["value_dtype"], name="value", shape=[])
|
||||
out = tf.fill(input1, input2)
|
||||
return [input1, input2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input1 = create_tensor_data(parameters["dims_dtype"],
|
||||
parameters["dims_shape"], 1)
|
||||
input2 = create_scalar_data(parameters["value_dtype"])
|
||||
return [input1, input2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input1, input2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=12)
|
49
tensorflow/lite/testing/op_tests/floor.py
Normal file
49
tensorflow/lite/testing/op_tests/floor.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for floor."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_floor_tests(options):
|
||||
"""Make a set of tests to do floor."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the floor op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.floor(input_value)
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(outputs, feed_dict={inputs[0]: input_value})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
99
tensorflow/lite/testing/op_tests/fully_connected.py
Normal file
99
tensorflow/lite/testing/op_tests/fully_connected.py
Normal file
@ -0,0 +1,99 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for fully_connected."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_fully_connected_tests(options):
|
||||
"""Make a set of tests to do fully_connected."""
|
||||
|
||||
test_parameters = [{
|
||||
"shape1": [[3, 3]],
|
||||
"shape2": [[3, 3]],
|
||||
"transpose_a": [True, False],
|
||||
"transpose_b": [True, False],
|
||||
"constant_filter": [True, False],
|
||||
}, {
|
||||
"shape1": [[4, 4], [1, 4], [4]],
|
||||
"shape2": [[4, 4], [4, 1], [4]],
|
||||
"transpose_a": [False],
|
||||
"transpose_b": [False],
|
||||
"constant_filter": [True, False],
|
||||
}, {
|
||||
"shape1": [[40, 37]],
|
||||
"shape2": [[37, 40]],
|
||||
"transpose_a": [False],
|
||||
"transpose_b": [False],
|
||||
"constant_filter": [True, False],
|
||||
}, {
|
||||
"shape1": [[40, 37]],
|
||||
"shape2": [[40, 37]],
|
||||
"transpose_a": [False],
|
||||
"transpose_b": [True],
|
||||
"constant_filter": [True, False],
|
||||
}, {
|
||||
"shape1": [[5, 3]],
|
||||
"shape2": [[5, 3]],
|
||||
"transpose_a": [True],
|
||||
"transpose_b": [False],
|
||||
"constant_filter": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a matmul graph given `parameters`."""
|
||||
input_tensor1 = tf.placeholder(
|
||||
dtype=tf.float32, name="input1", shape=parameters["shape1"])
|
||||
|
||||
# Get input_tensor2 either as a placeholder or constants. Also get a list of
|
||||
# the input tensors that are represented as placeholders.
|
||||
if parameters["constant_filter"]:
|
||||
input_tensor2 = create_tensor_data(np.float32, parameters["shape2"])
|
||||
input_tensors = [input_tensor1]
|
||||
else:
|
||||
input_tensor2 = tf.placeholder(
|
||||
dtype=tf.float32, name="input2", shape=parameters["shape2"])
|
||||
input_tensors = [input_tensor1, input_tensor2]
|
||||
|
||||
out = tf.matmul(
|
||||
input_tensor1,
|
||||
input_tensor2,
|
||||
transpose_a=parameters["transpose_a"],
|
||||
transpose_b=parameters["transpose_b"])
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
# Build list of input values either containing 1 tensor (input_values1) or 2
|
||||
# tensors (input_values1, input_values2) based on whether the second input
|
||||
# is a constant or variable input.
|
||||
values = [create_tensor_data(np.float32, shape=parameters["shape1"])]
|
||||
if not parameters["constant_filter"]:
|
||||
values.append(create_tensor_data(np.float32, parameters["shape2"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=10)
|
70
tensorflow/lite/testing/op_tests/fused_batch_norm.py
Normal file
70
tensorflow/lite/testing/op_tests/fused_batch_norm.py
Normal file
@ -0,0 +1,70 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for fused_batch_norm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_fused_batch_norm_tests(options):
|
||||
"""Make a set of tests to do fused_batch_norm."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 1, 6, 2]],
|
||||
"epsilon": [0.001, 0.1],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the testing graph for fused batch normalization."""
|
||||
input_shape = parameters["input_shape"]
|
||||
scale_shape = input_shape[3]
|
||||
|
||||
scale = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
offset = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
mean = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
variance = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
|
||||
x = create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
[x_norm, _, _] = tf.nn.fused_batch_norm(
|
||||
x,
|
||||
scale,
|
||||
offset,
|
||||
mean,
|
||||
variance,
|
||||
parameters["epsilon"],
|
||||
data_format="NHWC",
|
||||
is_training=False)
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.add(input_tensor, x_norm)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
77
tensorflow/lite/testing/op_tests/gather.py
Normal file
77
tensorflow/lite/testing/op_tests/gather.py
Normal file
@ -0,0 +1,77 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for gather."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_gather_tests(options):
|
||||
"""Make a set of tests to do gather."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"params_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"params_shape": [[10], [1, 2, 20]],
|
||||
"indices_dtype": [tf.int32, tf.int64],
|
||||
"indices_shape": [[3], [5]],
|
||||
"axis": [-1, 0, 1],
|
||||
},
|
||||
{
|
||||
# TODO(b/123895910): add Nd support for strings.
|
||||
"params_dtype": [tf.string],
|
||||
"params_shape": [[8]],
|
||||
"indices_dtype": [tf.int32],
|
||||
"indices_shape": [[3]],
|
||||
"axis": [0],
|
||||
}
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the gather op testing graph."""
|
||||
params = tf.placeholder(
|
||||
dtype=parameters["params_dtype"],
|
||||
name="params",
|
||||
shape=parameters["params_shape"])
|
||||
indices = tf.placeholder(
|
||||
dtype=parameters["indices_dtype"],
|
||||
name="indices",
|
||||
shape=parameters["indices_shape"])
|
||||
axis = min(len(parameters["params_shape"]), parameters["axis"])
|
||||
out = tf.gather(params, indices, axis=axis)
|
||||
return [params, indices], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
params = create_tensor_data(parameters["params_dtype"],
|
||||
parameters["params_shape"])
|
||||
indices = create_tensor_data(parameters["indices_dtype"],
|
||||
parameters["indices_shape"], 0,
|
||||
parameters["params_shape"][0] - 1)
|
||||
return [params, indices], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [params, indices])))
|
||||
|
||||
# Note that TF can't execute with index=1 and params_shape=[10].
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=12)
|
73
tensorflow/lite/testing/op_tests/gather_nd.py
Normal file
73
tensorflow/lite/testing/op_tests/gather_nd.py
Normal file
@ -0,0 +1,73 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for gather_nd."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_gather_nd_tests(options):
|
||||
"""Make a set of tests to do gather_nd."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"params_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"params_shape": [[5, 1]],
|
||||
"indices_dtype": [tf.int32, tf.int64],
|
||||
"indices_shape": [[1, 1]],
|
||||
},
|
||||
{
|
||||
"params_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"params_shape": [[5, 5]],
|
||||
"indices_dtype": [tf.int32, tf.int64],
|
||||
"indices_shape": [[2, 1], [2, 2]],
|
||||
},
|
||||
{
|
||||
"params_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"params_shape": [[5, 5, 10]],
|
||||
"indices_dtype": [tf.int32, tf.int64],
|
||||
"indices_shape": [[3, 1], [2, 2], [2, 3], [2, 1, 3]],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the gather_nd op testing graph."""
|
||||
params = tf.placeholder(
|
||||
dtype=parameters["params_dtype"],
|
||||
name="params",
|
||||
shape=parameters["params_shape"])
|
||||
indices = tf.placeholder(
|
||||
dtype=parameters["indices_dtype"],
|
||||
name="indices",
|
||||
shape=parameters["indices_shape"])
|
||||
out = tf.gather_nd(params, indices)
|
||||
return [params, indices], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
params = create_tensor_data(parameters["params_dtype"],
|
||||
parameters["params_shape"])
|
||||
indices = create_tensor_data(parameters["indices_dtype"],
|
||||
parameters["indices_shape"], 0,
|
||||
parameters["params_shape"][0] - 1)
|
||||
return [params, indices], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [params, indices])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
54
tensorflow/lite/testing/op_tests/gather_with_constant.py
Normal file
54
tensorflow/lite/testing/op_tests/gather_with_constant.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for gather_with_constant."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_gather_with_constant_tests(options):
|
||||
"""Make a set of test which feed a constant to gather toco."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[3]],
|
||||
"reference_shape": [[2]],
|
||||
}, {
|
||||
"input_shape": [[2, 3]],
|
||||
"reference_shape": [[2, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a graph where the inputs to Gather are constants."""
|
||||
reference = tf.placeholder(
|
||||
dtype=tf.int32, shape=parameters["reference_shape"])
|
||||
gather_input = tf.constant(
|
||||
create_tensor_data(tf.int32, parameters["input_shape"]))
|
||||
gather_indices = tf.constant([0, 1], tf.int32)
|
||||
out = tf.equal(reference, tf.gather(gather_input, gather_indices))
|
||||
return [reference], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
reference_values = np.zeros(parameters["reference_shape"], dtype=np.int32)
|
||||
return [reference_values], sess.run(
|
||||
outputs, feed_dict={inputs[0]: reference_values})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
65
tensorflow/lite/testing/op_tests/global_batch_norm.py
Normal file
65
tensorflow/lite/testing/op_tests/global_batch_norm.py
Normal file
@ -0,0 +1,65 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for global_batch_norm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_global_batch_norm_tests(options):
|
||||
"""Make a set of tests to do batch_norm_with_global_normalization."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 1, 6, 2], [3, 4, 5, 4]],
|
||||
"epsilon": [0.1, 0.0001],
|
||||
"scale_after": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the global batch norm testing graph."""
|
||||
input_shape = parameters["input_shape"]
|
||||
scale_shape = input_shape[3]
|
||||
|
||||
scale = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
offset = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
mean = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
variance = create_tensor_data(parameters["dtype"], scale_shape)
|
||||
|
||||
x = create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
x_norm = tf.nn.batch_norm_with_global_normalization(
|
||||
x, mean, variance, scale, offset, parameters["epsilon"],
|
||||
parameters["scale_after"])
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.add(input_tensor, x_norm)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/greater.py
Normal file
63
tensorflow/lite/testing/op_tests/greater.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for conv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_greater_tests(options):
|
||||
"""Make a set of tests to do greater."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the greater op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.greater(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
63
tensorflow/lite/testing/op_tests/greater_equal.py
Normal file
63
tensorflow/lite/testing/op_tests/greater_equal.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for greater_equal."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_greater_equal_tests(options):
|
||||
"""Make a set of tests to do greater_equal."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the greater_equal op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.greater_equal(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
76
tensorflow/lite/testing/op_tests/hardswish.py
Normal file
76
tensorflow/lite/testing/op_tests/hardswish.py
Normal file
@ -0,0 +1,76 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for hardswish."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import functools
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def _tflite_convert_verify_num_ops(tflite_convert_function, *args, **kwargs):
|
||||
"""Verifies that the result of the conversion is a single op."""
|
||||
num_ops = kwargs.pop("num_ops", 2)
|
||||
result = tflite_convert_function(*args, **kwargs)
|
||||
tflite_model_binary = result[0]
|
||||
if not result[0]:
|
||||
tf.logging.error(result[1]) # stderr from running tflite_convert.
|
||||
raise RuntimeError("Failed to bulid model: \n\n" + result[1])
|
||||
interpreter = tf.lite.Interpreter(model_content=tflite_model_binary)
|
||||
interpreter.allocate_tensors()
|
||||
if len(interpreter.get_tensor_details()) != num_ops:
|
||||
raise RuntimeError(
|
||||
"Expected to generate two node graph got %s " %
|
||||
"\n".join(str(x) for x in interpreter.get_tensor_details()))
|
||||
return result
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_hardswish_tests(options):
|
||||
"""Make a set of tests to do hardswish."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3],
|
||||
[3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
inp = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = inp * tf.nn.relu6(inp + np.float32(3)) * np.float32(1. / 6.)
|
||||
|
||||
return [inp], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-10, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
# Add additional validation if we are using toco.
|
||||
# Flex doesn't yet support this.
|
||||
if not options.run_with_flex:
|
||||
options.tflite_convert_function = functools.partial(
|
||||
_tflite_convert_verify_num_ops,
|
||||
options.tflite_convert_function,
|
||||
num_ops=2)
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
78
tensorflow/lite/testing/op_tests/identity.py
Normal file
78
tensorflow/lite/testing/op_tests/identity.py
Normal file
@ -0,0 +1,78 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for identity."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.python.ops import array_ops
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_identity_tests(options):
|
||||
"""Make a set of tests to do identity."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1], [3, 3]],
|
||||
"op_to_use": [
|
||||
"identity", "identity_n", "snapshot", "identity_n_with_2_inputs"
|
||||
],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Make a set of tests to do identity."""
|
||||
|
||||
input_tensors = []
|
||||
input_count = (2 if parameters["op_to_use"] == "identity_n_with_2_inputs"
|
||||
else 1)
|
||||
input_tensors = [
|
||||
tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
for _ in range(input_count)
|
||||
]
|
||||
|
||||
# We add the Multiply before Identity just as a walk-around to make the test
|
||||
# pass when input_shape is scalar.
|
||||
# During graph transformation, TOCO will replace the Identity op with
|
||||
# Reshape when input has shape. However, currently TOCO can't distinguish
|
||||
# between missing shape and scalar shape. As a result, when input has scalar
|
||||
# shape, this conversion still fails.
|
||||
# TODO(b/129197312), remove the walk-around code once the bug is fixed.
|
||||
inputs_doubled = [input_tensor * 2.0 for input_tensor in input_tensors]
|
||||
if parameters["op_to_use"] == "identity":
|
||||
identity_outputs = [tf.identity(inputs_doubled[0])]
|
||||
elif parameters["op_to_use"] == "snapshot":
|
||||
identity_outputs = [array_ops.snapshot(inputs_doubled[0])]
|
||||
elif parameters["op_to_use"] in ("identity_n", "identity_n_with_2_inputs"):
|
||||
identity_outputs = tf.identity_n(inputs_doubled)
|
||||
return input_tensors, identity_outputs
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = [
|
||||
create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
for _ in range(len(inputs))
|
||||
]
|
||||
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
60
tensorflow/lite/testing/op_tests/l2norm.py
Normal file
60
tensorflow/lite/testing/op_tests/l2norm.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for l2norm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_l2norm_tests(options):
|
||||
"""Make a set of tests to do l2norm."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[5, 7], [1, 1, 1, 1], [1, 3, 4, 3], [3, 15, 14, 3],
|
||||
[3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
"dim": [0, 1, 2, 3, [2, 3], -2],
|
||||
"epsilon": [None, 1e-12, 1e-3],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
if parameters["epsilon"]:
|
||||
out = tf.nn.l2_normalize(
|
||||
input_tensor, parameters["dim"], epsilon=parameters["epsilon"])
|
||||
else:
|
||||
out = tf.nn.l2_normalize(input_tensor, parameters["dim"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=9)
|
53
tensorflow/lite/testing/op_tests/l2norm_shared_epsilon.py
Normal file
53
tensorflow/lite/testing/op_tests/l2norm_shared_epsilon.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for l2norm_shared_epsilon."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_l2norm_shared_epsilon_tests(options):
|
||||
"""Regression test for a bug (b/122651451)."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[5, 7]],
|
||||
"dim": [1],
|
||||
"epsilon": [1e-8],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
epsilon = tf.constant(parameters["epsilon"])
|
||||
out1 = tf.nn.l2_normalize(input_tensor, parameters["dim"], epsilon=epsilon)
|
||||
out2 = tf.nn.l2_normalize(input_tensor, parameters["dim"], epsilon=epsilon)
|
||||
out = out1 + out2
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
53
tensorflow/lite/testing/op_tests/leaky_relu.py
Normal file
53
tensorflow/lite/testing/op_tests/leaky_relu.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for leaky_relu."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_leaky_relu_tests(options):
|
||||
"""Make a set of tests to do LeakyRelu."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[], [1], [5], [1, 10, 10, 3], [3, 3, 3, 3]],
|
||||
"alpha": [0.1, 1.0, 2.0, -0.1, -1.0, -2.0],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for the test case."""
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.nn.leaky_relu(input_tensor, alpha=parameters["alpha"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for the test case."""
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-3, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/less.py
Normal file
63
tensorflow/lite/testing/op_tests/less.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for less."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_less_tests(options):
|
||||
"""Make a set of tests to do less."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the less op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.less(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
63
tensorflow/lite/testing/op_tests/less_equal.py
Normal file
63
tensorflow/lite/testing/op_tests/less_equal.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for less_equal."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_less_equal_tests(options):
|
||||
"""Make a set of tests to do less_equal."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the less_equal op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.less_equal(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
57
tensorflow/lite/testing/op_tests/local_response_norm.py
Normal file
57
tensorflow/lite/testing/op_tests/local_response_norm.py
Normal file
@ -0,0 +1,57 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for local_response_norm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_local_response_norm_tests(options):
|
||||
"""Make a set of tests to do local_response_norm."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 1, 1, 1], [1, 3, 4, 3], [3, 15, 14, 3]],
|
||||
"depth_radius": [None, 0, 1, 3, 5],
|
||||
"bias": [None, 0.3, -0.1],
|
||||
"alpha": [None, 2, -3],
|
||||
"beta": [None, 0.25, 2],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.nn.local_response_normalization(
|
||||
input_tensor,
|
||||
depth_radius=parameters["depth_radius"],
|
||||
bias=parameters["bias"],
|
||||
alpha=parameters["alpha"],
|
||||
beta=parameters["beta"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
55
tensorflow/lite/testing/op_tests/log_softmax.py
Normal file
55
tensorflow/lite/testing/op_tests/log_softmax.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for log_softmax."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_log_softmax_tests(options):
|
||||
"""Make a set of tests to do log_softmax."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[1, 100], [4, 2], [5, 224]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the log_softmax op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
out = tf.nn.log_softmax(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(
|
||||
parameters["input_dtype"],
|
||||
parameters["input_shape"],
|
||||
min_value=-100,
|
||||
max_value=9)
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
79
tensorflow/lite/testing/op_tests/logic.py
Normal file
79
tensorflow/lite/testing/op_tests/logic.py
Normal file
@ -0,0 +1,79 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for logic operators."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def _make_logical_tests(op):
|
||||
"""Make a set of tests to do logical operations."""
|
||||
|
||||
def logical(options, expected_tf_failures=0):
|
||||
"""Generate examples."""
|
||||
test_parameters = [{
|
||||
"input_shape_pair": [([], []), ([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the logical testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=tf.bool, name="input1", shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=tf.bool, name="input2", shape=parameters["input_shape_pair"][1])
|
||||
out = op(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(tf.bool,
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(tf.bool,
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=expected_tf_failures)
|
||||
|
||||
return logical
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_logical_or_tests(options):
|
||||
"""Make a set of tests to do logical_or."""
|
||||
return _make_logical_tests(tf.logical_or)(options, expected_tf_failures=1)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_logical_and_tests(options):
|
||||
"""Make a set of tests to do logical_and."""
|
||||
return _make_logical_tests(tf.logical_and)(options, expected_tf_failures=1)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_logical_xor_tests(options):
|
||||
"""Make a set of tests to do logical_xor, test logical_not as well."""
|
||||
return _make_logical_tests(tf.logical_xor)(options, expected_tf_failures=1)
|
106
tensorflow/lite/testing/op_tests/lstm.py
Normal file
106
tensorflow/lite/testing/op_tests/lstm.py
Normal file
@ -0,0 +1,106 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for lstm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.python.ops import rnn
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_lstm_tests(options):
|
||||
"""Make a set of tests to do basic Lstm cell."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"num_batchs": [1],
|
||||
"time_step_size": [1],
|
||||
"input_vec_size": [3],
|
||||
"num_cells": [4],
|
||||
"split_tflite_lstm_inputs": [False],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a simple graph with BasicLSTMCell."""
|
||||
|
||||
num_batchs = parameters["num_batchs"]
|
||||
time_step_size = parameters["time_step_size"]
|
||||
input_vec_size = parameters["input_vec_size"]
|
||||
num_cells = parameters["num_cells"]
|
||||
inputs_after_split = []
|
||||
for i in xrange(time_step_size):
|
||||
one_timestamp_input = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="split_{}".format(i),
|
||||
shape=[num_batchs, input_vec_size])
|
||||
inputs_after_split.append(one_timestamp_input)
|
||||
# Currently lstm identifier has a few limitations: only supports
|
||||
# forget_bias == 0, inner state activation == tanh.
|
||||
# TODO(zhixianyan): Add another test with forget_bias == 1.
|
||||
# TODO(zhixianyan): Add another test with relu as activation.
|
||||
lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(
|
||||
num_cells, forget_bias=0.0, state_is_tuple=True)
|
||||
cell_outputs, _ = rnn.static_rnn(
|
||||
lstm_cell, inputs_after_split, dtype=tf.float32)
|
||||
out = cell_outputs[-1]
|
||||
return inputs_after_split, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Feed inputs, assign variables, and freeze graph."""
|
||||
|
||||
with tf.variable_scope("", reuse=True):
|
||||
kernel = tf.get_variable("rnn/basic_lstm_cell/kernel")
|
||||
bias = tf.get_variable("rnn/basic_lstm_cell/bias")
|
||||
kernel_values = create_tensor_data(parameters["dtype"],
|
||||
[kernel.shape[0], kernel.shape[1]], -1,
|
||||
1)
|
||||
bias_values = create_tensor_data(parameters["dtype"], [bias.shape[0]], 0,
|
||||
1)
|
||||
sess.run(tf.group(kernel.assign(kernel_values), bias.assign(bias_values)))
|
||||
|
||||
num_batchs = parameters["num_batchs"]
|
||||
time_step_size = parameters["time_step_size"]
|
||||
input_vec_size = parameters["input_vec_size"]
|
||||
input_values = []
|
||||
for _ in xrange(time_step_size):
|
||||
tensor_data = create_tensor_data(parameters["dtype"],
|
||||
[num_batchs, input_vec_size], 0, 1)
|
||||
input_values.append(tensor_data)
|
||||
out = sess.run(outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
return input_values, out
|
||||
|
||||
# TODO(zhixianyan): Automatically generate rnn_states for lstm cell.
|
||||
extra_toco_options = ExtraTocoOptions()
|
||||
extra_toco_options.rnn_states = (
|
||||
"{state_array:rnn/BasicLSTMCellZeroState/zeros,"
|
||||
"back_edge_source_array:rnn/basic_lstm_cell/Add_1,size:4},"
|
||||
"{state_array:rnn/BasicLSTMCellZeroState/zeros_1,"
|
||||
"back_edge_source_array:rnn/basic_lstm_cell/Mul_2,size:4}")
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
extra_toco_options,
|
||||
use_frozen_graph=True)
|
51
tensorflow/lite/testing/op_tests/matrix_diag.py
Normal file
51
tensorflow/lite/testing/op_tests/matrix_diag.py
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for matrix_diag."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_matrix_diag_tests(options):
|
||||
"""Make a set of tests for tf.linalg.diag op."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[3], [2, 3], [3, 4, 5], [2, 4, 6, 8]],
|
||||
"input_dtype": [tf.int32, tf.float32],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
outs = tf.matrix_diag(input_tensor)
|
||||
return [input_tensor], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
57
tensorflow/lite/testing/op_tests/matrix_set_diag.py
Normal file
57
tensorflow/lite/testing/op_tests/matrix_set_diag.py
Normal file
@ -0,0 +1,57 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for matrix_set_diag."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_matrix_set_diag_tests(options):
|
||||
"""Make a set of tests for tf.linalg.set_diag op."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_diag_shapes": [([3, 3], [3]), ([2, 3], [2]), ([2, 4,
|
||||
4], [2, 4]),
|
||||
([3, 4, 5, 6], [3, 4, 5])],
|
||||
"input_dtype": [tf.int32, tf.float32, tf.uint8],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_shape = parameters["input_diag_shapes"][0]
|
||||
diag_shape = parameters["input_diag_shapes"][1]
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"], name="input", shape=input_shape)
|
||||
diag_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"], name="diagonal", shape=diag_shape)
|
||||
outs = tf.matrix_set_diag(input_tensor, diag_tensor)
|
||||
return [input_tensor, diag_tensor], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_shape = parameters["input_diag_shapes"][0]
|
||||
diag_shape = parameters["input_diag_shapes"][1]
|
||||
input_values = create_tensor_data(parameters["input_dtype"], input_shape)
|
||||
diag_values = create_tensor_data(parameters["input_dtype"], diag_shape)
|
||||
return [input_values, diag_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values, diag_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
64
tensorflow/lite/testing/op_tests/maximum.py
Normal file
64
tensorflow/lite/testing/op_tests/maximum.py
Normal file
@ -0,0 +1,64 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for maximum."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_maximum_tests(options):
|
||||
"""Make a set of tests to do maximum."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape_1": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
"input_shape_2": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the maximum op testing graph."""
|
||||
input_tensor_1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input_1",
|
||||
shape=parameters["input_shape_1"])
|
||||
input_tensor_2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input_2",
|
||||
shape=parameters["input_shape_2"])
|
||||
|
||||
out = tf.maximum(input_tensor_1, input_tensor_2)
|
||||
return [input_tensor_1, input_tensor_2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_1"]),
|
||||
create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_2"])
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=8)
|
64
tensorflow/lite/testing/op_tests/minimum.py
Normal file
64
tensorflow/lite/testing/op_tests/minimum.py
Normal file
@ -0,0 +1,64 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for minimum."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_minimum_tests(options):
|
||||
"""Make a set of tests to do minimum."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape_1": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
"input_shape_2": [[], [3], [1, 100], [4, 2, 3], [5, 224, 224, 3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the minimum op testing graph."""
|
||||
input_tensor_1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input_1",
|
||||
shape=parameters["input_shape_1"])
|
||||
input_tensor_2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input_2",
|
||||
shape=parameters["input_shape_2"])
|
||||
|
||||
out = tf.minimum(input_tensor_1, input_tensor_2)
|
||||
return [input_tensor_1, input_tensor_2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_1"]),
|
||||
create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_2"])
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=8)
|
108
tensorflow/lite/testing/op_tests/mirror_pad.py
Normal file
108
tensorflow/lite/testing/op_tests/mirror_pad.py
Normal file
@ -0,0 +1,108 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for mirror_pad."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_mirror_pad_tests(options):
|
||||
"""Make a set of tests to do mirror_pad."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_shape": [[2, 3]],
|
||||
"padding_matrix": [[[1, 1], [2, 1]]],
|
||||
"mode": ["REFLECT"],
|
||||
"type": ["const"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[2, 3]],
|
||||
"padding_matrix": [[[1, 1], [1, 1]]],
|
||||
"mode": ["REFLECT"],
|
||||
"type": ["const"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[2, 3]],
|
||||
"padding_matrix": [[[1, 1], [2, 1]]],
|
||||
"mode": ["SYMMETRIC"],
|
||||
"type": ["placeholder"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[2, 3]],
|
||||
"padding_matrix": [[[1, 1], [2, 1]]],
|
||||
"mode": ["REFLECT"],
|
||||
"type": ["placeholder"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[3]],
|
||||
"padding_matrix": [[[0, 2]]],
|
||||
"mode": ["SYMMETRIC"],
|
||||
"type": ["placeholder"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[3]],
|
||||
"padding_matrix": [[[0, 2]]],
|
||||
"mode": ["SYMMETRIC"],
|
||||
"type": ["const"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[3]],
|
||||
"padding_matrix": [[[0, 2]]],
|
||||
"mode": ["REFLECT"],
|
||||
"type": ["const"]
|
||||
},
|
||||
{
|
||||
"input_shape": [[3, 2, 4, 5]],
|
||||
"padding_matrix": [[[1, 1], [2, 2], [1, 1], [1, 1]]],
|
||||
"mode": ["SYMMETRIC"],
|
||||
"type": ["placeholder"]
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for the test case."""
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.int32, name="input", shape=parameters["input_shape"])
|
||||
if parameters["type"] != "const":
|
||||
padding_matrix = tf.placeholder(
|
||||
dtype=tf.int32,
|
||||
name="padding",
|
||||
shape=[len(parameters["input_shape"]), 2])
|
||||
input_tensors = [input_tensor, padding_matrix]
|
||||
else:
|
||||
padding_matrix = tf.constant(np.array(parameters["padding_matrix"]))
|
||||
input_tensors = [input_tensor]
|
||||
output = tf.pad(
|
||||
input_tensor, paddings=padding_matrix, mode=parameters["mode"])
|
||||
|
||||
return input_tensors, [output]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = [create_tensor_data(tf.int32, parameters["input_shape"])]
|
||||
if parameters["type"] != "const":
|
||||
input_values.append(np.array(parameters["padding_matrix"]))
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
49
tensorflow/lite/testing/op_tests/neg.py
Normal file
49
tensorflow/lite/testing/op_tests/neg.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for neg."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_neg_tests(options):
|
||||
"""Make a set of tests to do neg."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[1, 3, 4, 3], [5], []],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the neg op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.negative(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [values], sess.run(outputs, feed_dict=dict(zip(inputs, [values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/not_equal.py
Normal file
63
tensorflow/lite/testing/op_tests/not_equal.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for not_equal."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_not_equal_tests(options):
|
||||
"""Make a set of tests to do not equal."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape_pair": [([1, 1, 1, 3], [1, 1, 1, 3]),
|
||||
([2, 3, 4, 5], [2, 3, 4, 5]), ([2, 3, 3], [2, 3]),
|
||||
([5, 5], [1]), ([10], [2, 4, 10])],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the not euqal op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape_pair"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_pair"][1])
|
||||
out = tf.not_equal(input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_pair"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=3)
|
85
tensorflow/lite/testing/op_tests/one_hot.py
Normal file
85
tensorflow/lite/testing/op_tests/one_hot.py
Normal file
@ -0,0 +1,85 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for one_hot."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_one_hot_tests(options):
|
||||
"""Make a set of tests to do one_hot."""
|
||||
|
||||
test_parameters = [{
|
||||
"indices_type": [tf.int32, tf.int64],
|
||||
"indices_shape": [[3], [4, 4], [1, 5], [5, 1]],
|
||||
"axis": [0, 1],
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"provide_optional_inputs": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the one_hot op testing graph."""
|
||||
indices = tf.placeholder(
|
||||
dtype=parameters["indices_type"],
|
||||
name="indices",
|
||||
shape=parameters["indices_shape"])
|
||||
depth = tf.placeholder(dtype=tf.int32, name="depth", shape=())
|
||||
|
||||
if not parameters["provide_optional_inputs"]:
|
||||
out = tf.one_hot(indices=indices, depth=depth)
|
||||
return [indices, depth], [out]
|
||||
|
||||
on_value = tf.placeholder(
|
||||
dtype=parameters["dtype"], name="on_value", shape=())
|
||||
off_value = tf.placeholder(
|
||||
dtype=parameters["dtype"], name="off_value", shape=())
|
||||
out = tf.one_hot(
|
||||
indices=indices,
|
||||
depth=depth,
|
||||
on_value=on_value,
|
||||
off_value=off_value,
|
||||
axis=parameters["axis"],
|
||||
dtype=parameters["dtype"])
|
||||
return [indices, depth, on_value, off_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the input for one_hot op."""
|
||||
input_values = [
|
||||
create_tensor_data(
|
||||
parameters["indices_type"],
|
||||
shape=parameters["indices_shape"],
|
||||
min_value=-1,
|
||||
max_value=10),
|
||||
create_tensor_data(tf.int32, shape=None, min_value=1, max_value=10),
|
||||
]
|
||||
|
||||
if parameters["provide_optional_inputs"]:
|
||||
input_values.append(
|
||||
create_tensor_data(
|
||||
parameters["dtype"], shape=None, min_value=1, max_value=10))
|
||||
input_values.append(
|
||||
create_tensor_data(
|
||||
parameters["dtype"], shape=None, min_value=-1, max_value=0))
|
||||
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
88
tensorflow/lite/testing/op_tests/pack.py
Normal file
88
tensorflow/lite/testing/op_tests/pack.py
Normal file
@ -0,0 +1,88 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for pack."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_pack_tests(options):
|
||||
"""Make a set of tests to do stack."""
|
||||
|
||||
test_parameters = [
|
||||
# Avoid creating all combinations to keep the test size small.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"base_shape": [[3, 4, 3], [3, 4], [5]],
|
||||
"num_tensors": [1, 2, 3, 4, 5, 6],
|
||||
"axis": [0, 1, 2, 3],
|
||||
"additional_shape": [1, 2, 3],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.int32],
|
||||
"base_shape": [[3, 4, 3], [3, 4], [5]],
|
||||
"num_tensors": [6],
|
||||
"axis": [0, 1, 2, 3],
|
||||
"additional_shape": [1, 2, 3],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.int64],
|
||||
"base_shape": [[3, 4, 3], [3, 4], [5]],
|
||||
"num_tensors": [5],
|
||||
"axis": [0, 1, 2, 3],
|
||||
"additional_shape": [1, 2, 3],
|
||||
}
|
||||
]
|
||||
|
||||
def get_shape(parameters):
|
||||
"""Return a tweaked version of 'base_shape'."""
|
||||
axis = parameters["axis"]
|
||||
shape = parameters["base_shape"][:]
|
||||
if axis < len(shape):
|
||||
shape[axis] += parameters["additional_shape"]
|
||||
return shape
|
||||
|
||||
def build_graph(parameters):
|
||||
all_tensors = []
|
||||
for n in range(0, parameters["num_tensors"]):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name=("input%d" % n),
|
||||
shape=get_shape(parameters))
|
||||
all_tensors.append(input_tensor)
|
||||
out = tf.stack(all_tensors, parameters["axis"])
|
||||
return all_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
all_values = []
|
||||
for _ in range(0, parameters["num_tensors"]):
|
||||
input_values = create_tensor_data(np.float32, get_shape(parameters))
|
||||
all_values.append(input_values)
|
||||
return all_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, all_values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=72)
|
84
tensorflow/lite/testing/op_tests/pad.py
Normal file
84
tensorflow/lite/testing/op_tests/pad.py
Normal file
@ -0,0 +1,84 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for pad."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_pad_tests(options):
|
||||
"""Make a set of tests to do pad."""
|
||||
|
||||
# TODO(nupurgarg): Add test for tf.uint8.
|
||||
test_parameters = [
|
||||
# 4D:
|
||||
{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[1, 1, 2, 1], [2, 1, 1, 1]],
|
||||
"paddings": [[[0, 0], [0, 1], [2, 3], [0, 0]],
|
||||
[[0, 1], [0, 0], [0, 0], [2, 3]]],
|
||||
"constant_paddings": [True, False],
|
||||
},
|
||||
# 2D:
|
||||
{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[1, 2]],
|
||||
"paddings": [[[0, 1], [2, 3]]],
|
||||
"constant_paddings": [True, False],
|
||||
},
|
||||
# 1D:
|
||||
{
|
||||
"dtype": [tf.int32],
|
||||
"input_shape": [[1]],
|
||||
"paddings": [[[1, 2]]],
|
||||
"constant_paddings": [False],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a pad graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
# Get paddings as either a placeholder or constants.
|
||||
if parameters["constant_paddings"]:
|
||||
paddings = parameters["paddings"]
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
shape = [len(parameters["paddings"]), 2]
|
||||
paddings = tf.placeholder(dtype=tf.int32, name="padding", shape=shape)
|
||||
input_tensors = [input_tensor, paddings]
|
||||
|
||||
out = tf.pad(input_tensor, paddings=paddings)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_paddings"]:
|
||||
values.append(np.array(parameters["paddings"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
90
tensorflow/lite/testing/op_tests/padv2.py
Normal file
90
tensorflow/lite/testing/op_tests/padv2.py
Normal file
@ -0,0 +1,90 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for padv2."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_padv2_tests(options):
|
||||
"""Make a set of tests to do padv2."""
|
||||
|
||||
# TODO(nupurgarg): Add test for tf.uint8.
|
||||
test_parameters = [
|
||||
# 4D:
|
||||
{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[1, 1, 2, 1], [2, 1, 1, 1]],
|
||||
"paddings": [[[0, 0], [0, 1], [2, 3], [0, 0]],
|
||||
[[0, 1], [0, 0], [0, 0], [2, 3]]],
|
||||
"constant_paddings": [True, False],
|
||||
"constant_values": [0, 2],
|
||||
},
|
||||
# 2D:
|
||||
{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[1, 2]],
|
||||
"paddings": [[[0, 1], [2, 3]]],
|
||||
"constant_paddings": [True, False],
|
||||
"constant_values": [0, 2],
|
||||
},
|
||||
# 1D:
|
||||
{
|
||||
"dtype": [tf.int32],
|
||||
"input_shape": [[1]],
|
||||
"paddings": [[[0, 1]]],
|
||||
"constant_paddings": [False],
|
||||
"constant_values": [0, 2],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a pad graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
# Get paddings as either a placeholder or constants.
|
||||
if parameters["constant_paddings"]:
|
||||
paddings = parameters["paddings"]
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
shape = [len(parameters["paddings"]), 2]
|
||||
paddings = tf.placeholder(dtype=tf.int32, name="padding", shape=shape)
|
||||
input_tensors = [input_tensor, paddings]
|
||||
|
||||
out = tf.pad(
|
||||
input_tensor,
|
||||
paddings=paddings,
|
||||
constant_values=parameters["constant_values"])
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_paddings"]:
|
||||
values.append(np.array(parameters["paddings"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
52
tensorflow/lite/testing/op_tests/placeholder_with_default.py
Normal file
52
tensorflow/lite/testing/op_tests/placeholder_with_default.py
Normal file
@ -0,0 +1,52 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for placeholder_with_default."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.lite.testing.zip_test_utils import TF_TYPE_INFO
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_placeholder_with_default_tests(options):
|
||||
"""Make a set of tests to test placeholder_with_default."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32, tf.int64],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the placeholder_with_default testing graph."""
|
||||
const_node = tf.constant([1, 2, 2, 0],
|
||||
shape=[2, 2],
|
||||
dtype=parameters["dtype"])
|
||||
input_tensor = tf.placeholder_with_default(
|
||||
const_node, shape=[2, 2], name="input")
|
||||
out = tf.equal(input_tensor, const_node, name="output")
|
||||
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
numpy_type = TF_TYPE_INFO[parameters["dtype"]][0]
|
||||
input_value = np.array([[1, 0], [2, 1]], numpy_type)
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
105
tensorflow/lite/testing/op_tests/pool.py
Normal file
105
tensorflow/lite/testing/op_tests/pool.py
Normal file
@ -0,0 +1,105 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for pool operators."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def make_pool_tests(pool_op_in):
|
||||
"""Make a set of tests to do average pooling.
|
||||
|
||||
Args:
|
||||
pool_op_in: TensorFlow pooling operation to test i.e. `tf.nn.avg_pool2d`.
|
||||
|
||||
Returns:
|
||||
A function representing the true generator (after curried pool_op_in).
|
||||
"""
|
||||
|
||||
pool_op = pool_op_in
|
||||
|
||||
def f(options, expected_tf_failures=0):
|
||||
"""Actual function that generates examples.
|
||||
|
||||
Args:
|
||||
options: An Options instance.
|
||||
expected_tf_failures: number of expected tensorflow failures.
|
||||
"""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"ksize": [[2, 1, 1, 2], [1, 1, 1, 1], [1, 1, 2, 1], [1, 10, 11, 1]],
|
||||
"strides": [[2, 1, 1, 2], [1, 1, 1, 1], [1, 1, 2, 1], [1, 10, 11, 1]],
|
||||
# TODO(aselle): should add in a degenerate shape (e.g. [1, 0, 1, 1]).
|
||||
"input_shape": [[], [1, 1, 1, 1], [1, 15, 14, 1], [3, 15, 14, 3]],
|
||||
"padding": ["SAME", "VALID"],
|
||||
"data_format": ["NHWC"], # TODO(aselle): NCHW would be good
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = pool_op(
|
||||
input_tensor,
|
||||
ksize=parameters["ksize"],
|
||||
strides=parameters["strides"],
|
||||
data_format=parameters["data_format"],
|
||||
padding=parameters["padding"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(tf.float32, parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=expected_tf_failures)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def make_l2_pool(input_tensor, ksize, strides, padding, data_format):
|
||||
"""Given an input perform a sequence of TensorFlow ops to produce l2pool."""
|
||||
return tf.sqrt(
|
||||
tf.nn.avg_pool(
|
||||
tf.square(input_tensor),
|
||||
ksize=ksize,
|
||||
strides=strides,
|
||||
padding=padding,
|
||||
data_format=data_format))
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_l2_pool_tests(options):
|
||||
make_pool_tests(make_l2_pool)(options, expected_tf_failures=80)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_avg_pool_tests(options):
|
||||
make_pool_tests(tf.nn.avg_pool)(options, expected_tf_failures=80)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_max_pool_tests(options):
|
||||
make_pool_tests(tf.nn.max_pool)(options, expected_tf_failures=80)
|
82
tensorflow/lite/testing/op_tests/prelu.py
Normal file
82
tensorflow/lite/testing/op_tests/prelu.py
Normal file
@ -0,0 +1,82 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for prelu."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_prelu_tests(options):
|
||||
"""Make a set of tests to do PReLU."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
# The canonical case for image processing is having a 4D `input`
|
||||
# (NHWC)and `shared_axes`=[1, 2], so the alpha parameter is per
|
||||
# channel.
|
||||
"input_shape": [[1, 10, 10, 3], [3, 3, 3, 3]],
|
||||
"shared_axes": [[1, 2], [1]],
|
||||
},
|
||||
{
|
||||
# 2D-3D example. Share the 2nd axis.
|
||||
"input_shape": [[20, 20], [20, 20, 20]],
|
||||
"shared_axes": [[1]],
|
||||
}
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for the test case."""
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
prelu = tf.keras.layers.PReLU(shared_axes=parameters["shared_axes"])
|
||||
out = prelu(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for the test case."""
|
||||
|
||||
input_shape = parameters["input_shape"]
|
||||
input_values = create_tensor_data(
|
||||
np.float32, input_shape, min_value=-10, max_value=10)
|
||||
shared_axes = parameters["shared_axes"]
|
||||
|
||||
alpha_shape = []
|
||||
for dim in range(1, len(input_shape)):
|
||||
alpha_shape.append(1 if dim in shared_axes else input_shape[dim])
|
||||
|
||||
alpha_values = create_tensor_data(np.float32, alpha_shape)
|
||||
|
||||
# There should be only 1 trainable variable tensor.
|
||||
variables = tf.all_variables()
|
||||
assert len(variables) == 1
|
||||
sess.run(variables[0].assign(alpha_values))
|
||||
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
use_frozen_graph=True)
|
55
tensorflow/lite/testing/op_tests/range.py
Normal file
55
tensorflow/lite/testing/op_tests/range.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for range."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_scalar_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_range_tests(options):
|
||||
"""Make a set of tests to do range."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.int32, tf.float32],
|
||||
"offset": [10, 100, 1000],
|
||||
"delta": [1, 2, 3, 4, -1, -2, -3, -4],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the range op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"], name=("start"), shape=[])
|
||||
if parameters["delta"] < 0:
|
||||
offset = parameters["offset"] * -1
|
||||
else:
|
||||
offset = parameters["offset"]
|
||||
delta = parameters["delta"]
|
||||
limit_tensor = input_tensor + offset
|
||||
delta_tensor = tf.constant(delta, dtype=parameters["dtype"])
|
||||
out = tf.range(input_tensor, limit_tensor, delta_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_scalar_data(parameters["dtype"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
47
tensorflow/lite/testing/op_tests/rank.py
Normal file
47
tensorflow/lite/testing/op_tests/rank.py
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for rank."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_rank_tests(options):
|
||||
"""Make a set of tests to do rank."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[], [0], [1, 1, 1, 3], [2, 3, 4, 5], [5, 5], [10]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the rank op testing graph."""
|
||||
input_value = tf.placeholder(dtype=parameters["input_dtype"], name="input")
|
||||
out = tf.rank(input_value)
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
166
tensorflow/lite/testing/op_tests/reduce.py
Normal file
166
tensorflow/lite/testing/op_tests/reduce.py
Normal file
@ -0,0 +1,166 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for reduce operators."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
def make_reduce_tests(reduce_op,
|
||||
min_value=-10,
|
||||
max_value=10,
|
||||
boolean_tensor_only=False):
|
||||
"""Make a set of tests to do reduce operation.
|
||||
|
||||
Args:
|
||||
reduce_op: TensorFlow reduce operation to test, i.e. `tf.reduce_mean`.
|
||||
min_value: min value for created tensor data.
|
||||
max_value: max value for created tensor data.
|
||||
boolean_tensor_only: If true, will only generate tensor with boolean value.
|
||||
|
||||
Returns:
|
||||
a function representing the true generator with `reduce_op_in` curried.
|
||||
"""
|
||||
|
||||
def f(options):
|
||||
"""Actual function that generates examples."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape": [[3, 3, 2, 4]],
|
||||
"axis": [
|
||||
0, 1, 2, [0, 1], [0, 2], [1, 2], [0, 1, 2], [1, 0], [2, 0],
|
||||
[2, 1], [2, 1, 0], [2, 0, 1], -1, -2, -3, [1, -1], [0, -1],
|
||||
[-1, 0], [-1, -2, -3], [0, 0, 0], [2, 2, 0], [1, 0, -3, -3]
|
||||
],
|
||||
"const_axis": [True, False],
|
||||
"keepdims": [True, False],
|
||||
},
|
||||
{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[1, 8, 8, 3]],
|
||||
"axis": [
|
||||
0, 1, 2, 3, [1, 2], [0, 3], [1, 2, 3], [0, 1, 2,
|
||||
3], [3, 2, 1, 0],
|
||||
[3, 1, 0, 2], [2, 0], [3, 0], [3, 1], [1, 0], -1, -2, -3, -4,
|
||||
[0, -2], [2, 3, -1, 0], [3, 1, 2, -3], [3, -4], [2, 2, 2],
|
||||
[2, 2, 3], [-3, -3, -4], [-3, 2, 1]
|
||||
],
|
||||
"const_axis": [True, False],
|
||||
"keepdims": [True, False],
|
||||
},
|
||||
{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1, 8, 8, 3], [3, 2, 4]],
|
||||
"axis": [[]], # shape is: [0]
|
||||
"const_axis": [False],
|
||||
"keepdims": [True, False],
|
||||
},
|
||||
{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1, 8, 8, 3], [3, 2, 4]],
|
||||
"axis": [None], # shape is: []
|
||||
"const_axis": [True],
|
||||
"keepdims": [True, False],
|
||||
}
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the mean op testing graph."""
|
||||
dtype = parameters["input_dtype"]
|
||||
if boolean_tensor_only:
|
||||
dtype = tf.bool
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=dtype, name="input", shape=parameters["input_shape"])
|
||||
|
||||
# Get axis as either a placeholder or constants.
|
||||
if parameters["const_axis"]:
|
||||
axis = parameters["axis"]
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
if isinstance(parameters["axis"], list):
|
||||
shape = [len(parameters["axis"])]
|
||||
else:
|
||||
shape = [] # shape for None or integers.
|
||||
axis = tf.placeholder(dtype=tf.int32, name="axis", shape=shape)
|
||||
input_tensors = [input_tensor, axis]
|
||||
|
||||
out = reduce_op(input_tensor, axis=axis, keepdims=parameters["keepdims"])
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for reduced operators."""
|
||||
|
||||
dtype = parameters["input_dtype"]
|
||||
if boolean_tensor_only:
|
||||
dtype = tf.bool
|
||||
values = [
|
||||
create_tensor_data(
|
||||
dtype,
|
||||
parameters["input_shape"],
|
||||
min_value=min_value,
|
||||
max_value=max_value)
|
||||
]
|
||||
if not parameters["const_axis"]:
|
||||
values.append(np.array(parameters["axis"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_mean_tests(options):
|
||||
"""Make a set of tests to do mean."""
|
||||
return make_reduce_tests(tf.reduce_mean)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sum_tests(options):
|
||||
"""Make a set of tests to do sum."""
|
||||
return make_reduce_tests(tf.reduce_sum)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reduce_prod_tests(options):
|
||||
"""Make a set of tests to do prod."""
|
||||
# set min max value to be -2, 2 to avoid overflow.
|
||||
return make_reduce_tests(tf.reduce_prod, -2, 2)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reduce_max_tests(options):
|
||||
"""Make a set of tests to do max."""
|
||||
return make_reduce_tests(tf.reduce_max)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reduce_min_tests(options):
|
||||
"""Make a set of tests to do min."""
|
||||
return make_reduce_tests(tf.reduce_min)(options)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reduce_any_tests(options):
|
||||
"""Make a set of tests to do any."""
|
||||
return make_reduce_tests(tf.reduce_any, boolean_tensor_only=True)(options)
|
49
tensorflow/lite/testing/op_tests/relu.py
Normal file
49
tensorflow/lite/testing/op_tests/relu.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for relu."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_relu_tests(options):
|
||||
"""Make a set of tests to do relu."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3],
|
||||
[3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.nn.relu(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-4, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
51
tensorflow/lite/testing/op_tests/relu1.py
Normal file
51
tensorflow/lite/testing/op_tests/relu1.py
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for relu1."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_relu1_tests(options):
|
||||
"""Make a set of tests to do relu1."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1, 1, 1, 1], [1, 3, 4, 3], [3, 15, 14, 3],
|
||||
[3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
# Note that the following is not supported:
|
||||
# out = tf.maximum(-1.0, tf.minimum(input_tensor, 1.0))
|
||||
out = tf.minimum(1.0, tf.maximum(input_tensor, -1.0))
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-3, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
49
tensorflow/lite/testing/op_tests/relu6.py
Normal file
49
tensorflow/lite/testing/op_tests/relu6.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for relu6."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_relu6_tests(options):
|
||||
"""Make a set of tests to do relu6."""
|
||||
|
||||
# Chose a set of parameters
|
||||
test_parameters = [{
|
||||
"input_shape": [[], [1, 1, 1, 1], [1, 3, 4, 3], [3, 15, 14, 3],
|
||||
[3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.nn.relu(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(
|
||||
np.float32, parameters["input_shape"], min_value=-3, max_value=10)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
73
tensorflow/lite/testing/op_tests/reshape.py
Normal file
73
tensorflow/lite/testing/op_tests/reshape.py
Normal file
@ -0,0 +1,73 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for reshape."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reshape_tests(options):
|
||||
"""Make a set of tests to do reshape."""
|
||||
|
||||
# All shapes below are suitable for tensors with 420 elements.
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[3, 4, 5, 7], [4, 105], [21, 5, 2, 2], [420]],
|
||||
"output_shape": [[15, 28], [420], [1, -1, 5, 7], [-1]],
|
||||
"constant_shape": [True, False],
|
||||
}, {
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1]],
|
||||
"output_shape": [[]],
|
||||
"constant_shape": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for reshape tests."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
# Get shape as either a placeholder or constants.
|
||||
if parameters["constant_shape"]:
|
||||
output_shape = parameters["output_shape"]
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
# The shape of the shape tensor.
|
||||
shape_tensor_shape = [len(parameters["output_shape"])]
|
||||
output_shape = tf.placeholder(
|
||||
dtype=tf.int32, name="output_shape", shape=shape_tensor_shape)
|
||||
input_tensors = [input_tensor, output_shape]
|
||||
out = tf.reshape(input_tensor, shape=output_shape)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_shape"]:
|
||||
values.append(np.array(parameters["output_shape"]))
|
||||
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
54
tensorflow/lite/testing/op_tests/resize_bilinear.py
Normal file
54
tensorflow/lite/testing/op_tests/resize_bilinear.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for resize_bilinear."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_resize_bilinear_tests(options):
|
||||
"""Make a set of tests to do resize_bilinear."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[1, 3, 4, 3], [1, 10, 2, 1]],
|
||||
"size": [[1, 1], [4, 3], [2, 2], [5, 6]],
|
||||
"align_corners": [None, True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.image.resize_bilinear(
|
||||
input_tensor,
|
||||
size=parameters["size"],
|
||||
align_corners=parameters["align_corners"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
54
tensorflow/lite/testing/op_tests/resize_nearest_neighbor.py
Normal file
54
tensorflow/lite/testing/op_tests/resize_nearest_neighbor.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for resize_nearest_neighbor."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_resize_nearest_neighbor_tests(options):
|
||||
"""Make a set of tests to do resize_nearest_neighbor."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[1, 3, 4, 3], [1, 10, 2, 1]],
|
||||
"size": [[1, 1], [4, 3], [2, 2], [5, 6]],
|
||||
"align_corners": [False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.image.resize_nearest_neighbor(
|
||||
input_tensor,
|
||||
size=parameters["size"],
|
||||
align_corners=parameters["align_corners"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
@ -0,0 +1,51 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for resolve_constant_strided_slice."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
# TODO(chaomei): refactor the test to cover more cases, like negative stride,
|
||||
# negative array index etc.
|
||||
@register_make_test_function()
|
||||
def make_resolve_constant_strided_slice_tests(options):
|
||||
"""Make a set of tests to show strided_slice yields incorrect results."""
|
||||
|
||||
test_parameters = [{
|
||||
"unused_iteration_counter": [1],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the strided_slice op testing graph."""
|
||||
del parameters
|
||||
input_values = tf.placeholder(dtype=tf.float32, shape=[4, 2])
|
||||
data = tf.constant(
|
||||
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],
|
||||
tf.float32)
|
||||
return [input_values], [input_values + data[:, :2]]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
del parameters
|
||||
input_values = np.zeros([4, 2], dtype=np.float32)
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict={inputs[0]: input_values})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
69
tensorflow/lite/testing/op_tests/reverse_sequence.py
Normal file
69
tensorflow/lite/testing/op_tests/reverse_sequence.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for reverse_sequence."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reverse_sequence_tests(options):
|
||||
"""Make a set of tests to do reverse_sequence."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape": [[8, 4, 5, 5, 6], [4, 4, 3, 5]],
|
||||
"seq_lengths": [[2, 2, 2, 2], [2, 1, 1, 0]],
|
||||
"seq_axis": [0, 3],
|
||||
"batch_axis": [1]
|
||||
}, {
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[2, 4, 5, 5, 6]],
|
||||
"seq_lengths": [[2, 1]],
|
||||
"seq_axis": [2],
|
||||
"batch_axis": [0]
|
||||
}, {
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[4, 2]],
|
||||
"seq_lengths": [[3, 1]],
|
||||
"seq_axis": [0],
|
||||
"batch_axis": [1]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for reverse_sequence tests."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
outs = tf.reverse_sequence(
|
||||
input_value,
|
||||
seq_lengths=parameters["seq_lengths"],
|
||||
batch_axis=parameters["batch_axis"],
|
||||
seq_axis=parameters["seq_axis"])
|
||||
return [input_value], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
55
tensorflow/lite/testing/op_tests/reverse_v2.py
Normal file
55
tensorflow/lite/testing/op_tests/reverse_v2.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for reverse_v2."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_reverse_v2_tests(options):
|
||||
"""Make a set of tests to do reverse_v2."""
|
||||
|
||||
test_parameters = [{
|
||||
"base_shape": [[3, 4, 3], [3, 4], [5, 6, 7, 8]],
|
||||
"axis": [0, 1, 2, 3],
|
||||
}]
|
||||
|
||||
def get_valid_axis(parameters):
|
||||
"""Return a tweaked version of 'axis'."""
|
||||
axis = parameters["axis"]
|
||||
shape = parameters["base_shape"][:]
|
||||
while axis > len(shape) - 1:
|
||||
axis -= 1
|
||||
return axis
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name=("input"), shape=parameters["base_shape"])
|
||||
outs = tf.reverse(input_tensor, axis=[get_valid_axis(parameters)])
|
||||
return [input_tensor], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(np.float32, shape=parameters["base_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
56
tensorflow/lite/testing/op_tests/rfft2d.py
Normal file
56
tensorflow/lite/testing/op_tests/rfft2d.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for rfft2d."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_rfft2d_tests(options):
|
||||
"""Make a set of tests to do rfft2d."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[8, 8], [3, 8, 8]],
|
||||
"fft_length": [
|
||||
None, [4, 4], [4, 8], [8, 4], [8, 8], [8, 16], [16, 8], [16, 16]
|
||||
]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
outs = tf.signal.rfft2d(input_value, fft_length=parameters["fft_length"])
|
||||
return [input_value], [outs]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
extra_toco_options = ExtraTocoOptions()
|
||||
extra_toco_options.allow_custom_ops = True
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
|
||||
extra_toco_options)
|
49
tensorflow/lite/testing/op_tests/round.py
Normal file
49
tensorflow/lite/testing/op_tests/round.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for round."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_round_tests(options):
|
||||
"""Build the round op testing graph."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the round op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input1",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.round(input_value)
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_value], sess.run(outputs, feed_dict={inputs[0]: input_value})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/shape.py
Normal file
63
tensorflow/lite/testing/op_tests/shape.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for shape."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_shape_tests(options):
|
||||
"""Make a set of tests to do shape."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[1, 4]],
|
||||
"new_shape": [[1, 4], [4, 1], [2, 2]],
|
||||
"out_type": [tf.int32, tf.int64],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the shape op testing graph."""
|
||||
# Note that we intentionally leave out the shape from the input placeholder
|
||||
# to prevent the Shape operation from being optimized out during conversion.
|
||||
# TODO(haoliang): Test shape op directly after we have better support for
|
||||
# dynamic input. Currently we need to introduce a Reshape op to prevent
|
||||
# shape being constant-folded.
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
shape=parameters["input_shape"],
|
||||
name="input")
|
||||
shape_of_new_shape = [len(parameters["new_shape"])]
|
||||
new_shape = tf.placeholder(
|
||||
dtype=tf.int32, shape=shape_of_new_shape, name="new_shape")
|
||||
reshaped = tf.reshape(input_value, shape=new_shape)
|
||||
out = tf.shape(reshaped, out_type=parameters["out_type"])
|
||||
return [input_value, new_shape], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
new_shape = np.array(parameters["new_shape"])
|
||||
return [input_value, new_shape], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value, new_shape])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
49
tensorflow/lite/testing/op_tests/sigmoid.py
Normal file
49
tensorflow/lite/testing/op_tests/sigmoid.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for sigmoid."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sigmoid_tests(options):
|
||||
"""Make a set of tests to do sigmoid."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 3, 4, 3], [4], [], [1, 2, 3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.sigmoid(input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
104
tensorflow/lite/testing/op_tests/slice.py
Normal file
104
tensorflow/lite/testing/op_tests/slice.py
Normal file
@ -0,0 +1,104 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for slice."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.lite.testing.zip_test_utils import TF_TYPE_INFO
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_slice_tests(options):
|
||||
"""Make a set of tests to do slice."""
|
||||
|
||||
# TODO(renjieliu): add test/support for uint8.
|
||||
test_parameters = [
|
||||
# 4-D
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32, tf.int64, tf.string],
|
||||
"index_type": [tf.int32, tf.int64],
|
||||
"input_shape": [[12, 2, 2, 5]],
|
||||
"begin": [[0, 0, 0, 0], [1, 0, 1, 0]],
|
||||
"size": [[8, 2, 2, 3], [11, 2, 1, 5]],
|
||||
},
|
||||
# 2-D
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32, tf.int64, tf.string],
|
||||
"index_type": [tf.int32, tf.int64],
|
||||
"input_shape": [[2, 3]],
|
||||
"begin": [[0, 0], [1, 0]],
|
||||
"size": [[2, 3], [2, 2]],
|
||||
},
|
||||
# 4-D with size -1
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[4, 4, 4, 4]],
|
||||
"begin": [[0, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
|
||||
[0, 0, 0, 1]],
|
||||
"size": [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]],
|
||||
},
|
||||
# last dimension out of index
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[4, 4, 4]],
|
||||
"begin": [[3, 3, 4]],
|
||||
"size": [[-1, -1, -1]],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build graph for slice test."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
begin = tf.placeholder(
|
||||
dtype=parameters["index_type"],
|
||||
name="begin",
|
||||
shape=[len(parameters["input_shape"])])
|
||||
size = tf.placeholder(
|
||||
dtype=parameters["index_type"],
|
||||
name="size",
|
||||
shape=[len(parameters["input_shape"])])
|
||||
tensors = [input_tensor, begin, size]
|
||||
out = tf.slice(input_tensor, begin, size)
|
||||
return tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build inputs for slice test."""
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
index_type = TF_TYPE_INFO[parameters["index_type"]][0]
|
||||
|
||||
begin_values = np.array(parameters["begin"]).astype(index_type)
|
||||
size_values = np.array(parameters["size"]).astype(index_type)
|
||||
values = [input_values, begin_values, size_values]
|
||||
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=24)
|
54
tensorflow/lite/testing/op_tests/softmax.py
Normal file
54
tensorflow/lite/testing/op_tests/softmax.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for softmax."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_softmax_tests(options):
|
||||
"""Make a set of tests to do softmax."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 3, 4, 3], [2, 3]],
|
||||
"dim": [-1, 0],
|
||||
}, {
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[4, 7]],
|
||||
"dim": [-1, 1],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.nn.softmax(input_tensor, dim=parameters["dim"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
102
tensorflow/lite/testing/op_tests/space_to_batch_nd.py
Normal file
102
tensorflow/lite/testing/op_tests/space_to_batch_nd.py
Normal file
@ -0,0 +1,102 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for space_to_batch_nd."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_space_to_batch_nd_tests(options):
|
||||
"""Make a set of tests to do space_to_batch_nd."""
|
||||
|
||||
# TODO(nupurgarg): Add test for uint8.
|
||||
test_parameters = [
|
||||
{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[1, 2, 2, 3], [2, 2, 4, 1]],
|
||||
"block_shape": [[1, 3], [2, 2]],
|
||||
"paddings": [[[0, 0], [0, 0]], [[0, 0], [2, 0]], [[1, 1], [1, 1]]],
|
||||
"constant_block_shape": [True, False],
|
||||
"constant_paddings": [True, False],
|
||||
},
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[2, 3, 7, 3]],
|
||||
"block_shape": [[1, 3], [2, 2]],
|
||||
"paddings": [[[0, 0], [2, 0]], [[1, 0], [1, 0]]],
|
||||
"constant_block_shape": [True, False],
|
||||
"constant_paddings": [True, False],
|
||||
},
|
||||
# Non-4D use case: 1 bath dimension, 3 spatial dimensions, 2 others.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 4, 4, 4, 1, 1]],
|
||||
"block_shape": [[2, 2, 2]],
|
||||
"paddings": [[[0, 0], [0, 0], [0, 0]]],
|
||||
"constant_block_shape": [True, False],
|
||||
"constant_paddings": [True, False],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a space_to_batch graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
input_tensors = [input_tensor]
|
||||
|
||||
# Get block_shape either as a const or as a placeholder (tensor).
|
||||
if parameters["constant_block_shape"]:
|
||||
block_shape = parameters["block_shape"]
|
||||
else:
|
||||
shape = [len(parameters["block_shape"])]
|
||||
block_shape = tf.placeholder(dtype=tf.int32, name="shape", shape=shape)
|
||||
input_tensors.append(block_shape)
|
||||
|
||||
# Get paddings either as a const or as a placeholder (tensor).
|
||||
if parameters["constant_paddings"]:
|
||||
paddings = parameters["paddings"]
|
||||
else:
|
||||
shape = [len(parameters["paddings"]), 2]
|
||||
paddings = tf.placeholder(dtype=tf.int32, name="paddings", shape=shape)
|
||||
input_tensors.append(paddings)
|
||||
|
||||
out = tf.space_to_batch_nd(input_tensor, block_shape, paddings)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_block_shape"]:
|
||||
values.append(np.array(parameters["block_shape"]))
|
||||
if not parameters["constant_paddings"]:
|
||||
values.append(np.array(parameters["paddings"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=56)
|
50
tensorflow/lite/testing/op_tests/space_to_depth.py
Normal file
50
tensorflow/lite/testing/op_tests/space_to_depth.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for space_to_depth."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_space_to_depth_tests(options):
|
||||
"""Make a set of tests to do space_to_depth."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32, tf.int32, tf.uint8, tf.int64],
|
||||
"input_shape": [[2, 12, 24, 1]],
|
||||
"block_size": [2, 3, 4],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.space_to_depth(input_tensor, block_size=parameters["block_size"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
88
tensorflow/lite/testing/op_tests/sparse_to_dense.py
Normal file
88
tensorflow/lite/testing/op_tests/sparse_to_dense.py
Normal file
@ -0,0 +1,88 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for sparse_to_dense."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_scalar_data
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_sparse_to_dense_tests(options):
|
||||
"""Make a set of tests to do sparse to dense."""
|
||||
|
||||
test_parameters = [{
|
||||
"value_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"index_dtype": [tf.int32, tf.int64],
|
||||
"value_count": [1, 3, 6, 8],
|
||||
"dense_shape": [[15], [3, 10], [4, 4, 4, 4], [7, 10, 9]],
|
||||
"default_value": [0, -1],
|
||||
"value_is_scalar": [True, False],
|
||||
}]
|
||||
|
||||
# Return a single value for 1-D dense shape, but a tuple for other shapes.
|
||||
def generate_index(dense_shape):
|
||||
if len(dense_shape) == 1:
|
||||
return np.random.randint(dense_shape[0])
|
||||
else:
|
||||
index = []
|
||||
for shape in dense_shape:
|
||||
index.append(np.random.randint(shape))
|
||||
return tuple(index)
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the sparse_to_dense op testing graph."""
|
||||
dense_shape = parameters["dense_shape"]
|
||||
|
||||
# Special handle for value_is_scalar case.
|
||||
# value_count must be 1.
|
||||
if parameters["value_is_scalar"] and parameters["value_count"] == 1:
|
||||
value = tf.placeholder(
|
||||
name="value", dtype=parameters["value_dtype"], shape=())
|
||||
else:
|
||||
value = tf.placeholder(
|
||||
name="value",
|
||||
dtype=parameters["value_dtype"],
|
||||
shape=[parameters["value_count"]])
|
||||
indices = set()
|
||||
while len(indices) < parameters["value_count"]:
|
||||
indices.add(generate_index(dense_shape))
|
||||
indices = tf.constant(tuple(indices), dtype=parameters["index_dtype"])
|
||||
# TODO(renjieliu): Add test for validate_indices case.
|
||||
out = tf.sparse_to_dense(
|
||||
indices,
|
||||
dense_shape,
|
||||
value,
|
||||
parameters["default_value"],
|
||||
validate_indices=False)
|
||||
|
||||
return [value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
if parameters["value_is_scalar"] and parameters["value_count"] == 1:
|
||||
input_value = create_scalar_data(parameters["value_dtype"])
|
||||
else:
|
||||
input_value = create_tensor_data(parameters["value_dtype"],
|
||||
[parameters["value_count"]])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
53
tensorflow/lite/testing/op_tests/split.py
Normal file
53
tensorflow/lite/testing/op_tests/split.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for split."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_split_tests(options):
|
||||
"""Make a set of tests to do tf.split."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 3, 4, 6], [2, 4, 1], [6, 4], [8]],
|
||||
"num_or_size_splits": [1, 2, 3, 4, 5],
|
||||
"axis": [0, 1, 2, 3, -4, -3, -2, -1],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.split(input_tensor, parameters["num_or_size_splits"],
|
||||
parameters["axis"])
|
||||
return [input_tensor], [out[0]]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [create_tensor_data(np.float32, parameters["input_shape"])]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=112)
|
53
tensorflow/lite/testing/op_tests/splitv.py
Normal file
53
tensorflow/lite/testing/op_tests/splitv.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for splitv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_splitv_tests(options):
|
||||
"""Make a set of tests to do tf.split_v."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 3, 4, 6], [2, 4, 1], [6, 4], [8]],
|
||||
"size_splits": [[2, 2], [1, 3], [4, 2], [5, 3], [-1, 1], [-1, 2], [-1,
|
||||
4]],
|
||||
"axis": [0, 1, 2, 3, -4, -3, -2, -1],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=parameters["input_shape"])
|
||||
out = tf.split(input_tensor, parameters["size_splits"], parameters["axis"])
|
||||
return [input_tensor], [out[0]]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [create_tensor_data(np.float32, parameters["input_shape"])]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=158)
|
67
tensorflow/lite/testing/op_tests/squeeze.py
Normal file
67
tensorflow/lite/testing/op_tests/squeeze.py
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for squeeze."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_squeeze_tests(options):
|
||||
"""Make a set of tests to do squeeze."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.int32, tf.float32, tf.int64],
|
||||
"input_shape": [[1, 2, 1, 3, 1, 4, 1, 1]],
|
||||
"axis": [
|
||||
None, [], [0, 2], [4, 7], [-1, 0, 2, 0, 7, -6], [1], [2, 3, 2],
|
||||
[-1, -2, -4, -6, -8], [0, 2, 4, 6, 7], [7, 6, 4, 2, 0], [6, 6],
|
||||
[0, 1, 2, 3, 4, 5, 6, 7], [-2, -3, 1, 0, 7, -5]
|
||||
],
|
||||
}, {
|
||||
"dtype": [tf.int32, tf.float32, tf.int64],
|
||||
"input_shape": [[1]],
|
||||
"axis": [None, [], [0], [-1]],
|
||||
}, {
|
||||
"dtype": [tf.int32, tf.float32, tf.int64],
|
||||
"input_shape": [[1, 1, 1, 1, 1]],
|
||||
"axis": [None, [], [0], [3, 0], [-2, 0, 3, 2]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.squeeze(input_tensor, axis=parameters["axis"])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=12)
|
56
tensorflow/lite/testing/op_tests/squeeze_transpose.py
Normal file
56
tensorflow/lite/testing/op_tests/squeeze_transpose.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for squeeze_transpose."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_squeeze_transpose_tests(options):
|
||||
"""Make a set of tests to do squeeze followed by transpose."""
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.int32, tf.float32, tf.int64],
|
||||
"input_shape": [[1, 4, 10, 1]],
|
||||
"axis": [[-1], [3]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
out = tf.squeeze(input_tensor, axis=parameters["axis"])
|
||||
out = tf.transpose(out, perm=[1, 2])
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
return [input_values], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_values])))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=0)
|
189
tensorflow/lite/testing/op_tests/strided_slice.py
Normal file
189
tensorflow/lite/testing/op_tests/strided_slice.py
Normal file
@ -0,0 +1,189 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for strided_slice operators."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.lite.testing.zip_test_utils import TF_TYPE_INFO
|
||||
|
||||
|
||||
def _make_strided_slice_tests(options, test_parameters, expected_tf_failures=0):
|
||||
"""Utility function to make strided_slice_tests based on parameters."""
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build graph for stride_slice test."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
if parameters["constant_indices"]:
|
||||
begin = parameters["begin"]
|
||||
end = parameters["end"]
|
||||
strides = parameters["strides"]
|
||||
tensors = [input_tensor]
|
||||
else:
|
||||
begin = tf.placeholder(
|
||||
dtype=parameters["index_type"],
|
||||
name="begin",
|
||||
shape=[len(parameters["input_shape"])])
|
||||
end = tf.placeholder(
|
||||
dtype=parameters["index_type"],
|
||||
name="end",
|
||||
shape=[len(parameters["input_shape"])])
|
||||
strides = None
|
||||
if parameters["strides"] is not None:
|
||||
strides = tf.placeholder(
|
||||
dtype=parameters["index_type"],
|
||||
name="strides",
|
||||
shape=[len(parameters["input_shape"])])
|
||||
tensors = [input_tensor, begin, end]
|
||||
if strides is not None:
|
||||
tensors.append(strides)
|
||||
out = tf.strided_slice(
|
||||
input_tensor,
|
||||
begin,
|
||||
end,
|
||||
strides,
|
||||
begin_mask=parameters["begin_mask"],
|
||||
end_mask=parameters["end_mask"])
|
||||
return tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build inputs for stride_slice test."""
|
||||
input_values = create_tensor_data(parameters["dtype"],
|
||||
parameters["input_shape"])
|
||||
index_type = TF_TYPE_INFO[parameters["index_type"]][0]
|
||||
values = [input_values]
|
||||
if not parameters["constant_indices"]:
|
||||
begin_values = np.array(parameters["begin"]).astype(index_type)
|
||||
end_values = np.array(parameters["end"]).astype(index_type)
|
||||
stride_values = (
|
||||
np.array(parameters["strides"]).astype(index_type)
|
||||
if parameters["strides"] is not None else None)
|
||||
values.append(begin_values)
|
||||
values.append(end_values)
|
||||
if stride_values is not None:
|
||||
values.append(stride_values)
|
||||
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=expected_tf_failures)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_strided_slice_tests(options):
|
||||
"""Make a set of tests to do strided_slice."""
|
||||
|
||||
# TODO(soroosh): add test/support for uint8.
|
||||
test_parameters = [
|
||||
# 4-D (basic cases with const/non-const indices).
|
||||
{
|
||||
"dtype": [tf.float32, tf.int32, tf.int64, tf.bool],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[12, 2, 2, 5]],
|
||||
"strides": [None, [2, 1, 3, 1]],
|
||||
"begin": [[0, 0, 0, 0]],
|
||||
"end": [[12, 2, 2, 5]],
|
||||
"begin_mask": [None],
|
||||
"end_mask": [None],
|
||||
"shrink_axis_mask": [None],
|
||||
"constant_indices": [False, True],
|
||||
},
|
||||
# 4-D with non-trivial begin & end.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[12, 2, 2, 5]],
|
||||
"begin": [[0, 0, 0, 0], [1, 0, 1, 0]],
|
||||
"end": [[8, 2, 2, 3], [12, 2, 2, 5]],
|
||||
"strides": [None, [2, 1, 3, 1]],
|
||||
"begin_mask": [None, 8],
|
||||
"end_mask": [None, 3],
|
||||
"shrink_axis_mask": [None, 15, -1],
|
||||
"constant_indices": [True],
|
||||
},
|
||||
# Begin, end, strides dim are different from input shape
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[12, 2, 2, 5]],
|
||||
"begin": [[0]],
|
||||
"end": [[1]],
|
||||
"strides": [None, [1]],
|
||||
"begin_mask": [0],
|
||||
"end_mask": [0],
|
||||
"shrink_axis_mask": [1],
|
||||
"constant_indices": [True],
|
||||
},
|
||||
# 2-D
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[2, 3]],
|
||||
"begin": [[0, 0]],
|
||||
"end": [[2, 2]],
|
||||
"strides": [None, [2, 2]],
|
||||
"begin_mask": [None, 1, 2],
|
||||
"end_mask": [None, 1, 2],
|
||||
"shrink_axis_mask": [None, 1, 2, 3, -1],
|
||||
"constant_indices": [False, True],
|
||||
},
|
||||
# Negative strides
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[2, 3]],
|
||||
"begin": [[0, -1]],
|
||||
"end": [[2, -3]],
|
||||
"strides": [[1, -1]],
|
||||
"begin_mask": [None, 1, 2],
|
||||
"end_mask": [None, 1, 2],
|
||||
"shrink_axis_mask": [None, 1, 2, 3, -1],
|
||||
"constant_indices": [False],
|
||||
},
|
||||
]
|
||||
_make_strided_slice_tests(options, test_parameters, expected_tf_failures=2)
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_strided_slice_1d_exhaustive_tests(options):
|
||||
"""Make a set of exhaustive tests for 1D strided_slice."""
|
||||
test_parameters = [
|
||||
# 1-D Exhaustive
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"index_type": [tf.int32],
|
||||
"input_shape": [[3]],
|
||||
"begin": [[-2], [-1], [0], [1], [2]],
|
||||
"end": [[-2], [-1], [0], [1], [2]],
|
||||
"strides": [[-2], [-1], [1], [2]],
|
||||
"begin_mask": [0, 1],
|
||||
"end_mask": [0, 1],
|
||||
"shrink_axis_mask": [0],
|
||||
"constant_indices": [False],
|
||||
},
|
||||
]
|
||||
_make_strided_slice_tests(options, test_parameters)
|
81
tensorflow/lite/testing/op_tests/strided_slice_np_style.py
Normal file
81
tensorflow/lite/testing/op_tests/strided_slice_np_style.py
Normal file
@ -0,0 +1,81 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for strided_slice_np_style."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
# TODO(b/137615945): Expand the test coverage of this one and remove the old
|
||||
# ones.
|
||||
@register_make_test_function()
|
||||
def make_strided_slice_np_style_tests(options):
|
||||
"""Make a set of tests to test strided_slice in np style."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[12, 7], [33, 1]],
|
||||
"spec": [[slice(3, 7, 2), slice(None)],
|
||||
[tf.newaxis,
|
||||
slice(3, 7, 1), tf.newaxis,
|
||||
slice(None)], [slice(1, 5, 1), slice(None)]],
|
||||
},
|
||||
# 1-D case
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[44]],
|
||||
"spec": [[slice(3, 7, 2)], [tf.newaxis, slice(None)]],
|
||||
},
|
||||
# Shrink mask.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[21, 15, 7]],
|
||||
"spec": [[slice(3, 7, 2), slice(None), 2]],
|
||||
},
|
||||
# Ellipsis.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[21, 15, 7]],
|
||||
"spec": [[slice(3, 7, 2), Ellipsis]],
|
||||
},
|
||||
# All combinations.
|
||||
{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[21, 15, 7]],
|
||||
"spec": [[tf.newaxis,
|
||||
slice(3, 7, 2),
|
||||
slice(None), Ellipsis]],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a simple graph with np style strided_slice."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["dtype"], shape=parameters["shape"])
|
||||
out = input_value.__getitem__(parameters["spec"])
|
||||
return [input_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["dtype"], parameters["shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/tile.py
Normal file
63
tensorflow/lite/testing/op_tests/tile.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for tile."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_tile_tests(options):
|
||||
"""Make a set of tests to do tile."""
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.bool],
|
||||
"input_shape": [[3, 2, 1], [2, 2, 2]],
|
||||
"multiplier_dtype": [tf.int32, tf.int64],
|
||||
"multiplier_shape": [[3]]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the tile op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
shape=parameters["input_shape"],
|
||||
name="input")
|
||||
multiplier_value = tf.placeholder(
|
||||
dtype=parameters["multiplier_dtype"],
|
||||
shape=parameters["multiplier_shape"],
|
||||
name="multiplier")
|
||||
out = tf.tile(input_value, multiplier_value)
|
||||
return [input_value, multiplier_value], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
multipliers_value = create_tensor_data(
|
||||
parameters["multiplier_dtype"],
|
||||
parameters["multiplier_shape"],
|
||||
min_value=0)
|
||||
return [input_value, multipliers_value], sess.run(
|
||||
outputs,
|
||||
feed_dict={
|
||||
inputs[0]: input_value,
|
||||
inputs[1]: multipliers_value
|
||||
})
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
63
tensorflow/lite/testing/op_tests/topk.py
Normal file
63
tensorflow/lite/testing/op_tests/topk.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for topk."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_topk_tests(options):
|
||||
"""Make a set of tests to do topk."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape": [[10], [5, 20]],
|
||||
"input_k": [None, 1, 3],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the topk op testing graph."""
|
||||
input_value = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
if parameters["input_k"] is not None:
|
||||
k = tf.placeholder(dtype=tf.int32, name="input_k", shape=[])
|
||||
inputs = [input_value, k]
|
||||
else:
|
||||
k = tf.constant(3, name="k")
|
||||
inputs = [input_value]
|
||||
out = tf.nn.top_k(input_value, k)
|
||||
return inputs, [out[1]]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
if parameters["input_k"] is not None:
|
||||
k = np.array(parameters["input_k"], dtype=np.int32)
|
||||
return [input_value, k], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value, k])))
|
||||
else:
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
80
tensorflow/lite/testing/op_tests/transpose.py
Normal file
80
tensorflow/lite/testing/op_tests/transpose.py
Normal file
@ -0,0 +1,80 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for transpose."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_transpose_tests(options):
|
||||
"""Make a set of tests to do transpose."""
|
||||
|
||||
# TODO(nupurgarg): Add test for uint8.
|
||||
test_parameters = [{
|
||||
"dtype": [tf.int32, tf.int64, tf.float32],
|
||||
"input_shape": [[2, 2, 3]],
|
||||
"perm": [[0, 1, 2], [0, 2, 1]],
|
||||
"constant_perm": [True, False],
|
||||
}, {
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 2, 3, 4]],
|
||||
"perm": [[0, 1, 2, 3], [3, 0, 1, 2]],
|
||||
"constant_perm": [True, False],
|
||||
}, {
|
||||
"dtype": [tf.float32],
|
||||
"input_shape": [[1, 2, 3, 4, 5]],
|
||||
"perm": [[4, 3, 2, 1, 0]],
|
||||
"constant_perm": [True, False],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a transpose graph given `parameters`."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
|
||||
if parameters["constant_perm"]:
|
||||
perm = parameters["perm"]
|
||||
input_tensors = [input_tensor]
|
||||
else:
|
||||
shape = [len(parameters["perm"]), 2]
|
||||
perm = tf.placeholder(dtype=tf.int32, name="perm", shape=shape)
|
||||
input_tensors = [input_tensor, perm]
|
||||
|
||||
out = tf.transpose(input_tensor, perm=perm)
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = [
|
||||
create_tensor_data(parameters["dtype"], parameters["input_shape"])
|
||||
]
|
||||
if not parameters["constant_perm"]:
|
||||
values.append(np.array(parameters["perm"]))
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
expected_tf_failures=9)
|
87
tensorflow/lite/testing/op_tests/transpose_conv.py
Normal file
87
tensorflow/lite/testing/op_tests/transpose_conv.py
Normal file
@ -0,0 +1,87 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for transpose_conv."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
# Since compute output_shape is fairly complicated for
|
||||
# tf.nn.conv2d_transpose input_sizes argument, so we here first perform a
|
||||
# "conv2d" operation to get the output, then we use the output to feed in
|
||||
# tf.nn.conv2d_backprop_input.
|
||||
# This test will depend on the "conv2d" operation's correctness.
|
||||
@register_make_test_function()
|
||||
def make_transpose_conv_tests(options):
|
||||
"""Make a set of tests to do transpose_conv."""
|
||||
|
||||
# Tensorflow only supports equal strides
|
||||
test_parameters = [{
|
||||
"input_shape": [[1, 3, 4, 1], [1, 10, 10, 3], [3, 20, 20, 1]],
|
||||
"filter_size": [[1, 1], [1, 2], [3, 3]],
|
||||
"strides": [[1, 1, 1, 1], [1, 3, 3, 1]],
|
||||
"padding": ["SAME", "VALID"],
|
||||
"data_format": ["NHWC"],
|
||||
"channel_multiplier": [1, 2],
|
||||
}]
|
||||
|
||||
def get_tensor_shapes(parameters):
|
||||
input_shape = parameters["input_shape"]
|
||||
filter_size = parameters["filter_size"]
|
||||
filter_shape = filter_size + [
|
||||
input_shape[3], parameters["channel_multiplier"]
|
||||
]
|
||||
return [input_shape, filter_shape]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build a transpose_conv graph given `parameters`."""
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name="input", shape=input_shape)
|
||||
|
||||
filter_input = tf.placeholder(
|
||||
dtype=tf.float32, name="filter", shape=filter_shape)
|
||||
|
||||
conv_outputs = tf.nn.conv2d(
|
||||
input_tensor,
|
||||
filter_input,
|
||||
strides=parameters["strides"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
out = tf.nn.conv2d_backprop_input(
|
||||
input_shape,
|
||||
filter_input,
|
||||
conv_outputs,
|
||||
strides=parameters["strides"],
|
||||
padding=parameters["padding"],
|
||||
data_format=parameters["data_format"])
|
||||
input_tensors = [input_tensor, filter_input]
|
||||
return input_tensors, [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_shape, filter_shape = get_tensor_shapes(parameters)
|
||||
values = [
|
||||
create_tensor_data(np.float32, input_shape),
|
||||
create_tensor_data(np.float32, filter_shape)
|
||||
]
|
||||
return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
67
tensorflow/lite/testing/op_tests/unfused_gru.py
Normal file
67
tensorflow/lite/testing/op_tests/unfused_gru.py
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unfused_gru."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_unfused_gru_tests(options):
|
||||
"""Make a set of tests for unfused gru op."""
|
||||
|
||||
test_parameters = [{
|
||||
"units": [2, 5],
|
||||
"batch_size": [1, 2],
|
||||
"time": [3],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for unfused_gru."""
|
||||
inputs = [
|
||||
tf.placeholder(tf.float32,
|
||||
[parameters["batch_size"], parameters["units"]])
|
||||
for _ in range(parameters["time"])
|
||||
]
|
||||
cell_fw = tf.nn.rnn_cell.GRUCell(parameters["units"])
|
||||
cell_bw = tf.nn.rnn_cell.GRUCell(parameters["units"])
|
||||
outputs, _, _ = tf.nn.static_bidirectional_rnn(
|
||||
cell_fw, cell_bw, inputs, dtype=tf.float32)
|
||||
|
||||
return inputs, outputs
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for unfused_gru."""
|
||||
input_values = [
|
||||
create_tensor_data(tf.float32,
|
||||
[parameters["batch_size"], parameters["units"]])
|
||||
for _ in range(parameters["time"])
|
||||
]
|
||||
init = tf.global_variables_initializer()
|
||||
sess.run(init)
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
use_frozen_graph=True)
|
103
tensorflow/lite/testing/op_tests/unidirectional_sequence_lstm.py
Normal file
103
tensorflow/lite/testing/op_tests/unidirectional_sequence_lstm.py
Normal file
@ -0,0 +1,103 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unidirectional_sequence_lstm."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.python.framework import test_util
|
||||
|
||||
|
||||
@register_make_test_function("make_unidirectional_sequence_lstm_tests")
|
||||
@test_util.enable_control_flow_v2
|
||||
def make_unidirectional_sequence_lstm_tests(options):
|
||||
"""Make a set of tests to do unidirectional_sequence_lstm."""
|
||||
|
||||
test_parameters = [{
|
||||
"batch_size": [2, 4, 6],
|
||||
"seq_length": [1, 3],
|
||||
"units": [4, 5],
|
||||
"use_peepholes": [False, True],
|
||||
"is_dynamic_rnn": [False, True]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for unidirectional_sequence_lstm."""
|
||||
input_values = []
|
||||
if parameters["is_dynamic_rnn"]:
|
||||
shape = [
|
||||
parameters["seq_length"], parameters["batch_size"],
|
||||
parameters["units"]
|
||||
]
|
||||
input_value = tf.placeholder(dtype=tf.float32, name="input", shape=shape)
|
||||
input_values.append(input_value)
|
||||
lstm_cell = tf.lite.experimental.nn.TFLiteLSTMCell(
|
||||
parameters["units"], use_peepholes=parameters["use_peepholes"])
|
||||
outs, _ = tf.lite.experimental.nn.dynamic_rnn(
|
||||
lstm_cell, input_value, dtype=tf.float32, time_major=True)
|
||||
outs = tf.unstack(outs, axis=1)
|
||||
else:
|
||||
shape = [parameters["batch_size"], parameters["units"]]
|
||||
for i in range(parameters["seq_length"]):
|
||||
input_value = tf.placeholder(
|
||||
dtype=tf.float32, name=("input_%d" % i), shape=shape)
|
||||
input_values.append(input_value)
|
||||
lstm_cell = tf.lite.experimental.nn.TFLiteLSTMCell(
|
||||
parameters["units"], use_peepholes=parameters["use_peepholes"])
|
||||
outs, _ = tf.nn.static_rnn(lstm_cell, input_values, dtype=tf.float32)
|
||||
|
||||
real_output = tf.zeros([1], dtype=tf.float32) + outs[-1]
|
||||
return input_values, [real_output]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for unidirectional_sequence_lstm."""
|
||||
input_values = []
|
||||
if parameters["is_dynamic_rnn"]:
|
||||
shape = [
|
||||
parameters["seq_length"], parameters["batch_size"],
|
||||
parameters["units"]
|
||||
]
|
||||
input_value = create_tensor_data(tf.float32, shape)
|
||||
input_values.append(input_value)
|
||||
else:
|
||||
shape = [parameters["batch_size"], parameters["units"]]
|
||||
for _ in range(parameters["seq_length"]):
|
||||
input_value = create_tensor_data(tf.float32, shape)
|
||||
input_values.append(input_value)
|
||||
init = tf.global_variables_initializer()
|
||||
sess.run(init)
|
||||
# Tflite fused kernel takes input as [time, batch, input].
|
||||
# For static unidirectional sequence lstm, the input is an array sized of
|
||||
# time, and pack the array together, however, for time = 1, the input is
|
||||
# not packed.
|
||||
tflite_input_values = input_values
|
||||
if not parameters["is_dynamic_rnn"] and parameters["seq_length"] == 1:
|
||||
tflite_input_values = [
|
||||
input_values[0].reshape(
|
||||
(1, parameters["batch_size"], parameters["units"]))
|
||||
]
|
||||
return tflite_input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
use_frozen_graph=True)
|
100
tensorflow/lite/testing/op_tests/unidirectional_sequence_rnn.py
Normal file
100
tensorflow/lite/testing/op_tests/unidirectional_sequence_rnn.py
Normal file
@ -0,0 +1,100 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unidirectional_sequence_rnn."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
from tensorflow.python.framework import test_util
|
||||
|
||||
|
||||
@register_make_test_function("make_unidirectional_sequence_rnn_tests")
|
||||
@test_util.enable_control_flow_v2
|
||||
def make_unidirectional_sequence_rnn_tests(options):
|
||||
"""Make a set of tests to do unidirectional_sequence_rnn."""
|
||||
|
||||
test_parameters = [{
|
||||
"batch_size": [2, 4, 6],
|
||||
"seq_length": [1, 3],
|
||||
"units": [4, 5],
|
||||
"is_dynamic_rnn": [False, True]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for unidirectional_sequence_rnn."""
|
||||
input_values = []
|
||||
if parameters["is_dynamic_rnn"]:
|
||||
shape = [
|
||||
parameters["seq_length"], parameters["batch_size"],
|
||||
parameters["units"]
|
||||
]
|
||||
input_value = tf.placeholder(dtype=tf.float32, name="input", shape=shape)
|
||||
input_values.append(input_value)
|
||||
rnn_cell = tf.lite.experimental.nn.TfLiteRNNCell(parameters["units"])
|
||||
outs, _ = tf.lite.experimental.nn.dynamic_rnn(
|
||||
rnn_cell, input_value, dtype=tf.float32, time_major=True)
|
||||
outs = tf.unstack(outs, axis=1)
|
||||
else:
|
||||
shape = [parameters["batch_size"], parameters["units"]]
|
||||
for i in range(parameters["seq_length"]):
|
||||
input_value = tf.placeholder(
|
||||
dtype=tf.float32, name=("input_%d" % i), shape=shape)
|
||||
input_values.append(input_value)
|
||||
rnn_cell = tf.lite.experimental.nn.TfLiteRNNCell(parameters["units"])
|
||||
outs, _ = tf.nn.static_rnn(rnn_cell, input_values, dtype=tf.float32)
|
||||
|
||||
real_output = tf.zeros([1], dtype=tf.float32) + outs[-1]
|
||||
return input_values, [real_output]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
"""Build the inputs for unidirectional_sequence_rnn."""
|
||||
input_values = []
|
||||
if parameters["is_dynamic_rnn"]:
|
||||
shape = [
|
||||
parameters["seq_length"], parameters["batch_size"],
|
||||
parameters["units"]
|
||||
]
|
||||
input_value = create_tensor_data(tf.float32, shape)
|
||||
input_values.append(input_value)
|
||||
else:
|
||||
shape = [parameters["batch_size"], parameters["units"]]
|
||||
for _ in range(parameters["seq_length"]):
|
||||
input_value = create_tensor_data(tf.float32, shape)
|
||||
input_values.append(input_value)
|
||||
init = tf.global_variables_initializer()
|
||||
sess.run(init)
|
||||
# Tflite fused kernel takes input as [time, batch, input].
|
||||
# For static unidirectional sequence rnn, the input is an array sized of
|
||||
# time, and pack the array together, however, for time = 1, the input is
|
||||
# not packed.
|
||||
tflite_input_values = input_values
|
||||
if not parameters["is_dynamic_rnn"] and parameters["seq_length"] == 1:
|
||||
tflite_input_values = [
|
||||
input_values[0].reshape(
|
||||
(1, parameters["batch_size"], parameters["units"]))
|
||||
]
|
||||
return tflite_input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(
|
||||
options,
|
||||
test_parameters,
|
||||
build_graph,
|
||||
build_inputs,
|
||||
use_frozen_graph=True)
|
65
tensorflow/lite/testing/op_tests/unique.py
Normal file
65
tensorflow/lite/testing/op_tests/unique.py
Normal file
@ -0,0 +1,65 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unique."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_unique_tests(options):
|
||||
"""Make a set of tests for Unique op."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_shape": [[1]],
|
||||
"index_type": [tf.int32, tf.int64, None],
|
||||
"input_values": [3]
|
||||
}, {
|
||||
"input_shape": [[5]],
|
||||
"index_type": [tf.int32, tf.int64],
|
||||
"input_values": [[3, 2, 1, 2, 3]]
|
||||
}, {
|
||||
"input_shape": [[7]],
|
||||
"index_type": [tf.int32, tf.int64],
|
||||
"input_values": [[1, 1, 1, 1, 1, 1, 1]]
|
||||
}, {
|
||||
"input_shape": [[5]],
|
||||
"index_type": [tf.int32, tf.int64],
|
||||
"input_values": [[3, 2, 1, 0, -1]]
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the graph for the test case."""
|
||||
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.int32, name="input", shape=parameters["input_shape"])
|
||||
if parameters["index_type"] is None:
|
||||
output = tf.unique(input_tensor)
|
||||
else:
|
||||
output = tf.unique(input_tensor, parameters["index_type"])
|
||||
|
||||
return [input_tensor], output
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_values = [create_tensor_data(tf.int32, parameters["input_shape"])]
|
||||
return input_values, sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, input_values)))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
55
tensorflow/lite/testing/op_tests/unpack.py
Normal file
55
tensorflow/lite/testing/op_tests/unpack.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unpack."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_unpack_tests(options):
|
||||
"""Make a set of tests to do unpack."""
|
||||
|
||||
test_parameters = [{
|
||||
"base_shape": [[3, 4, 3], [3, 4], [5, 6, 7, 8]],
|
||||
"axis": [0, 1, 2, 3],
|
||||
}]
|
||||
|
||||
def get_valid_axis(parameters):
|
||||
"""Return a tweaked version of 'axis'."""
|
||||
axis = parameters["axis"]
|
||||
shape = parameters["base_shape"][:]
|
||||
while axis > len(shape) - 1:
|
||||
axis -= 1
|
||||
return axis
|
||||
|
||||
def build_graph(parameters):
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=tf.float32, name=("input"), shape=parameters["base_shape"])
|
||||
outs = tf.unstack(input_tensor, axis=get_valid_axis(parameters))
|
||||
return [input_tensor], [outs[0]]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value = create_tensor_data(np.float32, shape=parameters["base_shape"])
|
||||
return [input_value], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
93
tensorflow/lite/testing/op_tests/unroll_batch_matmul.py
Normal file
93
tensorflow/lite/testing/op_tests/unroll_batch_matmul.py
Normal file
@ -0,0 +1,93 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for unroll_batch_matmul."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_unroll_batch_matmul_tests(options):
|
||||
"""Make a set of tests to test unroll_batch_matmul."""
|
||||
|
||||
# The test cases below requires broadcasting support (BatchMatMulV2 semantic),
|
||||
# whis isn't supported as of this change.
|
||||
broadcast_shape_params = [
|
||||
# Simple broadcast.
|
||||
[(1, 2, 3), (3, 5), False, False],
|
||||
# Empty batch broadcast.
|
||||
[(2, 5, 3), (3, 7), False, False],
|
||||
# Single batch with non-empty batch broadcast.
|
||||
[(1, 5, 3), (4, 3, 7), False, False],
|
||||
# Broadcast both operands
|
||||
[(3, 1, 5, 3), (1, 4, 3, 7), False, False],
|
||||
]
|
||||
|
||||
test_parameters = [{
|
||||
"dtype": [tf.float32],
|
||||
"shape": [[(2, 2, 3),
|
||||
(2, 3, 2), False, False], [(2, 2, 3), (2, 3, 2), True, True],
|
||||
[(2, 2, 3),
|
||||
(2, 2, 3), False, True], [(2, 2, 3), (2, 2, 3), True, False],
|
||||
[(4, 2, 2, 3), (4, 2, 3, 2), False, False],
|
||||
[(4, 2, 2, 3), (4, 2, 3, 2), True, True],
|
||||
[(4, 2, 2, 3), (4, 2, 2, 3), False, True],
|
||||
[(4, 2, 2, 3),
|
||||
(4, 2, 2, 3), True, False]] + broadcast_shape_params,
|
||||
# TODO(b/130887442): Improve the forward compatibility tests for every
|
||||
# ops.
|
||||
"forward_compatibility_test": [False, True],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the batch_matmul op testing graph."""
|
||||
|
||||
def _build_graph():
|
||||
"""Build the graph."""
|
||||
input_tensor1 = tf.placeholder(
|
||||
dtype=parameters["dtype"], shape=parameters["shape"][0])
|
||||
input_tensor2 = tf.placeholder(
|
||||
dtype=parameters["dtype"], shape=parameters["shape"][1])
|
||||
# Should be unrolled and replaced with fully_connected ops in the end.
|
||||
out = tf.matmul(
|
||||
input_tensor1,
|
||||
input_tensor2,
|
||||
transpose_a=parameters["shape"][2],
|
||||
transpose_b=parameters["shape"][3])
|
||||
return [input_tensor1, input_tensor2], [out]
|
||||
|
||||
if parameters["forward_compatibility_test"]:
|
||||
# This is hardcoded to the date after MatMulV2 is activated.
|
||||
# TODO(b/130887442): Improve the forward compatibility tests for every
|
||||
# ops, and remove the hardcoded date.
|
||||
with tf.compat.forward_compatibility_horizon(2019, 4, 26):
|
||||
return _build_graph()
|
||||
else:
|
||||
return _build_graph()
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(
|
||||
parameters["dtype"], shape=parameters["shape"][0])
|
||||
input_value2 = create_tensor_data(
|
||||
parameters["dtype"], shape=parameters["shape"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
66
tensorflow/lite/testing/op_tests/where.py
Normal file
66
tensorflow/lite/testing/op_tests/where.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for where."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_where_tests(options):
|
||||
"""Make a set of tests to do where."""
|
||||
|
||||
test_parameters = [
|
||||
{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape_set": [([1, 2, 3, 4], [1, 2, 3, 4]),],
|
||||
"use_where_v2": [False, True],
|
||||
},
|
||||
{
|
||||
"input_dtype": [tf.float32, tf.int32],
|
||||
"input_shape_set": [([1, 2, 3, 4], [1, 2, 3, 1]),],
|
||||
"use_where_v2": [True],
|
||||
},
|
||||
]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the where op testing graph."""
|
||||
input_value1 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input2",
|
||||
shape=parameters["input_shape_set"][0])
|
||||
input_value2 = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input3",
|
||||
shape=parameters["input_shape_set"][1])
|
||||
less = tf.less(input_value1, input_value2)
|
||||
where = tf.where_v2 if parameters["use_where_v2"] else tf.where
|
||||
out = where(less, input_value1, input_value2)
|
||||
return [input_value1, input_value2], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
input_value1 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_set"][0])
|
||||
input_value2 = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape_set"][1])
|
||||
return [input_value1, input_value2], sess.run(
|
||||
outputs, feed_dict=dict(zip(inputs, [input_value1, input_value2])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
56
tensorflow/lite/testing/op_tests/zeros_like.py
Normal file
56
tensorflow/lite/testing/op_tests/zeros_like.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Test configs for zeros_like."""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import tensorflow as tf
|
||||
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
|
||||
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
|
||||
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
|
||||
|
||||
|
||||
@register_make_test_function()
|
||||
def make_zeros_like_tests(options):
|
||||
"""Make a set of tests to do zeros_like."""
|
||||
|
||||
test_parameters = [{
|
||||
"input_dtype": [tf.float32, tf.int32, tf.int64],
|
||||
"input_shape": [[], [1], [1, 2], [5, 6, 7, 8], [3, 4, 5, 6]],
|
||||
}]
|
||||
|
||||
def build_graph(parameters):
|
||||
"""Build the zeros_like op testing graph."""
|
||||
input_tensor = tf.placeholder(
|
||||
dtype=parameters["input_dtype"],
|
||||
name="input",
|
||||
shape=parameters["input_shape"])
|
||||
zeros = tf.zeros_like(input_tensor)
|
||||
# This maximum node is so that toco can perform the constants-propagation
|
||||
# through the above zeros_like, which it can't do if the output of the
|
||||
# zeros_like as an output of the whole graphs (graph outputs can't be
|
||||
# constants). If toco does not perform such constants-propagation then
|
||||
# the resulting tflite graph retains the zeros_like as a Fill op, which
|
||||
# is unsupported by TFLite, even as a custom op.
|
||||
out = tf.maximum(zeros, input_tensor)
|
||||
return [input_tensor], [out]
|
||||
|
||||
def build_inputs(parameters, sess, inputs, outputs):
|
||||
values = create_tensor_data(parameters["input_dtype"],
|
||||
parameters["input_shape"])
|
||||
return [values], sess.run(outputs, feed_dict=dict(zip(inputs, [values])))
|
||||
|
||||
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user