What Does Invalidargumenterror In Tensorflow 2 Mean?
I am new tensorflow. I am trying to implement Linear Regression with custom training, following this tutorial. But when I try to compute W*x + b I am getting this error tf.add(tf
Solution 1:
The result of np.random.rand(1,9)
(and other initializations) is of type np.float64
. Using this with tf.Variable
gives a tensor of type tf.float64
.
The parameters to Tensorflow's add
must be of the same type. The result of matmul
is of type tf.float64
and b
is of type tf.float32
. You need to cast one to the other's type.
In Tensorflow, you can either do this (recommended, going by convention):
# Can be done in a single line too
matmul_result = tf.matmul(W,x)
matmul_result = tf.cast(matmul_result, tf.float32)
tf.add(matmul_result, b)
Or you can do this:
tf.add(tf.matmul(W,x), tf.cast(b, tf.float64))
You can also directy change the type of numpy's array:
W = tf.Variable(np.random.rand(1,9).astype(np.float32))
Post a Comment for "What Does Invalidargumenterror In Tensorflow 2 Mean?"