报错:using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution

原因:

if tf.equal(self.optimizer.iterations % log_freq, 0):
	pass

tensorflow版本:1.15.0
由于python的if语句是通过bool类型判断的,而tf.equal()返回的是Tensor张量类型,所以报错
解决:

myflag = tf.cond(tf.equal(self.optimizer.iterations % log_freq, 0), lambda: True, lambda: False)
if myflag:
	pass

你可能感兴趣的:(tensorflow,算法,深度学习,keras)