aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/testing/generate_examples.py
diff options
context:
space:
mode:
authorGravatar Jared Duke <jdduke@google.com>2018-07-26 10:53:21 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-26 10:56:43 -0700
commit6e658c0a5ca77677a954a34fb98f241c592c970d (patch)
treeb645103887539af5232b3f70d80a2eb9b77ed63a /tensorflow/contrib/lite/testing/generate_examples.py
parent0a3155f7fbf56df5e81c7cbf35afd45173359635 (diff)
Add one_hot op support to TFLite
PiperOrigin-RevId: 206185190
Diffstat (limited to 'tensorflow/contrib/lite/testing/generate_examples.py')
-rw-r--r--tensorflow/contrib/lite/testing/generate_examples.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/tensorflow/contrib/lite/testing/generate_examples.py b/tensorflow/contrib/lite/testing/generate_examples.py
index 41ece94237..3c7ad9d8b3 100644
--- a/tensorflow/contrib/lite/testing/generate_examples.py
+++ b/tensorflow/contrib/lite/testing/generate_examples.py
@@ -242,7 +242,9 @@ def create_tensor_data(dtype, shape, min_value=-100, max_value=100):
value = (max_value-min_value)*np.random.random_sample(shape)+min_value
elif dtype in (tf.int32, tf.uint8, tf.int64):
value = np.random.randint(min_value, max_value+1, shape)
- return value.astype(dtype)
+
+ return np.dtype(dtype).type(value) if np.isscalar(value) else value.astype(
+ dtype)
def create_scalar_data(dtype, min_value=-100, max_value=100):
@@ -1665,6 +1667,65 @@ def make_shape_tests(zip_path):
make_zip_of_tests(zip_path, test_parameters, build_graph, build_inputs)
+def make_one_hot_tests(zip_path):
+ """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):
+ 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):
+ 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(zip_path, test_parameters, build_graph, build_inputs)
+
+
def make_resize_bilinear_tests(zip_path):
"""Make a set of tests to do resize_bilinear."""