def testNoInts(self): with self.cached_session(): with self.assertRaisesRegexp( TypeError, "'features' has DataType int32 not in list of allowed values" ): nn_ops.softsign(constant_op.constant(7)).eval()
def _testSoftsign(self, np_features, use_gpu=False): np_softsign = self._npSoftsign(np_features) with self.cached_session(use_gpu=use_gpu): softsign = nn_ops.softsign(np_features) tf_softsign = self.evaluate(softsign) self.assertAllClose(np_softsign, tf_softsign) self.assertShapeEqual(np_softsign, softsign)
def testGradient(self): with self.test_session(): x = constant_op.constant([-0.9, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9], shape=[2, 5], name="x") y = nn_ops.softsign(x, name="softsign") x_init = np.asarray( [[-0.9, -0.7, -0.5, -0.3, -0.1], [0.1, 0.3, 0.5, 0.7, 0.9]], dtype=np.float32, order="F" ) err = gradient_checker.compute_gradient_error(x, [2, 5], y, [2, 5], x_init_value=x_init) print("softsign (float) gradient err = ", err) self.assertLess(err, 1e-4)
def testGradient(self): with self.cached_session(): x = constant_op.constant( [-0.9, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9], shape=[2, 5], name="x") y = nn_ops.softsign(x, name="softsign") x_init = np.asarray( [[-0.9, -0.7, -0.5, -0.3, -0.1], [0.1, 0.3, 0.5, 0.7, 0.9]], dtype=np.float32, order="F") err = gradient_checker.compute_gradient_error( x, [2, 5], y, [2, 5], x_init_value=x_init) print("softsign (float) gradient err = ", err) self.assertLess(err, 1e-4)
def testNoInts(self): with self.cached_session(): with self.assertRaisesRegexp( TypeError, "'features' has DataType int32 not in list of allowed values"): nn_ops.softsign(constant_op.constant(7)).eval()
def testNoInts(self): with self.cached_session(): with self.assertRaisesRegexp( errors.InvalidArgumentError, "No OpKernel was registered to support Op 'Softsign'"): nn_ops.softsign(constant_op.constant(7)).eval()
def testWarnInts(self): # NOTE(irving): Actually I don't know how to intercept the warning, but # let's make sure it runs. I promised I've looked, and there was a warning. with self.test_session(): nn_ops.softsign(constant_op.constant(7)).eval()
def testNoInts(self): with self.test_session(): with self.assertRaisesRegexp( errors.InvalidArgumentError, "No OpKernel was registered to support Op 'Softsign'"): nn_ops.softsign(constant_op.constant(7)).eval()