Testing

Testing

Unit tests

TensorFlow provides a convenience class inheriting from unittest.TestCase which adds methods relevant to TensorFlow tests. Here is an example:

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 inherits from unittest.TestCase but adds a few additional methods. We will document these methods soon.

Utilities

Gradient checking

tf.test.compute_gradient and tf.test.compute_gradient_error perform numerical differentiation of graphs for comparison against registered analytic gradients.

© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_guides/python/test

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部