def testSoftmax(self):
x_shape = [5, 10]
x_np = np.random.randn(*x_shape).astype(np.float32)
y_np = self._softmax(x_np)
with self.test_session():
x_tf = tf.constant(x_np)
y_tf = tf.nn.softmax(x_tf)
y_tf_np = y_tf.eval()
eps = 1e-3
self.assertAllClose(y_tf_np, y_np, eps)
# def testGradient(self):
# x_shape = [5, 10]
# x_np = np.random.randn(*x_shape).astype(np.float64)
# with self.test_session():
# x_tf = tf.constant(x_np)
# y_tf = tf.nn.softmax(x_tf)
# err = tf.test.compute_gradient_error(x_tf, x_shape, y_tf, x_shape)
# eps = 1e-8
# self.assertLess(err, eps)
# use work-around from https://github.com/tensorflow/tensorflow/issues/2511
评论列表
文章目录