Esempio n. 1
0
 def testCustomNoiseShape(self):
     inputs = array_ops.ones((5, 3, 2))
     noise_shape = [5, 1, 2]
     dp = core_layers.Dropout(0.5, noise_shape=noise_shape, seed=1)
     dropped = dp.apply(inputs, training=True)
     self.evaluate(variables.global_variables_initializer())
     np_output = self.evaluate(dropped)
     self.assertAlmostEqual(0., np_output.min())
     self.assertAllClose(np_output[:, 0, :], np_output[:, 1, :])
Esempio n. 2
0
 def testDynamicRate(self):
     with self.cached_session() as sess:
         rate = array_ops.placeholder(dtype='float32', name='rate')
         dp = core_layers.Dropout(rate, name='dropout')
         inputs = array_ops.ones((5, 5))
         dropped = dp.apply(inputs, training=True)
         self.evaluate(variables.global_variables_initializer())
         np_output = sess.run(dropped, feed_dict={rate: 0.5})
         self.assertAlmostEqual(0., np_output.min())
         np_output = sess.run(dropped, feed_dict={rate: 0.0})
         self.assertAllClose(np.ones((5, 5)), np_output)
Esempio n. 3
0
 def testBooleanLearningPhase(self):
     dp = core_layers.Dropout(0.5)
     inputs = array_ops.ones((5, 3))
     dropped = dp.apply(inputs, training=True)
     if not context.executing_eagerly():
         self.evaluate(variables.global_variables_initializer())
     np_output = self.evaluate(dropped)
     self.assertAlmostEqual(0., np_output.min())
     dropped = dp.apply(inputs, training=False)
     np_output = self.evaluate(dropped)
     self.assertAllClose(np.ones((5, 3)), np_output)
Esempio n. 4
0
 def testDynamicLearningPhase(self):
     with self.cached_session() as sess:
         dp = core_layers.Dropout(0.5, seed=1)
         inputs = array_ops.ones((5, 5))
         training = array_ops.placeholder(dtype='bool')
         dropped = dp.apply(inputs, training=training)
         self.evaluate(variables.global_variables_initializer())
         np_output = sess.run(dropped, feed_dict={training: True})
         self.assertAlmostEqual(0., np_output.min())
         np_output = sess.run(dropped, feed_dict={training: False})
         self.assertAllClose(np.ones((5, 5)), np_output)
Esempio n. 5
0
 def testDropoutProperties(self):
     dp = core_layers.Dropout(0.5, name='dropout')
     self.assertEqual(dp.rate, 0.5)
     self.assertEqual(dp.noise_shape, None)
     dp.apply(array_ops.ones(()))
     self.assertEqual(dp.name, 'dropout')