输出层代码:
Weights1 = tf.Variable(tf.random_normal([11, 4]))
biases1 = tf.Variable(tf.zeros([1, 4]) + 0.1)
Wx_plus_b1 = tf.matmul(l0, Weights1) + biases1
N1act = 2/(1+pow(math.e,-Wx_plus_b1[3]))-1
我想使用第四个节点的输出
这是我的自定义激活函数,它只需要一个输入。
prediction = tf_spiky(N1act)
错误信息:
raise ValueError(err.message)
ValueError: slice index 3 of dimension 0 out of bounds. for 'strided_slice' (op: 'StridedSlice') with input shapes: [1,4], [1], [1], [1] and with computed input tensors: input[1] = , input[2] = , input[3] = .
最佳答案
tf.matmul(l0, Weights1)
和 biases1
都具有形状 [1,4],因此 Wx_plus_b1
也是如此。也就是说,Wx_plus_b1
是一个一行四列的矩阵。当您编写 Wx_plus_b1[3]
时,您选择的是 Wx_plus_b1
的第 4 行,该行不存在,因此会出现错误。您要查找的值实际上是 Wx_plus_b1[0,3]
,即第一行第四列中的值。
关于python - 输出层有四个节点,但我想使用其中一个节点的输出,如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55114380/