nn_test.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:imperative 作者: yaroslavvb 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号