|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
-
- import os
- import unittest
-
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
-
- import tensorflow as tf
- import tensorlayer as tl
-
- import numpy as np
-
- from tests.utils import CustomTestCase
-
-
- class Array_Op_Alphas_Test(CustomTestCase):
-
- @classmethod
- def setUpClass(cls):
-
- b1 = tl.alphas([4, 3, 2, 1], 0.5431)
- b2 = tl.alphas([4, 3, 2], 5)
- b3 = tl.alphas([1, 2, 3, 4], -5)
- b4 = tl.alphas([2, 3, 4], True)
-
- with tf.Session() as sess:
- cls._b1, cls._b2, cls._b3, cls._b4 = sess.run([b1, b2, b3, b4])
-
- @classmethod
- def tearDownClass(cls):
- tf.reset_default_graph()
-
- def test_b1(self):
- self.assertEqual(self._b1.shape, (4, 3, 2, 1))
-
- b1 = np.array(
- [
- [
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- ], [
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- ], [
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- ], [
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- [
- [0.5431],
- [0.5431],
- ],
- ]
- ]
- )
-
- np.array_equal(self._b1, b1)
-
- def test_b2(self):
- self.assertEqual(self._b2.shape, (4, 3, 2))
-
- b2 = np.array(
- [
- [
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- ], [
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- ], [
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- ], [
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- [
- 5,
- 5,
- ],
- ]
- ]
- )
-
- np.array_equal(self._b2, b2)
-
- def test_b3(self):
- self.assertEqual(self._b3.shape, (1, 2, 3, 4))
-
- b3 = np.array(
- [
- [
- [[-5, -5, -5, -5], [-5, -5, -5, -5], [-5, -5, -5, -5]],
- [[-5, -5, -5, -5], [-5, -5, -5, -5], [-5, -5, -5, -5]],
- ]
- ]
- )
-
- np.array_equal(self._b3, b3)
-
- def test_b4(self):
- self.assertEqual(self._b4.shape, (2, 3, 4))
-
- b4 = np.array(
- [
- [[True, True, True, True], [True, True, True, True], [True, True, True, True]],
- [[True, True, True, True], [True, True, True, True], [True, True, True, True]],
- ]
- )
-
- np.array_equal(self._b4, b4)
-
-
- class Array_Op_Alphas_Like_Test(CustomTestCase):
-
- @classmethod
- def setUpClass(cls):
- a = tf.constant([[[4, 5, 6], [1, 2, 3]], [[4, 5, 6], [1, 2, 3]]])
-
- b1 = tl.alphas_like(a, 0.5431)
- b2 = tl.alphas_like(a, 5)
- b3 = tl.alphas_like(a, -5)
- b4 = tl.alphas_like(a, True)
-
- with tf.Session() as sess:
- cls._b1, cls._b2, cls._b3, cls._b4 = sess.run([b1, b2, b3, b4])
-
- @classmethod
- def tearDownClass(cls):
- tf.reset_default_graph()
-
- def test_b1(self):
- self.assertEqual(self._b1.shape, (2, 2, 3))
-
- b1 = np.array(
- [
- [[0.5431, 0.5431, 0.5431], [0.5431, 0.5431, 0.5431]],
- [[0.5431, 0.5431, 0.5431], [0.5431, 0.5431, 0.5431]]
- ]
- )
-
- np.array_equal(self._b1, b1)
-
- def test_b2(self):
- self.assertEqual(self._b2.shape, (2, 2, 3))
-
- b2 = np.array([[[5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5]]])
-
- np.array_equal(self._b2, b2)
-
- def test_b3(self):
- self.assertEqual(self._b3.shape, (2, 2, 3))
-
- b3 = np.array([[[-5, -5, -5], [-5, -5, -5]], [[-5, -5, -5], [-5, -5, -5]]])
-
- np.array_equal(self._b3, b3)
-
- def test_b4(self):
- self.assertEqual(self._b4.shape, (2, 2, 3))
-
- b4 = np.array([[[True, True, True], [True, True, True]], [[True, True, True], [True, True, True]]])
-
- np.array_equal(self._b4, b4)
-
-
- if __name__ == '__main__':
-
- tf.logging.set_verbosity(tf.logging.DEBUG)
- tl.logging.set_verbosity(tl.logging.DEBUG)
-
- unittest.main()
|