Example #1
0
 def testInvalidKeepProb(self):
   x_dim, y_dim = 40, 30
   t = constant_op.constant(1.0, shape=[x_dim, y_dim], dtype=dtypes.float32)
   with self.assertRaises(ValueError):
     alpha_dropout(t, -1.0)
   with self.assertRaises(ValueError):
     alpha_dropout(t, 1.1)
   with self.assertRaises(ValueError):
     alpha_dropout(t, [0.0, 1.0])
   with self.assertRaises(ValueError):
     alpha_dropout(t, array_ops.placeholder(dtypes.float64))
   with self.assertRaises(ValueError):
     alpha_dropout(t, array_ops.placeholder(dtypes.float32, shape=[2]))
 def testInvalidKeepProb(self):
   x_dim, y_dim = 40, 30
   t = constant_op.constant(1.0, shape=[x_dim, y_dim], dtype=dtypes.float32)
   with self.assertRaises(ValueError):
     alpha_dropout(t, -1.0)
   with self.assertRaises(ValueError):
     alpha_dropout(t, 1.1)
   with self.assertRaises(ValueError):
     alpha_dropout(t, [0.0, 1.0])
   with self.assertRaises(ValueError):
     alpha_dropout(t, array_ops.placeholder(dtypes.float64))
   with self.assertRaises(ValueError):
     alpha_dropout(t, array_ops.placeholder(dtypes.float32, shape=[2]))
 def testAlphaDropout(self):
     x_dim, y_dim = 40, 30
     for keep_prob in [0.1, 0.5, 0.8]:
         with self.test_session():
             t = random_ops.random_normal([x_dim, y_dim])
             output = alpha_dropout(t, keep_prob)
             self.assertEqual([x_dim, y_dim], output.get_shape())
             t_mean, t_std = nn_impl.moments(t, axes=[0, 1])
             output_mean, output_std = nn_impl.moments(output, axes=[0, 1])
             self.assertLess(abs(t_mean.eval() - output_mean.eval()), 0.1)
             self.assertLess(abs(t_std.eval() - output_std.eval()), 0.1)
 def testAlphaDropout(self):
   x_dim, y_dim = 40, 30
   for keep_prob in [0.1, 0.5, 0.8]:
     with self.test_session():
       t = random_ops.random_normal([x_dim, y_dim])
       output = alpha_dropout(t, keep_prob)
       self.assertEqual([x_dim, y_dim], output.get_shape())
       t_mean, t_std = nn_impl.moments(t, axes=[0, 1])
       output_mean, output_std = nn_impl.moments(output, axes=[0, 1])
       self.assertLess(abs(t_mean.eval() - output_mean.eval()), 0.1)
       self.assertLess(abs(t_std.eval() - output_std.eval()), 0.1)
Example #5
0
  def testShapedDropoutShapeError(self):
    # Runs shaped dropout and verifies an error is thrown on misshapen noise.
    x_dim = 40
    y_dim = 30
    keep_prob = 0.5
    t = constant_op.constant(1.0, shape=[x_dim, y_dim], dtype=dtypes.float32)
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, y_dim + 10])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, y_dim, 5])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim + 3])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim])

    # test that broadcasting proceeds
    _ = alpha_dropout(t, keep_prob, noise_shape=[y_dim])
    _ = alpha_dropout(t, keep_prob, noise_shape=[1, y_dim])
    _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, 1])
    _ = alpha_dropout(t, keep_prob, noise_shape=[1, 1])
  def testShapedDropoutShapeError(self):
    # Runs shaped dropout and verifies an error is thrown on misshapen noise.
    x_dim = 40
    y_dim = 30
    keep_prob = 0.5
    t = constant_op.constant(1.0, shape=[x_dim, y_dim], dtype=dtypes.float32)
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, y_dim + 10])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, y_dim, 5])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim + 3])
    with self.assertRaises(ValueError):
      _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim])

    # test that broadcasting proceeds
    _ = alpha_dropout(t, keep_prob, noise_shape=[y_dim])
    _ = alpha_dropout(t, keep_prob, noise_shape=[1, y_dim])
    _ = alpha_dropout(t, keep_prob, noise_shape=[x_dim, 1])
    _ = alpha_dropout(t, keep_prob, noise_shape=[1, 1])
 def testNoDropoutFast(self):
     x = array_ops.zeros((5, ))
     for p in 1, constant_op.constant(1.0):
         y = alpha_dropout(x, keep_prob=p)
         self.assertTrue(x is y)
 def testNoDropoutFast(self):
   x = array_ops.zeros((5,))
   for p in 1, constant_op.constant(1.0):
     y = alpha_dropout(x, keep_prob=p)
     self.assertTrue(x is y)