
import numpy as np
import tensorflow as tf

from skflow import ops


class DropoutTest(tf.test.TestCase):

    def test_dropout_float(self):
        with self.test_session():
            x = tf.placeholder(tf.float32, [5, 5])
            y = ops.dropout(x, 0.5)
            probs = tf.get_collection(ops.DROPOUTS)
            self.assertEqual(len(probs), 1)


if __name__ == '__main__':
    tf.test.main()


import numpy as np
import tensorflow as tf

from skflow import ops


class DropoutTest(tf.test.TestCase):

    def test_dropout_float(self):
        with self.test_session() as session:
            x = tf.placeholder(tf.float32, [5, 5])
            y = ops.dropout(x, 0.5)
            probs = tf.get_collection(ops.DROPOUTS)
            session.run(tf.initialize_all_variables())
            self.assertEqual(len(probs), 1)
            self.assertEqual(session.run(probs[0]), 0.5)

    def test_dropout_tensor(self):
        with self.test_session():
            x = tf.placeholder(tf.float32, [5, 5])
            y = tf.get_variable("prob", [], initializer=tf.constant_initializer(0.5))
            z = ops.dropout(x, y)
            probs = tf.get_collection(ops.DROPOUTS)
            self.assertEqual(probs, [y])


if __name__ == '__main__':
    tf.test.main()

Test for dropout probability be a tensor
Test for dropout probability be a tensor

  
  import numpy as np
  import tensorflow as tf
  
  from skflow import ops
  
  
  class DropoutTest(tf.test.TestCase):
  
      def test_dropout_float(self):
-         with self.test_session():
+         with self.test_session() as session:
              x = tf.placeholder(tf.float32, [5, 5])
              y = ops.dropout(x, 0.5)
              probs = tf.get_collection(ops.DROPOUTS)
+             session.run(tf.initialize_all_variables())
              self.assertEqual(len(probs), 1)
+             self.assertEqual(session.run(probs[0]), 0.5)
+ 
+     def test_dropout_tensor(self):
+         with self.test_session():
+             x = tf.placeholder(tf.float32, [5, 5])
+             y = tf.get_variable("prob", [], initializer=tf.constant_initializer(0.5))
+             z = ops.dropout(x, y)
+             probs = tf.get_collection(ops.DROPOUTS)
+             self.assertEqual(probs, [y])
  
  
  if __name__ == '__main__':
      tf.test.main()
  
Test for dropout probability be a tensor
## Code Before:

import numpy as np
import tensorflow as tf

from skflow import ops


class DropoutTest(tf.test.TestCase):

    def test_dropout_float(self):
        with self.test_session():
            x = tf.placeholder(tf.float32, [5, 5])
            y = ops.dropout(x, 0.5)
            probs = tf.get_collection(ops.DROPOUTS)
            self.assertEqual(len(probs), 1)


if __name__ == '__main__':
    tf.test.main()

## Instruction:
Test for dropout probability be a tensor
## Code After:

import numpy as np
import tensorflow as tf

from skflow import ops


class DropoutTest(tf.test.TestCase):

    def test_dropout_float(self):
        with self.test_session() as session:
            x = tf.placeholder(tf.float32, [5, 5])
            y = ops.dropout(x, 0.5)
            probs = tf.get_collection(ops.DROPOUTS)
            session.run(tf.initialize_all_variables())
            self.assertEqual(len(probs), 1)
            self.assertEqual(session.run(probs[0]), 0.5)

    def test_dropout_tensor(self):
        with self.test_session():
            x = tf.placeholder(tf.float32, [5, 5])
            y = tf.get_variable("prob", [], initializer=tf.constant_initializer(0.5))
            z = ops.dropout(x, y)
            probs = tf.get_collection(ops.DROPOUTS)
            self.assertEqual(probs, [y])


if __name__ == '__main__':
    tf.test.main()
