【问题标题】:threre are four nodes in output layer, but I want to use one of the node' s output, how can I fix it?输出层有四个节点,但我想使用其中一个节点的输出,我该如何解决?
【发布时间】:2019-03-12 04:49:02
【问题描述】:

输出层代码:

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) 

错误信息:

引发 ValueError(err.message)

ValueError: 维度 0 的切片索引 3 超出范围。为了 'strided_slice' (op: 'StridedSlice') 输入形状:[1,4], [1], [1], [1] 和计算输入张量: input[1] = , input[2] = , 输入[3] = .

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    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],即第一行第四列中的值。

    【讨论】:

    • 谢谢你的回答,但是你的方法不行。我把 Wx_plus_b1[3] 改成了 Wx_plus_b1[0,3],然后出现错误,这是 Expected binary or unicode string, got 跨度>
    • 我试图对张量进行 tf.split,但出现了同样的错误,即 Expected binary or unicode string, got ,似乎 tf.spilt 没有拆分张量
    • 这似乎是另一个错误。如果您完全消除 Wx_plus_b1[3] 及其变体会发生什么?例如。设置 N1act = 2/(1+pow(math.e,1))-1 或 N1act = 1 看看是否仍然出现错误。根据错误消息,我的猜测是 N1act 是正确的,而问题出在其他地方。
    • 设置 N1act = 2/(1+pow(math.e,1))-1 或 N1act = 1 将导致没有为任何变量提供梯度的错误,如果我更改数字将输出从 4 变为 1,网络可以完美运行。所以我认为问题的根源是我没有成功拆分张量。
    猜你喜欢
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多