aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/labeled_tensor
diff options
context:
space:
mode:
authorGravatar Justine Tunney <jart@google.com>2016-12-29 22:46:24 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-12-29 23:06:59 -0800
commite121667dc609de978a223c56ee906368d2c4ceef (patch)
tree7d4e1f1e1b4fd469487872c0cd34ddace5ac570c /tensorflow/contrib/labeled_tensor
parent7815fcba7767aa1eb3196c5861e174f8b3c43bab (diff)
Remove so many more hourglass imports
Change: 143230429
Diffstat (limited to 'tensorflow/contrib/labeled_tensor')
-rw-r--r--tensorflow/contrib/labeled_tensor/BUILD32
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/core_test.py279
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/io_ops_test.py72
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/nn_test.py26
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/ops_test.py277
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/sugar_test.py43
-rw-r--r--tensorflow/contrib/labeled_tensor/python/ops/test_util.py11
7 files changed, 414 insertions, 326 deletions
diff --git a/tensorflow/contrib/labeled_tensor/BUILD b/tensorflow/contrib/labeled_tensor/BUILD
index 709ab0e4aa..f8efe0fb8d 100644
--- a/tensorflow/contrib/labeled_tensor/BUILD
+++ b/tensorflow/contrib/labeled_tensor/BUILD
@@ -36,6 +36,7 @@ py_library(
"//tensorflow/python:array_ops",
"//tensorflow/python:framework_for_generated_wrappers",
"//tensorflow/python:math_ops",
+ "//third_party/py/numpy",
],
)
@@ -46,7 +47,8 @@ py_library(
deps = [
":_typecheck",
":core",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:training",
],
)
@@ -61,7 +63,11 @@ py_test(
":_typecheck",
":core",
":test_util",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:math_ops",
+ "//third_party/py/numpy",
],
)
@@ -90,7 +96,11 @@ py_test(
":io_ops",
":ops",
":test_util",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/core:protos_all_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
],
)
@@ -115,7 +125,8 @@ py_test(
":core",
":nn",
":test_util",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:nn",
+ "//tensorflow/python:nn_ops",
],
)
@@ -132,6 +143,7 @@ py_library(
"//tensorflow/python:numerics",
"//tensorflow/python:random_ops",
"//tensorflow/python:training",
+ "//third_party/py/numpy",
],
)
@@ -146,7 +158,12 @@ py_test(
":core",
":ops",
":test_util",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:errors",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:math_ops",
+ "//third_party/py/numpy",
],
)
@@ -174,7 +191,10 @@ py_test(
":ops",
":sugar",
":test_util",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:math_ops",
],
)
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/core_test.py b/tensorflow/contrib/labeled_tensor/python/ops/core_test.py
index f01955d507..19cc85cb41 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/core_test.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/core_test.py
@@ -23,17 +23,23 @@ import textwrap
import numpy as np
from six.moves import range # pylint: disable=redefined-builtin
-import tensorflow as tf
from tensorflow.contrib.labeled_tensor.python.ops import _typecheck as tc
from tensorflow.contrib.labeled_tensor.python.ops import core
from tensorflow.contrib.labeled_tensor.python.ops import test_util
+from tensorflow.python.framework import constant_op
+from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import ops
+from tensorflow.python.framework import tensor_shape
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import math_ops
+from tensorflow.python.platform import test as test_lib
-class AxisTest(tf.test.TestCase):
+class AxisTest(test_lib.TestCase):
def setUp(self):
- d_7 = tf.Dimension(7)
+ d_7 = tensor_shape.Dimension(7)
p_rgb = ['red', 'green', 'blue']
self.i_7 = core.Axis('7', d_7)
@@ -53,7 +59,7 @@ class AxisTest(tf.test.TestCase):
self.assertNotEqual(axis_0, axis_1)
def test_axis_value(self):
- self.assertEqual(self.i_7.value, tf.Dimension(7))
+ self.assertEqual(self.i_7.value, tensor_shape.Dimension(7))
self.assertTrue(self.i_range.value == tuple(range(7)))
def test_axis_input(self):
@@ -113,11 +119,11 @@ class AxisTest(tf.test.TestCase):
self.assertEqual(self.i_7, core.as_axis(self.i_7))
-class AxesTest(tf.test.TestCase):
+class AxesTest(test_lib.TestCase):
def setUp(self):
- d_7 = tf.Dimension(7)
- d_8 = tf.Dimension(8)
+ d_7 = tensor_shape.Dimension(7)
+ d_8 = tensor_shape.Dimension(8)
p_rgb = ['red', 'green', 'blue']
p_range = range(7)
@@ -155,11 +161,11 @@ class AxesTest(tf.test.TestCase):
class LabeledTensorTest(test_util.Base):
def setUp(self):
- tensor = tf.ones([7, 3, 8, 1])
+ tensor = array_ops.ones([7, 3, 8, 1])
a0 = ('x', range(7))
a1 = ('channel', ['red', 'green', 'blue'])
a2 = ('y', 8)
- a3 = ('z', tf.Dimension(1))
+ a3 = ('z', tensor_shape.Dimension(1))
self.lt = core.LabeledTensor(tensor, [a0, a1, a2, a3])
@@ -216,7 +222,7 @@ class LabeledTensorTest(test_util.Base):
self.lt[:, :, :, :, 0] # pylint: disable=pointless-statement
def test_unknown_size(self):
- tensor = tf.placeholder(tf.string, [None])
+ tensor = array_ops.placeholder(dtypes.string, [None])
actual = core.LabeledTensor(tensor, ['x'])
self.assertIsNone(actual.axes['x'].size)
self.assertIs(actual.axes['x'].value, tensor.get_shape()[0])
@@ -243,7 +249,7 @@ class LabeledTensorTest(test_util.Base):
def test_convert_to_tensor(self):
expected = self.lt.tensor
- actual = tf.convert_to_tensor(self.lt)
+ actual = ops.convert_to_tensor(self.lt)
self.assertIs(expected, actual)
@@ -255,10 +261,10 @@ class Base(test_util.Base):
self.z_size = 4
self.probs_size = 11
- tensor = tf.range(0, self.x_size * self.channel_size * self.z_size *
- self.probs_size)
- tensor = tf.reshape(tensor, [self.x_size, self.channel_size, self.z_size,
- self.probs_size])
+ tensor = math_ops.range(0, self.x_size * self.channel_size * self.z_size *
+ self.probs_size)
+ tensor = array_ops.reshape(
+ tensor, [self.x_size, self.channel_size, self.z_size, self.probs_size])
a0 = ('x', range(self.x_size))
a1 = ('channel', ['red', 'green', 'blue'])
a2 = 'z'
@@ -271,10 +277,12 @@ class Base(test_util.Base):
self.a3 = a3
self.original_lt = core.LabeledTensor(tensor, [a0, a1, a2, a3])
- self.x_probs_lt = core.slice_function(self.original_lt, {'z': 0,
- 'channel': 0})
- self.channel_probs_lt = core.slice_function(self.original_lt, {'x': 3,
- 'z': 0})
+ self.x_probs_lt = core.slice_function(self.original_lt,
+ {'z': 0,
+ 'channel': 0})
+ self.channel_probs_lt = core.slice_function(self.original_lt,
+ {'x': 3,
+ 'z': 0})
class IdentityTest(Base):
@@ -292,8 +300,8 @@ class SliceFunctionTest(Base):
def test_scalar(self):
select_lt = core.slice_function(self.original_lt, {'channel': 1})
- golden_lt = core.LabeledTensor(self.tensor[:, 1, :, :], [self.a0, self.a2,
- self.a3])
+ golden_lt = core.LabeledTensor(self.tensor[:, 1, :, :],
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(select_lt, golden_lt)
@@ -307,9 +315,9 @@ class SliceFunctionTest(Base):
self.assertLabeledTensorsEqual(select_lt, golden_lt)
def test_slices(self):
- select_lt = core.slice_function(self.original_lt, {'x': slice(1, 5),
- 'channel': slice(1,
- None)})
+ select_lt = core.slice_function(
+ self.original_lt, {'x': slice(1, 5),
+ 'channel': slice(1, None)})
a0_sliced = ('x', range(1, 5))
a1_sliced = ('channel', ['green', 'blue'])
@@ -328,7 +336,8 @@ class SliceFunctionTest(Base):
self.assertLabeledTensorsEqual(select_lt, golden_lt)
def test_slice_unknown_shape(self):
- lt = core.LabeledTensor(tf.placeholder(tf.float32, [None, 1]), ['x', 'y'])
+ lt = core.LabeledTensor(
+ array_ops.placeholder(dtypes.float32, [None, 1]), ['x', 'y'])
sliced_lt = core.slice_function(lt, {'y': 0})
self.assertEqual(list(sliced_lt.axes.values()), [lt.axes['x']])
@@ -348,10 +357,10 @@ class TransposeTest(Base):
self.assertLabeledTensorsEqual(transpose_lt, golden_lt)
def test(self):
- transpose_lt = core.transpose(self.original_lt, ['z', 'channel', 'x',
- 'probs'])
+ transpose_lt = core.transpose(self.original_lt,
+ ['z', 'channel', 'x', 'probs'])
golden_lt = core.LabeledTensor(
- tf.transpose(self.tensor, [2, 1, 0, 3]),
+ array_ops.transpose(self.tensor, [2, 1, 0, 3]),
[self.a2, self.a1, self.a0, self.a3])
self.assertLabeledTensorsEqual(transpose_lt, golden_lt)
@@ -359,7 +368,7 @@ class TransposeTest(Base):
def test_default_axis_order(self):
transpose_lt = core.transpose(self.original_lt)
golden_lt = core.LabeledTensor(
- tf.transpose(self.tensor, [3, 2, 1, 0]),
+ array_ops.transpose(self.tensor, [3, 2, 1, 0]),
list(reversed(list(self.original_lt.axes.values()))))
self.assertLabeledTensorsEqual(transpose_lt, golden_lt)
@@ -384,41 +393,45 @@ class ExpandDimsTest(Base):
self.assertLabeledTensorsEqual(expand_lt, golden_lt)
def test(self):
- expand_lt = core.expand_dims(self.original_lt, ['foo', 'x', 'bar',
- 'channel', 'z', 'probs',
- 'grok'])
+ expand_lt = core.expand_dims(
+ self.original_lt, ['foo', 'x', 'bar', 'channel', 'z', 'probs', 'grok'])
golden_lt = core.LabeledTensor(
- tf.reshape(self.tensor, [1, self.x_size, 1, self.channel_size,
- self.z_size, self.probs_size, 1]),
- ['foo', self.a0, 'bar', self.a1, self.a2, self.a3, 'grok'])
+ array_ops.reshape(self.tensor, [
+ 1, self.x_size, 1, self.channel_size, self.z_size, self.probs_size,
+ 1
+ ]), ['foo', self.a0, 'bar', self.a1, self.a2, self.a3, 'grok'])
self.assertLabeledTensorsEqual(expand_lt, golden_lt)
def test_label(self):
- expand_lt = core.expand_dims(self.original_lt, ['x',
- 'channel',
- ('foo', 'bar'),
- 'z',
- 'probs',])
+ expand_lt = core.expand_dims(self.original_lt, [
+ 'x',
+ 'channel',
+ ('foo', 'bar'),
+ 'z',
+ 'probs',
+ ])
golden_lt = core.LabeledTensor(
- tf.reshape(self.tensor, [self.x_size, self.channel_size, 1, self.z_size,
- self.probs_size]),
+ array_ops.reshape(
+ self.tensor,
+ [self.x_size, self.channel_size, 1, self.z_size, self.probs_size]),
[self.a0, self.a1, ('foo', ['bar']), self.a2, self.a3])
self.assertLabeledTensorsEqual(expand_lt, golden_lt)
def test_unknown_dimension(self):
- orig_lt = core.LabeledTensor(tf.placeholder(tf.float32, [None]), ['x'])
+ orig_lt = core.LabeledTensor(
+ array_ops.placeholder(dtypes.float32, [None]), ['x'])
expand_lt = core.expand_dims(orig_lt, ['x', 'y'])
self.assertEqual(expand_lt.axes, core.Axes([('x', None), ('y', 1)]))
def test_invalid_input(self):
with self.assertRaises(core.AxisOrderError):
- core.expand_dims(self.original_lt, ['foo', 'not_x', 'bar', 'channel', 'z',
- 'probs', 'grok'])
+ core.expand_dims(self.original_lt,
+ ['foo', 'not_x', 'bar', 'channel', 'z', 'probs', 'grok'])
with self.assertRaises(core.AxisOrderError):
- core.expand_dims(self.original_lt, ['foo', 'z', 'bar', 'channel', 'x',
- 'probs', 'grok'])
+ core.expand_dims(self.original_lt,
+ ['foo', 'z', 'bar', 'channel', 'x', 'probs', 'grok'])
class AxisOrderScopeTest(Base):
@@ -450,18 +463,18 @@ class CheckAxisOrderTest(Base):
def test_passes(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.ones((1, 1, 1, 1)), axis_order)
+ lt = core.LabeledTensor(array_ops.ones((1, 1, 1, 1)), axis_order)
core.check_axis_order(lt, axis_order)
- lt = core.LabeledTensor(tf.ones((1, 1, 1)), axis_order[1:])
+ lt = core.LabeledTensor(array_ops.ones((1, 1, 1)), axis_order[1:])
core.check_axis_order(lt, axis_order)
- lt = core.LabeledTensor(tf.ones((1, 1, 1)), axis_order[:-1])
+ lt = core.LabeledTensor(array_ops.ones((1, 1, 1)), axis_order[:-1])
core.check_axis_order(lt, axis_order)
def test_invalid(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.ones((1, 1, 1, 1)), axis_order)
+ lt = core.LabeledTensor(array_ops.ones((1, 1, 1, 1)), axis_order)
with self.assertRaises(core.AxisOrderError):
core.check_axis_order(lt)
with self.assertRaises(core.AxisOrderError):
@@ -471,7 +484,7 @@ class CheckAxisOrderTest(Base):
def test_scope(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.ones((1, 1, 1, 1)), axis_order)
+ lt = core.LabeledTensor(array_ops.ones((1, 1, 1, 1)), axis_order)
with core.axis_order_scope(axis_order):
core.check_axis_order(lt)
@@ -480,23 +493,27 @@ class ImposeAxisOrderTest(Base):
def test_identity(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.reshape(tf.range(24), (1, 2, 3, 4)), axis_order)
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(24), (1, 2, 3, 4)), axis_order)
actual = core.impose_axis_order(lt, axis_order)
self.assertLabeledTensorsEqual(lt, actual)
- lt = core.LabeledTensor(tf.reshape(tf.range(6), (1, 2, 3)), axis_order[:3])
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(6), (1, 2, 3)), axis_order[:3])
actual = core.impose_axis_order(lt, axis_order)
self.assertLabeledTensorsEqual(lt, actual)
def test_reverse(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.reshape(tf.range(24), (1, 2, 3, 4)), axis_order)
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(24), (1, 2, 3, 4)), axis_order)
actual = core.impose_axis_order(lt, axis_order[::-1])
expected = core.transpose(lt, axis_order[::-1])
self.assertLabeledTensorsEqual(expected, actual)
- lt = core.LabeledTensor(tf.reshape(tf.range(6), (1, 2, 3)), axis_order[:3])
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(6), (1, 2, 3)), axis_order[:3])
actual = core.impose_axis_order(lt, axis_order[::-1])
expected = core.transpose(lt, ['y', 'x', 'w'])
self.assertLabeledTensorsEqual(expected, actual)
@@ -504,14 +521,16 @@ class ImposeAxisOrderTest(Base):
def test_scope(self):
axis_order = ['w', 'x', 'y', 'z']
- lt = core.LabeledTensor(tf.reshape(tf.range(24), (1, 2, 3, 4)), axis_order)
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(24), (1, 2, 3, 4)), axis_order)
expected = core.transpose(lt, axis_order[::-1])
with core.axis_order_scope(axis_order[::-1]):
actual = core.impose_axis_order(lt)
self.assertLabeledTensorsEqual(expected, actual)
def test_invalid(self):
- lt = core.LabeledTensor(tf.reshape(tf.range(2), (1, 2)), ['x', 'y'])
+ lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(2), (1, 2)), ['x', 'y'])
with self.assertRaises(ValueError):
core.impose_axis_order(lt)
with self.assertRaises(ValueError):
@@ -571,14 +590,15 @@ class AlignTest(Base):
self.x_probs_lt, self.channel_probs_lt)
x_probs_golden_lt = core.LabeledTensor(
- tf.reshape(self.x_probs_lt.tensor, [self.x_size, 1, self.probs_size]),
+ array_ops.reshape(self.x_probs_lt.tensor,
+ [self.x_size, 1, self.probs_size]),
[self.a0, 'channel', self.a3])
self.assertLabeledTensorsEqual(align_x_probs_lt, x_probs_golden_lt)
channel_probs_golden_lt = core.LabeledTensor(
- tf.reshape(self.channel_probs_lt.tensor,
- [1, self.channel_size, self.probs_size]),
+ array_ops.reshape(self.channel_probs_lt.tensor,
+ [1, self.channel_size, self.probs_size]),
['x', self.a1, self.a3])
self.assertLabeledTensorsEqual(align_channel_probs_lt,
@@ -587,8 +607,8 @@ class AlignTest(Base):
self.assertEqual(broadcast_axes, core.Axes([self.a0, self.a1, self.a3]))
def test_axis_order_scope(self):
- xz_lt = core.LabeledTensor(tf.ones((2, 3)), ['x', 'z'])
- yz_lt = core.LabeledTensor(tf.ones((4, 3)), ['y', 'z'])
+ xz_lt = core.LabeledTensor(array_ops.ones((2, 3)), ['x', 'z'])
+ yz_lt = core.LabeledTensor(array_ops.ones((4, 3)), ['y', 'z'])
_, _, broadcast_axes = core.align(xz_lt, yz_lt)
self.assertEqual(list(broadcast_axes.keys()), ['x', 'y', 'z'])
@@ -607,8 +627,8 @@ class AlignTest(Base):
core.align(yz_lt, xz_lt)
def test_invalid_input(self):
- lt_0 = core.LabeledTensor(tf.zeros([5]), [('a', range(5))])
- lt_1 = core.LabeledTensor(tf.zeros([5]), [('a', range(1, 6))])
+ lt_0 = core.LabeledTensor(array_ops.zeros([5]), [('a', range(5))])
+ lt_1 = core.LabeledTensor(array_ops.zeros([5]), [('a', range(1, 6))])
with self.assertRaises(ValueError):
core.align(lt_0, lt_1)
@@ -624,22 +644,22 @@ class ConvertToLabeledTensorTest(Base):
def test_python_scalar(self):
actual = core.convert_to_labeled_tensor(42)
- golden_lt = core.LabeledTensor(tf.convert_to_tensor(42), [])
+ golden_lt = core.LabeledTensor(ops.convert_to_tensor(42), [])
self.assertLabeledTensorsEqual(actual, golden_lt)
def test_numpy_array(self):
actual = core.convert_to_labeled_tensor(np.array(42))
- golden_lt = core.LabeledTensor(tf.convert_to_tensor(42), [])
+ golden_lt = core.LabeledTensor(ops.convert_to_tensor(42), [])
self.assertLabeledTensorsEqual(actual, golden_lt)
def test_tensor(self):
- actual = core.convert_to_labeled_tensor(tf.constant(42))
- golden_lt = core.LabeledTensor(tf.convert_to_tensor(42), [])
+ actual = core.convert_to_labeled_tensor(constant_op.constant(42))
+ golden_lt = core.LabeledTensor(ops.convert_to_tensor(42), [])
self.assertLabeledTensorsEqual(actual, golden_lt)
def test_invalid_input(self):
with self.assertRaises(ValueError):
- core.convert_to_labeled_tensor(tf.range(5))
+ core.convert_to_labeled_tensor(math_ops.range(5))
with self.assertRaises(ValueError):
core.convert_to_labeled_tensor(np.array([1, 2]))
@@ -660,8 +680,8 @@ class UnaryOpsTestsMixin(object):
def test_core_op(self):
for op_name, _, tf_op, lt_op in self.ops:
if tf_op is not None:
- golden_lt = core.LabeledTensor(tf_op(self.test_lt.tensor),
- self.test_lt.axes)
+ golden_lt = core.LabeledTensor(
+ tf_op(self.test_lt.tensor), self.test_lt.axes)
actual_lt = lt_op(self.test_lt)
self.assertIn(op_name, actual_lt.name)
self.assertLabeledTensorsEqual(golden_lt, actual_lt)
@@ -669,8 +689,8 @@ class UnaryOpsTestsMixin(object):
def test_infix(self):
for op_name, infix_op, _, _ in self.ops:
if infix_op is not None:
- expected_lt = core.LabeledTensor(infix_op(self.test_lt.tensor),
- self.test_lt.axes)
+ expected_lt = core.LabeledTensor(
+ infix_op(self.test_lt.tensor), self.test_lt.axes)
actual_lt = infix_op(self.test_lt)
self.assertIn(op_name, actual_lt.name)
self.assertLabeledTensorsEqual(expected_lt, actual_lt)
@@ -682,36 +702,36 @@ class CoreUnaryOpsTest(Base, DocStringCheckMixin, UnaryOpsTestsMixin):
super(CoreUnaryOpsTest, self).setUp()
self.ops = [
- ('abs', operator.abs, tf.abs, core.abs_function),
- ('neg', operator.neg, tf.neg, core.neg),
+ ('abs', operator.abs, math_ops.abs, core.abs_function),
+ ('neg', operator.neg, math_ops.neg, core.neg),
# TODO(shoyer): add unary + to core TensorFlow
('pos', None, None, None),
- ('sign', None, tf.sign, core.sign),
- ('reciprocal', None, tf.reciprocal, core.reciprocal),
- ('square', None, tf.square, core.square),
- ('round', None, tf.round, core.round_function),
- ('sqrt', None, tf.sqrt, core.sqrt),
- ('rsqrt', None, tf.rsqrt, core.rsqrt),
- ('log', None, tf.log, core.log),
- ('exp', None, tf.exp, core.exp),
- ('log', None, tf.log, core.log),
- ('ceil', None, tf.ceil, core.ceil),
- ('floor', None, tf.floor, core.floor),
- ('cos', None, tf.cos, core.cos),
- ('sin', None, tf.sin, core.sin),
- ('tan', None, tf.tan, core.tan),
- ('acos', None, tf.acos, core.acos),
- ('asin', None, tf.asin, core.asin),
- ('atan', None, tf.atan, core.atan),
- ('lgamma', None, tf.lgamma, core.lgamma),
- ('digamma', None, tf.digamma, core.digamma),
- ('erf', None, tf.erf, core.erf),
- ('erfc', None, tf.erfc, core.erfc),
- ('lgamma', None, tf.lgamma, core.lgamma),
+ ('sign', None, math_ops.sign, core.sign),
+ ('reciprocal', None, math_ops.reciprocal, core.reciprocal),
+ ('square', None, math_ops.square, core.square),
+ ('round', None, math_ops.round, core.round_function),
+ ('sqrt', None, math_ops.sqrt, core.sqrt),
+ ('rsqrt', None, math_ops.rsqrt, core.rsqrt),
+ ('log', None, math_ops.log, core.log),
+ ('exp', None, math_ops.exp, core.exp),
+ ('log', None, math_ops.log, core.log),
+ ('ceil', None, math_ops.ceil, core.ceil),
+ ('floor', None, math_ops.floor, core.floor),
+ ('cos', None, math_ops.cos, core.cos),
+ ('sin', None, math_ops.sin, core.sin),
+ ('tan', None, math_ops.tan, core.tan),
+ ('acos', None, math_ops.acos, core.acos),
+ ('asin', None, math_ops.asin, core.asin),
+ ('atan', None, math_ops.atan, core.atan),
+ ('lgamma', None, math_ops.lgamma, core.lgamma),
+ ('digamma', None, math_ops.digamma, core.digamma),
+ ('erf', None, math_ops.erf, core.erf),
+ ('erfc', None, math_ops.erfc, core.erfc),
+ ('lgamma', None, math_ops.lgamma, core.lgamma),
]
total_size = np.prod([v.size for v in self.original_lt.axes.values()])
self.test_lt = core.LabeledTensor(
- tf.cast(self.original_lt, tf.float32) / total_size,
+ math_ops.cast(self.original_lt, dtypes.float32) / total_size,
self.original_lt.axes)
@@ -719,9 +739,8 @@ class LogicalNotTest(Base, DocStringCheckMixin, UnaryOpsTestsMixin):
def setUp(self):
super(LogicalNotTest, self).setUp()
- self.ops = [
- ('logical_not', operator.invert, tf.logical_not, core.logical_not),
- ]
+ self.ops = [('logical_not', operator.invert, math_ops.logical_not,
+ core.logical_not),]
self.test_lt = self.original_lt < 10
@@ -731,8 +750,7 @@ class BinaryOpsTestsMixin(object):
def test_core_op(self):
for op_name, _, tf_op, lt_op in self.ops:
- golden_tensor = tf_op(self.test_lt_1_broadcast,
- self.test_lt_2_broadcast)
+ golden_tensor = tf_op(self.test_lt_1_broadcast, self.test_lt_2_broadcast)
golden_lt = core.LabeledTensor(golden_tensor, self.broadcast_axes)
actual_lt = lt_op(self.test_lt_1, self.test_lt_2)
self.assertIn(op_name, actual_lt.name)
@@ -752,27 +770,28 @@ class CoreBinaryOpsTest(Base, DocStringCheckMixin, BinaryOpsTestsMixin):
def setUp(self):
super(CoreBinaryOpsTest, self).setUp()
- self.x_probs_broadcast_tensor = tf.reshape(
+ self.x_probs_broadcast_tensor = array_ops.reshape(
self.x_probs_lt.tensor, [self.x_size, 1, self.probs_size])
- self.channel_probs_broadcast_tensor = tf.reshape(
+ self.channel_probs_broadcast_tensor = array_ops.reshape(
self.channel_probs_lt.tensor, [1, self.channel_size, self.probs_size])
# == and != are not element-wise for tf.Tensor, so they shouldn't be
# elementwise for LabeledTensor, either.
self.ops = [
- ('add', operator.add, tf.add, core.add),
- ('sub', operator.sub, tf.sub, core.sub),
- ('mul', operator.mul, tf.mul, core.mul),
- ('div', operator.truediv, tf.div, core.div),
- ('mod', operator.mod, tf.mod, core.mod),
- ('pow', operator.pow, tf.pow, core.pow_function),
- ('equal', None, tf.equal, core.equal),
- ('less', operator.lt, tf.less, core.less),
- ('less_equal', operator.le, tf.less_equal, core.less_equal),
- ('not_equal', None, tf.not_equal, core.not_equal),
- ('greater', operator.gt, tf.greater, core.greater),
- ('greater_equal', operator.ge, tf.greater_equal, core.greater_equal),
+ ('add', operator.add, math_ops.add, core.add),
+ ('sub', operator.sub, math_ops.sub, core.sub),
+ ('mul', operator.mul, math_ops.mul, core.mul),
+ ('div', operator.truediv, math_ops.div, core.div),
+ ('mod', operator.mod, math_ops.mod, core.mod),
+ ('pow', operator.pow, math_ops.pow, core.pow_function),
+ ('equal', None, math_ops.equal, core.equal),
+ ('less', operator.lt, math_ops.less, core.less),
+ ('less_equal', operator.le, math_ops.less_equal, core.less_equal),
+ ('not_equal', None, math_ops.not_equal, core.not_equal),
+ ('greater', operator.gt, math_ops.greater, core.greater),
+ ('greater_equal', operator.ge, math_ops.greater_equal,
+ core.greater_equal),
]
self.test_lt_1 = self.x_probs_lt
self.test_lt_2 = self.channel_probs_lt
@@ -801,9 +820,9 @@ class LogicalBinaryOpsTest(Base, DocStringCheckMixin, BinaryOpsTestsMixin):
super(LogicalBinaryOpsTest, self).setUp()
self.ops = [
- ('logical_and', operator.and_, tf.logical_and, core.logical_and),
- ('logical_or', operator.or_, tf.logical_or, core.logical_or),
- ('logical_xor', operator.xor, tf.logical_xor, core.logical_xor),
+ ('logical_and', operator.and_, math_ops.logical_and, core.logical_and),
+ ('logical_or', operator.or_, math_ops.logical_or, core.logical_or),
+ ('logical_xor', operator.xor, math_ops.logical_xor, core.logical_xor),
]
self.test_lt_1 = self.original_lt < 10
self.test_lt_2 = self.original_lt < 5
@@ -818,18 +837,18 @@ class FloatBinaryOpsTest(Base, DocStringCheckMixin, BinaryOpsTestsMixin):
super(FloatBinaryOpsTest, self).setUp()
self.ops = [
- ('igamma', None, tf.igamma, core.igamma),
- ('igammac', None, tf.igammac, core.igammac),
- ('zeta', None, tf.zeta, core.zeta),
- ('polygamma', None, tf.polygamma, core.polygamma),
- ('maximum', None, tf.maximum, core.maximum),
- ('minimum', None, tf.minimum, core.minimum),
- ('squared_difference', None, tf.squared_difference,
+ ('igamma', None, math_ops.igamma, core.igamma),
+ ('igammac', None, math_ops.igammac, core.igammac),
+ ('zeta', None, math_ops.zeta, core.zeta),
+ ('polygamma', None, math_ops.polygamma, core.polygamma),
+ ('maximum', None, math_ops.maximum, core.maximum),
+ ('minimum', None, math_ops.minimum, core.minimum),
+ ('squared_difference', None, math_ops.squared_difference,
core.squared_difference),
]
total_size = np.prod([v.size for v in self.original_lt.axes.values()])
test_lt = core.LabeledTensor(
- tf.cast(self.original_lt, tf.float32) / total_size,
+ math_ops.cast(self.original_lt, dtypes.float32) / total_size,
self.original_lt.axes)
self.test_lt_1 = test_lt
self.test_lt_2 = 1.0 - test_lt
@@ -839,4 +858,4 @@ class FloatBinaryOpsTest(Base, DocStringCheckMixin, BinaryOpsTestsMixin):
if __name__ == '__main__':
- tf.test.main()
+ test_lib.main()
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/io_ops_test.py b/tensorflow/contrib/labeled_tensor/python/ops/io_ops_test.py
index b9d3d9cec2..72dc3a8e44 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/io_ops_test.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/io_ops_test.py
@@ -17,11 +17,16 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import tensorflow as tf
-
from tensorflow.contrib.labeled_tensor.python.ops import core
from tensorflow.contrib.labeled_tensor.python.ops import io_ops
from tensorflow.contrib.labeled_tensor.python.ops import test_util
+from tensorflow.core.example import example_pb2
+from tensorflow.core.example import feature_pb2
+from tensorflow.python.client import session
+from tensorflow.python.framework import constant_op
+from tensorflow.python.framework import dtypes
+from tensorflow.python.ops import array_ops
+from tensorflow.python.platform import test as test_lib
class ParseBase(test_util.Base):
@@ -29,38 +34,45 @@ class ParseBase(test_util.Base):
def setUp(self):
super(ParseBase, self).setUp()
examples = [
- tf.train.Example(features=tf.train.Features(feature={
- 'a': tf.train.Feature(
- int64_list=tf.train.Int64List(value=[1])),
- 'b': tf.train.Feature(
- int64_list=tf.train.Int64List(value=[2, 3, 4])),
+ example_pb2.Example(features=feature_pb2.Features(feature={
+ 'a':
+ feature_pb2.Feature(
+ int64_list=feature_pb2.Int64List(value=[1])),
+ 'b':
+ feature_pb2.Feature(
+ int64_list=feature_pb2.Int64List(value=[2, 3, 4])),
})),
- tf.train.Example(features=tf.train.Features(feature={
- 'a': tf.train.Feature(
- int64_list=tf.train.Int64List(value=[5])),
- 'b': tf.train.Feature(
- int64_list=tf.train.Int64List(value=[6, 7, 8])),
+ example_pb2.Example(features=feature_pb2.Features(feature={
+ 'a':
+ feature_pb2.Feature(
+ int64_list=feature_pb2.Int64List(value=[5])),
+ 'b':
+ feature_pb2.Feature(
+ int64_list=feature_pb2.Int64List(value=[6, 7, 8])),
})),
]
self.serialized = core.LabeledTensor(
- tf.constant([ex.SerializeToString() for ex in examples]), ['batch'])
- self.features = {'a': io_ops.FixedLenFeature([], tf.int64),
- 'b': io_ops.FixedLenFeature([('x', 3)], tf.int64)}
+ constant_op.constant([ex.SerializeToString() for ex in examples]),
+ ['batch'])
+ self.features = {
+ 'a': io_ops.FixedLenFeature([], dtypes.int64),
+ 'b': io_ops.FixedLenFeature([('x', 3)], dtypes.int64)
+ }
class TestParseExample(ParseBase):
def test(self):
- expected_a = core.LabeledTensor(tf.constant([1, 5]), ['batch'])
- expected_b = core.LabeledTensor(tf.constant([[2, 3, 4], [6, 7, 8]]),
- ['batch', 'x'])
+ expected_a = core.LabeledTensor(constant_op.constant([1, 5]), ['batch'])
+ expected_b = core.LabeledTensor(
+ constant_op.constant([[2, 3, 4], [6, 7, 8]]), ['batch', 'x'])
parsed = io_ops.parse_example(self.serialized, self.features)
self.assertLabeledTensorsEqual(expected_a, parsed['a'])
self.assertLabeledTensorsEqual(expected_b, parsed['b'])
def test_placeholder(self):
- serialized = core.LabeledTensor(tf.placeholder(tf.string, [None]),
- ['batch'])
+ serialized = core.LabeledTensor(
+ array_ops.placeholder(dtypes.string, [None]), ['batch'])
# should not raise
io_ops.parse_example(serialized, self.features)
@@ -68,15 +80,15 @@ class TestParseExample(ParseBase):
class TestParseSingleExample(ParseBase):
def test(self):
- expected_a = core.LabeledTensor(tf.constant(1), [])
- expected_b = core.LabeledTensor(tf.constant([2, 3, 4]), ['x'])
+ expected_a = core.LabeledTensor(constant_op.constant(1), [])
+ expected_b = core.LabeledTensor(constant_op.constant([2, 3, 4]), ['x'])
parsed = io_ops.parse_single_example(self.serialized[0], self.features)
self.assertLabeledTensorsEqual(expected_a, parsed['a'])
self.assertLabeledTensorsEqual(expected_b, parsed['b'])
def test_unknown_size(self):
- features = {'a': io_ops.FixedLenFeature([('x', None)], tf.int64)}
- serialized = tf.placeholder(tf.string, [])
+ features = {'a': io_ops.FixedLenFeature([('x', None)], dtypes.int64)}
+ serialized = array_ops.placeholder(dtypes.string, [])
with self.assertRaisesRegexp(ValueError, 'unknown size'):
io_ops.parse_single_example(serialized, features)
@@ -84,23 +96,23 @@ class TestParseSingleExample(ParseBase):
class PlaceholderTest(test_util.Base):
def test_name(self):
- placeholder_lt = io_ops.placeholder(tf.float32, [])
+ placeholder_lt = io_ops.placeholder(dtypes.float32, [])
self.assertIn('lt_placeholder', placeholder_lt.name)
def test(self):
- placeholder_lt = io_ops.placeholder(tf.float32,
+ placeholder_lt = io_ops.placeholder(dtypes.float32,
['batch', ('x', ['a', 'b'])])
- self.assertEqual(placeholder_lt.dtype, tf.float32)
+ self.assertEqual(placeholder_lt.dtype, dtypes.float32)
self.assertEqual(placeholder_lt.axes,
core.Axes([('batch', None), ('x', ['a', 'b'])]))
def test_feed(self):
- sess = tf.Session()
- placeholder_lt = io_ops.placeholder(tf.float32, [])
+ sess = session.Session()
+ placeholder_lt = io_ops.placeholder(dtypes.float32, [])
two_times = 2.0 * placeholder_lt
result = sess.run(two_times, {placeholder_lt.tensor: 1})
self.assertEqual(result, 2.0)
if __name__ == '__main__':
- tf.test.main()
+ test_lib.main()
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/nn_test.py b/tensorflow/contrib/labeled_tensor/python/ops/nn_test.py
index 18cbd8b4ed..a5baf07dff 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/nn_test.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/nn_test.py
@@ -17,11 +17,11 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import tensorflow as tf
-
from tensorflow.contrib.labeled_tensor.python.ops import core
from tensorflow.contrib.labeled_tensor.python.ops import nn
from tensorflow.contrib.labeled_tensor.python.ops import test_util
+from tensorflow.python.ops import nn_impl
+from tensorflow.python.ops import nn_ops
class NNTests(test_util.Base):
@@ -34,14 +34,14 @@ class NNTests(test_util.Base):
def test_unary_ops(self):
ops = [
- ('relu', tf.nn.relu, nn.relu),
- ('relu6', tf.nn.relu6, nn.relu6),
- ('crelu', tf.nn.crelu, nn.crelu),
- ('elu', tf.nn.elu, nn.elu),
- ('softplus', tf.nn.softplus, nn.softplus),
- ('l2_loss', tf.nn.l2_loss, nn.l2_loss),
- ('softmax', tf.nn.softmax, nn.softmax),
- ('log_softmax', tf.nn.log_softmax, nn.log_softmax),
+ ('relu', nn_ops.relu, nn.relu),
+ ('relu6', nn_ops.relu6, nn.relu6),
+ ('crelu', nn_ops.crelu, nn.crelu),
+ ('elu', nn_ops.elu, nn.elu),
+ ('softplus', nn_ops.softplus, nn.softplus),
+ ('l2_loss', nn_ops.l2_loss, nn.l2_loss),
+ ('softmax', nn_ops.softmax, nn.softmax),
+ ('log_softmax', nn_ops.log_softmax, nn.log_softmax),
]
for op_name, tf_op, lt_op in ops:
golden_tensor = tf_op(self.original_lt.tensor)
@@ -53,13 +53,13 @@ class NNTests(test_util.Base):
def test_binary_ops(self):
ops = [
('sigmoid_cross_entropy_with_logits',
- tf.nn.sigmoid_cross_entropy_with_logits,
+ nn_impl.sigmoid_cross_entropy_with_logits,
nn.sigmoid_cross_entropy_with_logits),
('softmax_cross_entropy_with_logits',
- tf.nn.softmax_cross_entropy_with_logits,
+ nn_ops.softmax_cross_entropy_with_logits,
nn.softmax_cross_entropy_with_logits),
('sparse_softmax_cross_entropy_with_logits',
- tf.nn.sparse_softmax_cross_entropy_with_logits,
+ nn_ops.sparse_softmax_cross_entropy_with_logits,
nn.sparse_softmax_cross_entropy_with_logits),
]
for op_name, tf_op, lt_op in ops:
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/ops_test.py b/tensorflow/contrib/labeled_tensor/python/ops/ops_test.py
index 55dd96e560..87e27ca85f 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/ops_test.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/ops_test.py
@@ -19,11 +19,16 @@ from __future__ import print_function
import numpy as np
from six.moves import range # pylint: disable=redefined-builtin
-import tensorflow as tf
from tensorflow.contrib.labeled_tensor.python.ops import core
from tensorflow.contrib.labeled_tensor.python.ops import ops
from tensorflow.contrib.labeled_tensor.python.ops import test_util
+from tensorflow.python.framework import constant_op
+from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import errors_impl
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import math_ops
+from tensorflow.python.platform import test as test_lib
class Base(test_util.Base):
@@ -36,10 +41,10 @@ class Base(test_util.Base):
self.z_size = 4
self.probs_size = 11
- tensor = tf.range(0, self.x_size * self.channel_size * self.z_size *
- self.probs_size)
- tensor = tf.reshape(tensor, [self.x_size, self.channel_size, self.z_size,
- self.probs_size])
+ tensor = math_ops.range(0, self.x_size * self.channel_size * self.z_size *
+ self.probs_size)
+ tensor = array_ops.reshape(
+ tensor, [self.x_size, self.channel_size, self.z_size, self.probs_size])
a0 = ('x', range(self.x_size))
a1 = ('channel', ['red', 'green', 'blue'])
a2 = 'z'
@@ -55,8 +60,9 @@ class Base(test_util.Base):
self.x_probs_lt = core.slice_function(self.original_lt, {'z': 0})
self.x_probs_lt = ops.select(self.x_probs_lt, {'channel': 'red'})
- self.channel_probs_lt = core.slice_function(self.original_lt, {'x': 3,
- 'z': 0})
+ self.channel_probs_lt = core.slice_function(self.original_lt,
+ {'x': 3,
+ 'z': 0})
class SelectTest(Base):
@@ -67,8 +73,8 @@ class SelectTest(Base):
def test_scalar(self):
select_lt = ops.select(self.original_lt, {'channel': 'green'})
- golden_lt = core.LabeledTensor(self.tensor[:, 1, :, :], [self.a0, self.a2,
- self.a3])
+ golden_lt = core.LabeledTensor(self.tensor[:, 1, :, :],
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(select_lt, golden_lt)
def test_slice(self):
@@ -79,8 +85,9 @@ class SelectTest(Base):
self.assertLabeledTensorsEqual(select_lt, golden_lt)
def test_slices(self):
- select_lt = ops.select(self.original_lt, {'x': slice(1, 4),
- 'channel': slice('green', None)})
+ select_lt = ops.select(self.original_lt,
+ {'x': slice(1, 4),
+ 'channel': slice('green', None)})
a0_sliced = ('x', range(1, 5))
a1_sliced = ('channel', ['green', 'blue'])
@@ -110,8 +117,7 @@ class SelectTest(Base):
def test_scalars(self):
select_lt = ops.select(self.original_lt, {'x': 1, 'channel': 'green'})
- golden_lt = core.LabeledTensor(self.tensor[1, 1, :, :],
- [self.a2, self.a3])
+ golden_lt = core.LabeledTensor(self.tensor[1, 1, :, :], [self.a2, self.a3])
self.assertLabeledTensorsEqual(select_lt, golden_lt)
def test_invalid_input(self):
@@ -174,17 +180,16 @@ class PackTest(Base):
def test(self):
pack_lt = ops.pack([self.original_lt, self.original_lt], 'batch')
golden_lt = core.LabeledTensor(
- tf.stack([self.original_lt.tensor, self.original_lt.tensor]),
+ array_ops.stack([self.original_lt.tensor, self.original_lt.tensor]),
['batch', self.a0, self.a1, self.a2, self.a3])
self.assertLabeledTensorsEqual(pack_lt, golden_lt)
def test_axis(self):
- pack_lt = ops.pack([self.original_lt, self.original_lt],
- new_axis='batch',
- axis_position=4)
+ pack_lt = ops.pack(
+ [self.original_lt, self.original_lt], new_axis='batch', axis_position=4)
golden_lt = core.LabeledTensor(
- tf.stack(
+ array_ops.stack(
[self.original_lt.tensor, self.original_lt.tensor], axis=4),
[self.a0, self.a1, self.a2, self.a3, 'batch'])
@@ -205,14 +210,15 @@ class UnpackTest(Base):
def test(self):
unpack_lt = ops.unpack(self.original_lt)[0]
golden_lt = core.LabeledTensor(
- tf.unstack(self.original_lt.tensor)[0], [self.a1, self.a2, self.a3])
+ array_ops.unstack(self.original_lt.tensor)[0],
+ [self.a1, self.a2, self.a3])
self.assertLabeledTensorsEqual(unpack_lt, golden_lt)
def test_axis(self):
unpack_lt = ops.unpack(self.original_lt, axis_name='z')[0]
golden_lt = core.LabeledTensor(
- tf.unstack(
+ array_ops.unstack(
self.original_lt.tensor, axis=2)[0], [self.a0, self.a1, self.a3])
self.assertLabeledTensorsEqual(unpack_lt, golden_lt)
@@ -229,7 +235,8 @@ class ReshapeTest(Base):
self.assertIn('lt_reshape', reshape_lt.name)
def test_identity(self):
- reshape_lt = ops.reshape(self.original_lt, self.original_lt.axes.keys(),
+ reshape_lt = ops.reshape(self.original_lt,
+ self.original_lt.axes.keys(),
self.original_lt.axes.values())
self.assertLabeledTensorsEqual(reshape_lt, self.original_lt)
@@ -238,7 +245,7 @@ class ReshapeTest(Base):
reshape_lt = ops.reshape(self.original_lt, ['channel', 'z', 'probs'],
[('new_dim', new_dim_size)])
golden_lt = core.LabeledTensor(
- tf.reshape(self.original_lt.tensor, [self.x_size, -1]),
+ array_ops.reshape(self.original_lt.tensor, [self.x_size, -1]),
[self.original_lt.axes['x'], 'new_dim'])
self.assertLabeledTensorsEqual(reshape_lt, golden_lt)
@@ -246,12 +253,13 @@ class ReshapeTest(Base):
reshape_lt = ops.reshape(self.original_lt, ['channel', 'z', 'probs'],
['new_dim'])
golden_lt = core.LabeledTensor(
- tf.reshape(self.original_lt.tensor, [self.x_size, -1]),
+ array_ops.reshape(self.original_lt.tensor, [self.x_size, -1]),
[self.original_lt.axes['x'], 'new_dim'])
self.assertLabeledTensorsEqual(reshape_lt, golden_lt)
def test_unknown_dimension(self):
- orig_lt = core.LabeledTensor(tf.placeholder(tf.float32, [None]), ['x'])
+ orig_lt = core.LabeledTensor(
+ array_ops.placeholder(dtypes.float32, [None]), ['x'])
reshape_lt = ops.reshape(orig_lt, ['x'], ['y', ('z', 1)])
self.assertEqual(reshape_lt.axes, core.Axes([('y', None), ('z', 1)]))
with self.test_session() as sess:
@@ -263,7 +271,7 @@ class ReshapeTest(Base):
reshape_lt = ops.reshape(self.original_lt, ['channel', 'z', 'probs'],
[('new_dim', range(new_dim_size))])
golden_lt = core.LabeledTensor(
- tf.reshape(self.original_lt.tensor, [self.x_size, -1]),
+ array_ops.reshape(self.original_lt.tensor, [self.x_size, -1]),
[self.original_lt.axes['x'], ('new_dim', range(new_dim_size))])
self.assertLabeledTensorsEqual(reshape_lt, golden_lt)
@@ -306,14 +314,13 @@ class BatchTest(Base):
tensors = []
for i in range(10):
- offset_lt = core.LabeledTensor(tf.constant(i), [])
+ offset_lt = core.LabeledTensor(constant_op.constant(i), [])
tensors.append(core.add(self.original_lt, offset_lt))
self.pack_lt = ops.pack(tensors, 'batch')
def test_name(self):
- batch_ops = ops.batch([self.pack_lt, self.pack_lt],
- batch_size=2,
- enqueue_many=True)
+ batch_ops = ops.batch(
+ [self.pack_lt, self.pack_lt], batch_size=2, enqueue_many=True)
for bo in batch_ops:
self.assertIn('lt_batch', bo.name)
@@ -339,8 +346,8 @@ class BatchTest(Base):
ops.batch([self.original_lt], 3, enqueue_many=True)
def test_allow_smaller_final_batch(self):
- [batch_2_op] = ops.batch([self.original_lt], batch_size=2,
- allow_smaller_final_batch=True)
+ [batch_2_op] = ops.batch(
+ [self.original_lt], batch_size=2, allow_smaller_final_batch=True)
self.assertEqual(batch_2_op.axes['batch'].size, None)
@@ -351,23 +358,23 @@ class ShuffleBatchTest(Base):
tensors = []
for i in range(10):
- offset_lt = core.LabeledTensor(tf.constant(i), [])
+ offset_lt = core.LabeledTensor(constant_op.constant(i), [])
tensors.append(core.add(self.original_lt, offset_lt))
self.pack_lt = ops.pack(tensors, 'batch')
def test_name(self):
- batch_lts = ops.shuffle_batch([self.pack_lt, self.pack_lt],
- batch_size=2,
- enqueue_many=True)
+ batch_lts = ops.shuffle_batch(
+ [self.pack_lt, self.pack_lt], batch_size=2, enqueue_many=True)
for blt in batch_lts:
self.assertIn('lt_shuffle_batch', blt.name)
def test_enqueue_many(self):
- [batch_2_lt] = ops.shuffle_batch([self.pack_lt],
- batch_size=2,
- enqueue_many=True,
- min_after_dequeue=8,
- seed=0)
+ [batch_2_lt] = ops.shuffle_batch(
+ [self.pack_lt],
+ batch_size=2,
+ enqueue_many=True,
+ min_after_dequeue=8,
+ seed=0)
self.assertEqual(len(batch_2_lt.axes['batch']), 2)
[batch_10_lt] = ops.batch([batch_2_lt], batch_size=10, enqueue_many=True)
@@ -377,8 +384,8 @@ class ShuffleBatchTest(Base):
self.assertFalse((batch_10 == pack).all())
def test_allow_smaller_final_batch(self):
- [batch_2_op] = ops.shuffle_batch([self.original_lt], batch_size=2,
- allow_smaller_final_batch=True)
+ [batch_2_op] = ops.shuffle_batch(
+ [self.original_lt], batch_size=2, allow_smaller_final_batch=True)
self.assertEqual(batch_2_op.axes['batch'].size, None)
@@ -410,31 +417,31 @@ class RandomCropTest(Base):
crop_lt.axes)
def test_different_seeds(self):
- crop_0_lt = ops.random_crop(self.original_lt, {'probs': 3,
- 'channel': 2},
- seed=0)
- crop_1_lt = ops.random_crop(self.original_lt, {'probs': 3,
- 'channel': 2},
- seed=1)
+ crop_0_lt = ops.random_crop(
+ self.original_lt, {'probs': 3,
+ 'channel': 2}, seed=0)
+ crop_1_lt = ops.random_crop(
+ self.original_lt, {'probs': 3,
+ 'channel': 2}, seed=1)
self.assertEqual(crop_0_lt.axes, crop_1_lt.axes)
[crop_0, crop_1] = self.eval([crop_0_lt.tensor, crop_1_lt.tensor])
self.assertFalse((crop_0 == crop_1).all())
def test_identical_seeds(self):
- crop_0_lt = ops.random_crop(self.original_lt, {'probs': 3,
- 'channel': 2},
- seed=0)
- crop_1_lt = ops.random_crop(self.original_lt, {'probs': 3,
- 'channel': 2},
- seed=0)
+ crop_0_lt = ops.random_crop(
+ self.original_lt, {'probs': 3,
+ 'channel': 2}, seed=0)
+ crop_1_lt = ops.random_crop(
+ self.original_lt, {'probs': 3,
+ 'channel': 2}, seed=0)
self.assertLabeledTensorsEqual(crop_0_lt, crop_1_lt)
def test_crop_idempotent(self):
- crop_0_lt = ops.random_crop(self.original_lt, {'probs': 3,
- 'channel': 2},
- seed=0)
+ crop_0_lt = ops.random_crop(
+ self.original_lt, {'probs': 3,
+ 'channel': 2}, seed=0)
crop_1_lt = ops.random_crop(crop_0_lt, {'probs': 3, 'channel': 2}, seed=1)
self.assertLabeledTensorsEqual(crop_0_lt, crop_1_lt)
@@ -476,9 +483,9 @@ class SqueezeTest(Base):
def setUp(self):
super(SqueezeTest, self).setUp()
- self.squeezable_lt = core.slice_function(self.original_lt,
- {'channel': slice(0, 1),
- 'probs': slice(0, 1)})
+ self.squeezable_lt = core.slice_function(
+ self.original_lt, {'channel': slice(0, 1),
+ 'probs': slice(0, 1)})
def test_name(self):
squeeze_lt = ops.squeeze(self.squeezable_lt)
@@ -504,35 +511,39 @@ class SqueezeTest(Base):
class MatMulTest(Base):
def test_name(self):
- x_lt = core.LabeledTensor(tf.ones((3,)), ['x'])
+ x_lt = core.LabeledTensor(array_ops.ones((3,)), ['x'])
matmul_lt = ops.matmul(x_lt, x_lt)
self.assertIn('lt_matmul', matmul_lt.name)
def test_vector_vector(self):
- x_lt = core.LabeledTensor(tf.range(3), ['x'])
+ x_lt = core.LabeledTensor(math_ops.range(3), ['x'])
matmul_lt = ops.matmul(x_lt, x_lt)
golden_lt = core.convert_to_labeled_tensor(5)
self.assertLabeledTensorsEqual(matmul_lt, golden_lt)
def test_matrix_vector(self):
- xy_lt = core.LabeledTensor(tf.reshape(tf.range(6), (2, 3)), ['x', 'y'])
- y_lt = core.LabeledTensor(tf.range(3), ['y'])
+ xy_lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(6), (2, 3)), ['x', 'y'])
+ y_lt = core.LabeledTensor(math_ops.range(3), ['y'])
matmul_lt = ops.matmul(xy_lt, y_lt)
golden_lt = core.LabeledTensor(
- tf.matmul(xy_lt.tensor, tf.reshape(y_lt.tensor, (-1, 1)))[:, 0], ['x'])
+ math_ops.matmul(xy_lt.tensor, array_ops.reshape(y_lt.tensor,
+ (-1, 1)))[:, 0], ['x'])
self.assertLabeledTensorsEqual(matmul_lt, golden_lt)
matmul_lt = ops.matmul(y_lt, xy_lt)
self.assertLabeledTensorsEqual(matmul_lt, golden_lt)
def test_matrix_matrix(self):
- xy_lt = core.LabeledTensor(tf.reshape(tf.range(6), (2, 3)), ['x', 'y'])
- yz_lt = core.LabeledTensor(tf.reshape(tf.range(12), (3, 4)), ['y', 'z'])
+ xy_lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(6), (2, 3)), ['x', 'y'])
+ yz_lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(12), (3, 4)), ['y', 'z'])
matmul_lt = ops.matmul(xy_lt, yz_lt)
golden_lt = core.LabeledTensor(
- tf.matmul(xy_lt.tensor, yz_lt.tensor), ['x', 'z'])
+ math_ops.matmul(xy_lt.tensor, yz_lt.tensor), ['x', 'z'])
self.assertLabeledTensorsEqual(matmul_lt, golden_lt)
transpose = lambda x: core.transpose(x, list(x.axes.keys())[::-1])
@@ -550,11 +561,13 @@ class MatMulTest(Base):
self.assertLabeledTensorsEqual(matmul_lt, transpose(golden_lt))
def test_matrix_matrix_axis_order(self):
- xy_lt = core.LabeledTensor(tf.reshape(tf.range(6), (2, 3)), ['x', 'y'])
- yz_lt = core.LabeledTensor(tf.reshape(tf.range(12), (3, 4)), ['y', 'z'])
+ xy_lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(6), (2, 3)), ['x', 'y'])
+ yz_lt = core.LabeledTensor(
+ array_ops.reshape(math_ops.range(12), (3, 4)), ['y', 'z'])
golden_lt = core.LabeledTensor(
- tf.matmul(xy_lt.tensor, yz_lt.tensor), ['x', 'z'])
+ math_ops.matmul(xy_lt.tensor, yz_lt.tensor), ['x', 'z'])
with core.axis_order_scope(['x', 'y', 'z']):
@@ -565,12 +578,12 @@ class MatMulTest(Base):
self.assertLabeledTensorsEqual(matmul_lt, golden_lt)
def test_invalid(self):
- scalar_lt = core.LabeledTensor(tf.ones(()), [])
- x_lt = core.LabeledTensor(tf.ones((2,)), ['x'])
- x2_lt = core.LabeledTensor(tf.ones((3,)), ['x'])
- y_lt = core.LabeledTensor(tf.ones((3,)), ['y'])
- xy_lt = core.LabeledTensor(tf.ones((2, 3)), ['x', 'y'])
- xyz_lt = core.LabeledTensor(tf.ones((2, 3, 1)), ['x', 'y', 'z'])
+ scalar_lt = core.LabeledTensor(array_ops.ones(()), [])
+ x_lt = core.LabeledTensor(array_ops.ones((2,)), ['x'])
+ x2_lt = core.LabeledTensor(array_ops.ones((3,)), ['x'])
+ y_lt = core.LabeledTensor(array_ops.ones((3,)), ['y'])
+ xy_lt = core.LabeledTensor(array_ops.ones((2, 3)), ['x', 'y'])
+ xyz_lt = core.LabeledTensor(array_ops.ones((2, 3, 1)), ['x', 'y', 'z'])
with self.assertRaisesRegexp(ValueError, 'inputs with at least rank'):
ops.matmul(x_lt, scalar_lt)
@@ -597,33 +610,35 @@ class ReduceSumTest(Base):
def test_drop_axis(self):
sum_lt = ops.reduce_sum(self.original_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_sum(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_sum(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
def test_drop_scalar_axis(self):
sum_lt = ops.reduce_sum(self.original_lt, 'channel')
golden_lt = core.LabeledTensor(
- tf.reduce_sum(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_sum(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
def test_keep_axis(self):
sum_lt = ops.reduce_sum(self.original_lt, {('channel', 'hihowareyou')})
golden_lt = core.LabeledTensor(
- tf.reduce_sum(self.original_lt.tensor,
- 1, keep_dims=True),
+ math_ops.reduce_sum(
+ self.original_lt.tensor, 1, keep_dims=True),
[self.a0, ('channel', ['hihowareyou']), self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
def test_keep_scalar_axis(self):
sum_lt = ops.reduce_sum(self.original_lt, ('channel', 'hihowareyou'))
golden_lt = core.LabeledTensor(
- tf.reduce_sum(self.original_lt.tensor,
- 1, keep_dims=True),
+ math_ops.reduce_sum(
+ self.original_lt.tensor, 1, keep_dims=True),
[self.a0, ('channel', ['hihowareyou']), self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
def test_scalar(self):
- scalar_lt = core.LabeledTensor(tf.constant(42), [])
+ scalar_lt = core.LabeledTensor(constant_op.constant(42), [])
reduce_lt = ops.reduce_sum(scalar_lt, [])
self.assertLabeledTensorsEqual(reduce_lt, scalar_lt)
@@ -633,7 +648,8 @@ class ReduceSumTest(Base):
def test_none(self):
sum_lt = ops.reduce_sum(self.original_lt)
- golden_lt = core.LabeledTensor(tf.reduce_sum(self.original_lt.tensor), [])
+ golden_lt = core.LabeledTensor(
+ math_ops.reduce_sum(self.original_lt.tensor), [])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
def test_function_docstring_and_name(self):
@@ -650,7 +666,8 @@ class ReduceMeanTest(Base):
def test(self):
actual_lt = ops.reduce_mean(self.original_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_mean(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_mean(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(actual_lt, golden_lt)
@@ -663,7 +680,8 @@ class ReduceProdTest(Base):
def test(self):
result_lt = ops.reduce_prod(self.original_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_prod(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_prod(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(result_lt, golden_lt)
@@ -676,7 +694,8 @@ class ReduceMinTest(Base):
def test(self):
result_lt = ops.reduce_min(self.original_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_min(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_min(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(result_lt, golden_lt)
@@ -689,7 +708,8 @@ class ReduceMaxTest(Base):
def test(self):
result_lt = ops.reduce_max(self.original_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_max(self.original_lt.tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_max(self.original_lt.tensor, 1),
+ [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(result_lt, golden_lt)
@@ -697,7 +717,7 @@ class BaseReduceBoolean(Base):
def setUp(self):
super(BaseReduceBoolean, self).setUp()
- self.bool_tensor = tf.cast(self.original_lt.tensor > 5, tf.bool)
+ self.bool_tensor = math_ops.cast(self.original_lt.tensor > 5, dtypes.bool)
self.bool_lt = core.LabeledTensor(self.bool_tensor, self.original_lt.axes)
@@ -710,7 +730,7 @@ class ReduceAllTest(BaseReduceBoolean):
def test(self):
result_lt = ops.reduce_all(self.bool_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_all(self.bool_tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_all(self.bool_tensor, 1), [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(result_lt, golden_lt)
@@ -723,7 +743,7 @@ class ReduceAnyTest(BaseReduceBoolean):
def test(self):
result_lt = ops.reduce_any(self.bool_lt, {'channel'})
golden_lt = core.LabeledTensor(
- tf.reduce_any(self.bool_tensor, 1), [self.a0, self.a2, self.a3])
+ math_ops.reduce_any(self.bool_tensor, 1), [self.a0, self.a2, self.a3])
self.assertLabeledTensorsEqual(result_lt, golden_lt)
@@ -734,11 +754,13 @@ class TileTest(Base):
self.assertIn('lt_tile', tile_lt.name)
def test(self):
- for multiple in [2, tf.constant(2)]:
+ for multiple in [2, constant_op.constant(2)]:
tile_lt = ops.tile(self.original_lt, {'z': multiple})
- golden_op = tf.tile(self.original_lt.tensor, [1, 1, multiple, 1])
- golden_axes = ['z' if axis.name == 'z' else axis
- for axis in self.original_lt.axes.values()]
+ golden_op = array_ops.tile(self.original_lt.tensor, [1, 1, multiple, 1])
+ golden_axes = [
+ 'z' if axis.name == 'z' else axis
+ for axis in self.original_lt.axes.values()
+ ]
golden_lt = core.LabeledTensor(golden_op, golden_axes)
self.assertLabeledTensorsEqual(tile_lt, golden_lt)
@@ -752,16 +774,18 @@ class TileTest(Base):
class PadTest(Base):
def test_name(self):
- pad_lt = ops.pad(self.original_lt, {'x': (1, 1),
- 'channel': ([], ['alpha'])})
+ pad_lt = ops.pad(self.original_lt,
+ {'x': (1, 1),
+ 'channel': ([], ['alpha'])})
self.assertIn('lt_pad', pad_lt.name)
def test(self):
- pad_lt = ops.pad(self.original_lt, {'x': (1, 1),
- 'channel': ([], ['alpha'])})
+ pad_lt = ops.pad(self.original_lt,
+ {'x': (1, 1),
+ 'channel': ([], ['alpha'])})
- golden_op = tf.pad(self.original_lt.tensor, [[1, 1], [0, 1], [0, 0],
- [0, 0]])
+ golden_op = array_ops.pad(self.original_lt.tensor, [[1, 1], [0, 1], [0, 0],
+ [0, 0]])
golden_axes = [('x', self.x_size + 2),
('channel', ['red', 'green', 'blue', 'alpha']), self.a2,
self.a3]
@@ -781,21 +805,21 @@ class ConstantTest(Base):
def test_scalar(self):
constant_lt = ops.constant(1)
- golden_lt = core.LabeledTensor(tf.constant(1), [])
+ golden_lt = core.LabeledTensor(constant_op.constant(1), [])
self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_infer_shape(self):
constant_lt = ops.constant([1, 2], axes=['x'])
- golden_lt = core.LabeledTensor(tf.constant([1, 2]), ['x'])
+ golden_lt = core.LabeledTensor(constant_op.constant([1, 2]), ['x'])
self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_specify_shape(self):
constant_lt = ops.constant(1, axes=[('x', 3)])
- golden_lt = core.LabeledTensor(tf.constant(1, shape=(3,)), ['x'])
+ golden_lt = core.LabeledTensor(constant_op.constant(1, shape=(3,)), ['x'])
self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_existing_axes(self):
- golden_lt = core.LabeledTensor(tf.constant([1, 2]), ['x'])
+ golden_lt = core.LabeledTensor(constant_op.constant([1, 2]), ['x'])
constant_lt = ops.constant([1, 2], axes=golden_lt.axes)
self.assertLabeledTensorsEqual(constant_lt, golden_lt)
@@ -809,7 +833,7 @@ class ZerosLikeTest(Base):
def test(self):
like_lt = ops.zeros_like(self.original_lt)
golden_lt = core.LabeledTensor(
- tf.zeros_like(self.original_lt.tensor), self.original_lt.axes)
+ array_ops.zeros_like(self.original_lt.tensor), self.original_lt.axes)
self.assertLabeledTensorsEqual(like_lt, golden_lt)
@@ -822,20 +846,21 @@ class OnesLikeTest(Base):
def test(self):
like_lt = ops.ones_like(self.original_lt)
golden_lt = core.LabeledTensor(
- tf.ones_like(self.original_lt.tensor), self.original_lt.axes)
+ array_ops.ones_like(self.original_lt.tensor), self.original_lt.axes)
self.assertLabeledTensorsEqual(like_lt, golden_lt)
class CastTest(Base):
def test_name(self):
- cast_lt = ops.cast(self.original_lt, tf.float16)
+ cast_lt = ops.cast(self.original_lt, dtypes.float16)
self.assertIn('lt_cast', cast_lt.name)
def test(self):
- cast_lt = ops.cast(self.original_lt, tf.float16)
+ cast_lt = ops.cast(self.original_lt, dtypes.float16)
golden_lt = core.LabeledTensor(
- tf.cast(self.original_lt.tensor, tf.float16), self.original_lt.axes)
+ math_ops.cast(self.original_lt.tensor, dtypes.float16),
+ self.original_lt.axes)
self.assertLabeledTensorsEqual(cast_lt, golden_lt)
@@ -844,8 +869,8 @@ class VerifyTensorAllFiniteTest(Base):
def setUp(self):
super(VerifyTensorAllFiniteTest, self).setUp()
- self.finite_lt = core.LabeledTensor(tf.constant(42.0), [])
- self.nan_lt = core.LabeledTensor(tf.constant(np.nan), [])
+ self.finite_lt = core.LabeledTensor(constant_op.constant(42.0), [])
+ self.nan_lt = core.LabeledTensor(constant_op.constant(np.nan), [])
self.checked_finite_lt = ops.verify_tensor_all_finite(self.finite_lt, '')
self.checked_nan_lt = ops.verify_tensor_all_finite(self.nan_lt, '')
@@ -858,7 +883,7 @@ class VerifyTensorAllFiniteTest(Base):
self.assertLabeledTensorsEqual(self.finite_lt, self.checked_finite_lt)
def test_nan(self):
- with self.assertRaisesRegexp(tf.errors.InvalidArgumentError,
+ with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
'Tensor had NaN values'):
self.eval([self.checked_nan_lt])
@@ -866,25 +891,25 @@ class VerifyTensorAllFiniteTest(Base):
class BooleanMaskTest(Base):
def test_name(self):
- mask = core.LabeledTensor(tf.range(7) > 3, [self.a0])
+ mask = core.LabeledTensor(math_ops.range(7) > 3, [self.a0])
masked_lt = ops.boolean_mask(self.original_lt, mask)
self.assertIn('lt_boolean_mask', masked_lt.name)
def test(self):
- mask = core.LabeledTensor(tf.range(7) > 3, [self.a0])
+ mask = core.LabeledTensor(math_ops.range(7) > 3, [self.a0])
masked_lt = ops.boolean_mask(self.original_lt, mask)
golden_lt = core.LabeledTensor(
- tf.boolean_mask(self.original_lt.tensor, mask.tensor),
+ array_ops.boolean_mask(self.original_lt.tensor, mask.tensor),
['x', self.a1, self.a2, self.a3])
self.assertLabeledTensorsEqual(masked_lt, golden_lt)
def test_invalid_rank(self):
- mask = core.LabeledTensor(tf.ones((7, 3)) > 3, [self.a0, self.a1])
+ mask = core.LabeledTensor(array_ops.ones((7, 3)) > 3, [self.a0, self.a1])
with self.assertRaises(NotImplementedError):
ops.boolean_mask(self.original_lt, mask)
def test_mismatched_axis(self):
- mask = core.LabeledTensor(tf.range(7) > 3, ['foo'])
+ mask = core.LabeledTensor(math_ops.range(7) > 3, ['foo'])
with self.assertRaisesRegexp(ValueError, 'not equal'):
ops.boolean_mask(self.original_lt, mask)
@@ -892,22 +917,22 @@ class BooleanMaskTest(Base):
class WhereTest(Base):
def test_name(self):
- condition = core.LabeledTensor(tf.range(5) < 3, ['x'])
+ condition = core.LabeledTensor(math_ops.range(5) < 3, ['x'])
where_lt = ops.where(condition, condition, condition)
self.assertIn('lt_where', where_lt.name)
def test(self):
- condition = core.LabeledTensor(tf.range(5) < 3, ['x'])
- x = core.LabeledTensor(tf.ones(5), ['x'])
- y = core.LabeledTensor(tf.zeros(5), ['x'])
+ condition = core.LabeledTensor(math_ops.range(5) < 3, ['x'])
+ x = core.LabeledTensor(array_ops.ones(5), ['x'])
+ y = core.LabeledTensor(array_ops.zeros(5), ['x'])
where_lt = ops.where(condition, x, y)
golden_lt = core.LabeledTensor(
- tf.concat_v2([tf.ones(3), tf.zeros(2)], 0), ['x'])
+ array_ops.concat_v2([array_ops.ones(3), array_ops.zeros(2)], 0), ['x'])
self.assertLabeledTensorsEqual(where_lt, golden_lt)
def test_mismatched_axes(self):
- condition = core.LabeledTensor(tf.range(5) < 3, ['x'])
+ condition = core.LabeledTensor(math_ops.range(5) < 3, ['x'])
with self.assertRaisesRegexp(ValueError, 'equal axes'):
ops.where(condition, condition[:3], condition)
with self.assertRaisesRegexp(ValueError, 'equal axes'):
@@ -915,4 +940,4 @@ class WhereTest(Base):
if __name__ == '__main__':
- tf.test.main()
+ test_lib.main()
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/sugar_test.py b/tensorflow/contrib/labeled_tensor/python/ops/sugar_test.py
index 3923f5a174..2797e7d525 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/sugar_test.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/sugar_test.py
@@ -18,12 +18,15 @@ from __future__ import division
from __future__ import print_function
from six.moves import range # pylint: disable=redefined-builtin
-import tensorflow as tf
from tensorflow.contrib.labeled_tensor.python.ops import core
from tensorflow.contrib.labeled_tensor.python.ops import ops
from tensorflow.contrib.labeled_tensor.python.ops import sugar
from tensorflow.contrib.labeled_tensor.python.ops import test_util
+from tensorflow.python.framework import constant_op
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import math_ops
+from tensorflow.python.platform import test
class Base(test_util.Base):
@@ -31,7 +34,7 @@ class Base(test_util.Base):
def setUp(self):
super(Base, self).setUp()
- self.small_lt = core.LabeledTensor(tf.constant([1]), [('x', 1)])
+ self.small_lt = core.LabeledTensor(constant_op.constant([1]), [('x', 1)])
class ReshapeCoderTest(Base):
@@ -45,11 +48,13 @@ class ReshapeCoderTest(Base):
self.channels = ['red', 'green', 'blue']
self.masks = [False, True]
- tensor = tf.range(0, self.batch_size * self.num_rows * self.num_columns *
- len(self.channels) * len(self.masks))
- tensor = tf.reshape(tensor, [self.batch_size, self.num_rows,
- self.num_columns, len(self.channels),
- len(self.masks)])
+ tensor = math_ops.range(0,
+ self.batch_size * self.num_rows * self.num_columns *
+ len(self.channels) * len(self.masks))
+ tensor = array_ops.reshape(tensor, [
+ self.batch_size, self.num_rows, self.num_columns, len(self.channels),
+ len(self.masks)
+ ])
self.batch_axis = ('batch', range(self.batch_size))
self.row_axis = ('row', range(self.num_rows))
@@ -57,8 +62,10 @@ class ReshapeCoderTest(Base):
self.channel_axis = ('channel', self.channels)
self.mask_axis = ('mask', self.masks)
- axes = [self.batch_axis, self.row_axis, self.column_axis, self.channel_axis,
- self.mask_axis]
+ axes = [
+ self.batch_axis, self.row_axis, self.column_axis, self.channel_axis,
+ self.mask_axis
+ ]
self.masked_image_lt = core.LabeledTensor(tensor, axes)
def test_name(self):
@@ -72,8 +79,10 @@ class ReshapeCoderTest(Base):
rc = sugar.ReshapeCoder(['channel', 'mask'], ['depth'])
encode_lt = rc.encode(self.masked_image_lt)
- golden_axes = core.Axes([self.batch_axis, self.row_axis, self.column_axis,
- ('depth', len(self.channels) * len(self.masks))])
+ golden_axes = core.Axes([
+ self.batch_axis, self.row_axis, self.column_axis,
+ ('depth', len(self.channels) * len(self.masks))
+ ])
self.assertEqual(encode_lt.axes, golden_axes)
decode_lt = rc.decode(encode_lt)
@@ -81,12 +90,14 @@ class ReshapeCoderTest(Base):
def test_bijection_with_labels(self):
depth_axis = core.Axis('depth', range(len(self.channels) * len(self.masks)))
- rc = sugar.ReshapeCoder(['channel', 'mask'], [depth_axis,
- ('other', ['label'])])
+ rc = sugar.ReshapeCoder(['channel', 'mask'],
+ [depth_axis, ('other', ['label'])])
encode_lt = rc.encode(self.masked_image_lt)
- golden_axes = core.Axes([self.batch_axis, self.row_axis, self.column_axis,
- depth_axis, ('other', ['label'])])
+ golden_axes = core.Axes([
+ self.batch_axis, self.row_axis, self.column_axis, depth_axis,
+ ('other', ['label'])
+ ])
self.assertEqual(encode_lt.axes, golden_axes)
decode_lt = rc.decode(encode_lt)
@@ -103,4 +114,4 @@ class ReshapeCoderTest(Base):
if __name__ == '__main__':
- tf.test.main()
+ test.main()
diff --git a/tensorflow/contrib/labeled_tensor/python/ops/test_util.py b/tensorflow/contrib/labeled_tensor/python/ops/test_util.py
index 521314010e..8f0416030f 100644
--- a/tensorflow/contrib/labeled_tensor/python/ops/test_util.py
+++ b/tensorflow/contrib/labeled_tensor/python/ops/test_util.py
@@ -12,23 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
-
"""Utils for writing tests."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import tensorflow as tf
+from tensorflow.python.platform import test
+from tensorflow.python.training import coordinator
+from tensorflow.python.training import queue_runner_impl
-class Base(tf.test.TestCase):
+class Base(test.TestCase):
"""A class with some useful methods for testing."""
def eval(self, tensors):
with self.test_session() as sess:
- coord = tf.train.Coordinator()
- threads = tf.train.start_queue_runners(sess=sess, coord=coord)
+ coord = coordinator.Coordinator()
+ threads = queue_runner_impl.start_queue_runners(sess=sess, coord=coord)
try:
results = sess.run(tensors)