From 0a3fd5b62065333669c7b391c626cb2505217617 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Fri, 12 Aug 2016 16:48:46 -0400 Subject: First commit --- Code/tfutils_test.py | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Code/tfutils_test.py (limited to 'Code/tfutils_test.py') diff --git a/Code/tfutils_test.py b/Code/tfutils_test.py new file mode 100644 index 0000000..4e2b490 --- /dev/null +++ b/Code/tfutils_test.py @@ -0,0 +1,102 @@ +from tfutils import * + +imgs = tf.constant(np.ones([2, 2, 2, 3])) +sess = tf.Session() + + +# noinspection PyClassHasNoInit,PyMethodMayBeStatic +class TestPad: + def test_rb(self): + res = sess.run(batch_pad_to_bounding_box(imgs, 0, 0, 4, 4)) + assert np.array_equal(res, np.array([[[[1, 1, 1], + [1, 1, 1], + [0, 0, 0], + [0, 0, 0]], + [[1, 1, 1], + [1, 1, 1], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + ], + [[[1, 1, 1], + [1, 1, 1], + [0, 0, 0], + [0, 0, 0]], + [[1, 1, 1], + [1, 1, 1], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + ]], dtype=float)) + + def test_center(self): + res = sess.run(batch_pad_to_bounding_box(imgs, 1, 1, 4, 4)) + assert np.array_equal(res, np.array([[[[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1], + [1, 1, 1], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1], + [1, 1, 1], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + ], + [[[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1], + [1, 1, 1], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1], + [1, 1, 1], + [0, 0, 0]], + [[0, 0, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + ]], dtype=float)) + + +padded = batch_pad_to_bounding_box(imgs, 1, 1, 4, 4) + + +# noinspection PyClassHasNoInit +class TestCrop: + def test_rb(self): + res = sess.run(batch_crop_to_bounding_box(padded, 0, 0, 2, 2)) + assert np.array_equal(res, np.array([[[[0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1]]], + [[[0, 0, 0], + [0, 0, 0]], + [[0, 0, 0], + [1, 1, 1]]]])) + + def test_center(self): + res = sess.run(batch_crop_to_bounding_box(padded, 1, 1, 2, 2)) + assert np.array_equal(res, np.ones([2, 2, 2, 3])) -- cgit v1.2.3-70-g09d2