def testGradients(self): shape = [5, 3, 4] sigma = 5 input_values = np.random.randn(*shape) * sigma x_tf = constant_op.constant(input_values) y_tf = nn_impl.swish(x_tf) with self.test_session(): err = gradient_checker.compute_gradient_error(x_tf, shape, y_tf, shape) self.assertLess(err, 1e-4)
def testValues(self): np_values = np.array( [np.linspace(-10.0, 0.0, 100), np.linspace(0.0, 10.0, 100)], dtype=np.float32) tf_values = constant_op.constant(np_values) actual_tf_outputs = nn_impl.swish(tf_values) expected_tf_outputs = tf_values * math_ops.sigmoid(tf_values) with self.test_session() as sess: actual_outputs, expected_outputs = sess.run( [actual_tf_outputs, expected_tf_outputs]) self.assertAllClose(actual_outputs, expected_outputs)