TensorFlow 測試

2019-01-31 18:13 更新

單元測試

TensorFlow 提供了一個方便的類,繼承 unittest.TestCase,可以添加與 TensorFlow 測試相關(guān)的方法。如下述的例子: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 對圖進行數(shù)值微分,以便與已注冊的分析梯度進行比較。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號