Reputation: 1488
I have a tensor that holds density values and when evaluated in a session takes values in (0,1e-31). Then I apply tf.log elementwise on the tensor and when evaluating this tensor I get a couple of elements having -inf.
The smallest value of my tensor, before applying the log, when evaluated is 1.4012985e-45, then after the log I get -inf.
What could this be? I thought it might have been caused because I was using tf.float32, but changing to float64 still resulted in -inf values.
EDIT: The problem was in fact caused by too low precision. Using tf.float64 on all placeholders and variables on the graph resulted in no -inf values.
Upvotes: 1
Views: 1944
Reputation: 1488
Tensorflow outputs -inf when evaluating a tf.log op on tensors of type tf.float32 with very small values (~1e-50). To prevent this problem, you should use tf.float64 on all variables in your graph.
Upvotes: 1