2017-06-26 34 views
-1

我有两个tf.Variable如何偏见添加到神经网络层

data_entries_times_weights1 
biases1 

他们有形状:

(10000, 1024) 
(1024,) 

然而,当我乘他们是这样的:

lay1_valid = tf.nn.relu(data_entries_times_weights1 + biases1) 

我收到:

ValueError: Tensor("Variable:0", shape=(784, 1024), dtype=float32_ref) must be from the same graph as Tensor("Const:0", shape=(10000, 784), dtype=float32). 

从我在Github上看到的,人们都以类似的方式添加偏见,如:data_entries_times_weights1 + biases1

这种方法是否正确?

+0

这是正确的。问题在于'data_entries_times_weights1'在图形中定义,而'biases1'在另一个图形中定义 – nessuno

+1

您可以显示整个代码吗? – nessuno

+0

重复https://stackoverflow.com/questions/44757650/multiplying-two-tensors –

回答

0

问题

我收到以下错误消息

ValueError: Tensor("Variable:0", shape=(784, 1024), dtype=float32_ref) must be from the same graph as Tensor("Const:0", shape=(10000, 784), dtype=float32). 

,我试图做类似

lay1_valid = tf.nn.relu(data_entries_times_weights1 + biases) 

其中:

  • 输入为常量(10000,784)
  • 权重是可变的(784,1024)
  • 偏压是变量(1024,)
  • data_entries_times_weights1 =输入*加权

最有可能的data_entries_times_weights1等于输入。仔细检查data_entries_times_weights1是否为

data_entries_times_weights1 = tf.matmul(input , weights) 
+0

这是否回答你的问题? – Wontonimo