'Tensor conversion of bool type to int type error
I'm doing an ML practice project using tensorflow to create a model. I am stuck at a problem where i have to create a filter_mask (bool) and then multiply it to data but i'm getting the following error or running. I'm not very familiar with tensorflow, i know that normally you can just multiply boolean values with integers and they act like 1 and 0. Is it different with tensorflow? How do I get past the problem?
Tensor conversion requested dtype bool for Tensor with dtype float32: 'Tensor("mul_2:0", shape=(19, 19, 5, 80), dtype=float32)'
Solution 1:[1]
I mean a simple fix is just to cast your boolean array to floats and do the multiplication:
tensor = tf.cast(tensor, tf.float32)
Solution 2:[2]
tf.math.greater return True or False value
print( tf.where(tf.math.greater( np.asarray(y1, dtype=np.float32), np.asarray(previous_cell, dtype=np.float32)), [1.0], [0.0]).numpy() )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Will.Evo |
Solution 2 | Martijn Pieters |