如何向神经网络层添加偏差

时间:2017-06-26 13:00:55

标签: python tensorflow

我有两个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

这种做法是否正确?

1 个答案:

答案 0 :(得分: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)

其中:

  • 输入为Const(10000,784)
  • 权重是可变的(784,1024)
  • bias是Variable(1024,)
  • data_entries_times_weights1 =输入*权重

解决方案

很可能 data_entries_times_weights1 等于输入。仔细检查data_entries_times_weights1是

data_entries_times_weights1 = tf.matmul( input , weights )
相关问题