nit*_*tin 5 python numpy machine-learning tensorflow
我正在尝试进行逻辑回归,我的训练数据集来自一个numpy float64数组.我的代码看起来像,
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
Run Code Online (Sandbox Code Playgroud)
这引发了一个例外
TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type float64 of argument 'a'.
Run Code Online (Sandbox Code Playgroud)
这可能是因为W和b是float32而不是float64.有没有办法转换W和b或创建它作为float64
要使其工作,您应该使用初始值定义W和b变量tf.float64.的tf.truncated_normal()和tf.zeros()OPS每一个可选dtype的是可以被设置为参数tf.float64,如下所示:
W = tf.Variable(tf.truncated_normal([115713, 2], dtype=tf.float64))
b = tf.Variable(tf.zeros([2], dtype=tf.float64))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10410 次 |
| 最近记录: |