阅读(2736) (2)

TensorFlow 测试

2017-08-26 17:13:52 更新

单元测试

TensorFlow 提供了一个方便的类,继承 unittest.TestCase,可以添加与 TensorFlow 测试相关的方法。如下述的例子:tf.

import tensorflow as tf

class SquareTest(tf.test.TestCase):

  def testSquare(self):
    with self.test_session():
      x = tf.square([2, 3])
      self.assertAllEqual(x.eval(), [4, 9])

if __name__ == '__main__':
  tf.test.main()

tf.test.TestCase 继承了 unittest.TestCase,但添加了一些额外的方法,我们将很快证明这些方法。

  • tf.test.main
  • tf.test.TestCase
  • tf.test.test_src_dir_path

TensorFlow 实用程序

  • tf.test.assert_equal_graph_def
  • tf.test.get_temp_dir
  • tf.test.is_built_with_cuda
  • tf.test.is_gpu_available
  • tf.test.gpu_device_name

TensorFlow 梯度检测

tf.test.compute_gradient 和 tf.test.compute_gradient_error 对图进行数值微分,以便与已注册的分析梯度进行比较。