Following is my code:
...
result=tf.div(product_norm,denom)
if(result>0.5):
result=1
else:
result=0
return result
If the value in a tensor is less than 0.5 then it should be replaced with 0 otherwise 1. But it keeps returning the error.
TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
In this simple case, you can use
result = tf.cast(result + 0.5, tf.int32)
When if-statement becomes more complex, consider using tf.cond
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With