diff options
author | 2016-06-30 15:49:37 -0800 | |
---|---|---|
committer | 2016-06-30 17:04:57 -0700 | |
commit | aabfe1d03ec518269f1b28793f70e4a95eb52574 (patch) | |
tree | ca6fb9eddc4774cfaad76c000d1081abf4880c2e /tensorflow/python/kernel_tests/sparse_xent_op_test.py | |
parent | 69abcd7ec28c8f6a58576d95fd59a8c7c537ade5 (diff) |
Fix sparse_softmax_cross_entropy_with_logits for empty tensor
If the batch size is zero, we need to avoid calling into Eigen because Eigen
will explode. Zero classes is an error.
Change: 126359444
Diffstat (limited to 'tensorflow/python/kernel_tests/sparse_xent_op_test.py')
-rw-r--r-- | tensorflow/python/kernel_tests/sparse_xent_op_test.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tensorflow/python/kernel_tests/sparse_xent_op_test.py b/tensorflow/python/kernel_tests/sparse_xent_op_test.py index eb6bdff8b5..ea379fbac0 100644 --- a/tensorflow/python/kernel_tests/sparse_xent_op_test.py +++ b/tensorflow/python/kernel_tests/sparse_xent_op_test.py @@ -120,6 +120,13 @@ class SparseXentTest(tf.test.TestCase): tf.nn.sparse_softmax_cross_entropy_with_logits( tf.constant(1.0), tf.constant(0)) + def testLabelsPlaceholderScalar(self): + with self.test_session(): + labels = tf.placeholder(np.int32) + y = tf.nn.sparse_softmax_cross_entropy_with_logits([[7.]], labels) + with self.assertRaisesOpError("labels must be 1-D"): + y.eval(feed_dict={labels: 0}) + def testVector(self): with self.test_session(): loss = tf.nn.sparse_softmax_cross_entropy_with_logits( @@ -145,6 +152,9 @@ class SparseXentTest(tf.test.TestCase): np.array([[1., 1., 1., 1.], [1., 2., 3., 4.]]).astype(np.float16), np.array([3, 0]).astype(label_dtype)) + def testEmpty(self): + self._testXent(np.zeros((0, 3)), np.zeros((0,), dtype=np.int32)) + def testGradient(self): with self.test_session(): l = tf.constant([3, 0, 1], name="l") |