diff --git a/CHANGELOG.md b/CHANGELOG.md index a556778ca..4a29d87ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ To release a new version, please update the changelog as followed: - Tutorials: - `tutorial_tfslim` has been introduced to show how to use `SlimNetsLayer` (by @2wins in #560). - Test: + - `test_utils_predict.py` added to reproduce and fix issue #288 (by @2wins in #566) - `Layer_DeformableConvolution_Test` added to reproduce issue #572 with deformable convolution (by @DEKHTIARJonathan in #573) - `Array_Op_Alphas_Test` and `Array_Op_Alphas_Like_Test` added to test `tensorlayer/array_ops.py` file (by @DEKHTIARJonathan in #580) - CI Tool: @@ -93,7 +94,8 @@ To release a new version, please update the changelog as followed: ### Fixed - Issue #498 - Deprecation Warning Fix in `tl.layers.RNNLayer` with `inspect` (by @DEKHTIARJonathan in #574) - Issue #498 - Deprecation Warning Fix in `tl.files` with truth value of an empty array is ambiguous (by @DEKHTIARJonathan in #575) -- Issue #572 with deformable convolution fixed (by @DEKHTIARJonathan in #573) +- Issue #565 related to `tl.utils.predict` fixed - `np.hstack` problem in which the results for multiple batches are stacked along `axis=1` (by @2wins in #566) +- Issue #572 with `tl.layers.DeformableConv2d` fixed (by @DEKHTIARJonathan in #573) - Typo of the document of ElementwiseLambdaLayer (by @zsdonghao in #588) ### Security diff --git a/tensorlayer/utils.py b/tensorlayer/utils.py index e316ca0d7..d65d36396 100644 --- a/tensorlayer/utils.py +++ b/tensorlayer/utils.py @@ -320,7 +320,7 @@ def predict(sess, network, X, x, y_op, batch_size=None): if result is None: result = result_a else: - result = np.hstack((result, result_a)) # TODO: https://github.com/tensorlayer/tensorlayer/issues/288 + result = np.concatenate((result, result_a)) if result is None: if len(X) % batch_size != 0: dp_dict = dict_to_one(network.all_drop) @@ -338,7 +338,7 @@ def predict(sess, network, X, x, y_op, batch_size=None): } feed_dict.update(dp_dict) result_a = sess.run(y_op, feed_dict=feed_dict) - result = np.hstack((result, result_a)) # TODO: https://github.com/tensorlayer/tensorlayer/issues/288 + result = np.concatenate((result, result_a)) return result diff --git a/tests/test_utils_predict.py b/tests/test_utils_predict.py new file mode 100644 index 000000000..dce212588 --- /dev/null +++ b/tests/test_utils_predict.py @@ -0,0 +1,51 @@ +import unittest + +try: + from tests.unittests_helper import CustomTestCase +except ImportError: + from unittests_helper import CustomTestCase + +import tensorflow as tf +import tensorlayer as tl +import numpy as np + + +class Util_Predict_Test(CustomTestCase): + + @classmethod + def setUpClass(cls): + cls.x1 = tf.placeholder(tf.float32, [None, 5, 5, 3]) + cls.x2 = tf.placeholder(tf.float32, [8, 5, 5, 3]) + cls.X1 = np.ones([127, 5, 5, 3]) + cls.X2 = np.ones([7, 5, 5, 3]) + cls.batch_size = 8 + + @classmethod + def tearDownClass(cls): + tf.reset_default_graph() + + def test_case1(self): + with self.assertNotRaises(Exception): + with tf.Session() as sess: + n = tl.layers.InputLayer(self.x1) + y = n.outputs + y_op = tf.nn.softmax(y) + tl.utils.predict(sess, n, self.X1, self.x1, y_op, batch_size=self.batch_size) + sess.close() + + def test_case2(self): + with self.assertRaises(Exception): + with tf.Session() as sess: + n = tl.layers.InputLayer(self.x2) + y = n.outputs + y_op = tf.nn.softmax(y) + tl.utils.predict(sess, n, self.X2, self.x2, y_op, batch_size=self.batch_size) + sess.close() + + +if __name__ == '__main__': + + # tf.logging.set_verbosity(tf.logging.INFO) + tf.logging.set_verbosity(tf.logging.DEBUG) + + unittest.main()