I am trying to do a logistic regression and my training dataset is derived from a a numpy float64 array. My code looks like,
import tensorflow as tf
graph = tf.Graph()
with graph.as_default():
examples =tf.constant(mat6) # mat6 is a numpy float64 array
t_labels = tf.constant(labels) # labels is an a numpy float64 array
W = tf.Variable(tf.truncated_normal([115713, 2]))
b = tf.Variable(tf.zeros([2]))
logits = tf.matmul(examples, W)+b
This throws an exception
TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type float64 of argument 'a'.
This probably because W and b are float32 and not float64. Is there a way to convert W and b OR create it as a float64
Tensorflow variables represent the tensors whose values can be changed by running operations on them. The assign() is the method available in the Variable class which is used to assign the new tf. Tensor to the variable. The new value must have the same shape and dtype as the old Variable value.
From my understanding, trainable means that the value could be changed during sess.run() That is not the definition of a trainable variable. Any variable can be modified during a sess. run() (That's why they are variables and not constants).
In TensorFlow the differences between constants and variables are that when you declare some constant, its value can't be changed in the future (also the initialization should be with a value, not with operation). Nevertheless, when you declare a Variable, you can change its value in the future with tf.
To make this work, you should define the W
and b
variables with tf.float64
initial values. The tf.truncated_normal()
and tf.zeros()
ops each take an optional dtype
argument that can be set to tf.float64
as follows:
W = tf.Variable(tf.truncated_normal([115713, 2], dtype=tf.float64))
b = tf.Variable(tf.zeros([2], dtype=tf.float64))
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