0
我測試TF,當我測試除了我得到:Tensorflow測試失敗
E AssertionError:
E Arrays are not equal
E
E (mismatch 100.0%)
E x: array(4.099999904632568, dtype=float32)
E y: array(4.1)
如果我改變從3.1測試3.0,它的工作原理?任何建議
代碼
import tensorflow as tf
import unittest
def sum_op(param1, param2):
return tf.add(param1, param2)
with tf.Graph().as_default():
result = sum_op(tf.constant(1.0), tf.Variable(2.0))
with tf.Session() as sess:
tf.global_variables_initializer().run()
print sess.run(result)
class AddTest(tf.test.TestCase):
def testAdd(self):
with self.test_session() as sess:
self.assertAllEqual(sum_op(1.0, 3.1).eval(), 4.1)
suite = unittest.TestLoader().loadTestsFromTestCase(AddTest)
unittest.TextTestRunner(verbosity=2).run(suite)
我使用了assertAlmostEqual和delta選項 – spicyramen