python - 输出层有四个节点,但我想使用其中一个节点的输出,如何修复?

标签 python tensorflow

输出层代码:

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/

相关文章:

python - 仅当存在公共(public)索引时如何组合两个数据帧,否则保留空单元格

Python geopy 安装

python - 如何在 groupby 2 列之后保留 DataFrame 的原始索引?

python - Django 管理页面不显示数据库表(djangobook 第 06 章)

tensorflow - 在 Tensorflow、Theano、Pytorch 中使用的是 GEMM 还是 BLAS

tensorflow - 转换 Mozilla DeepSpeech 模型以在 tensorflow.js 环境中使用

python - Tensorflow 下一个词预测器错误

python - 如何使用现有模型的值初始化 slim.conv2d() 中的权重

tensorflow - 杀死tensorflow实例后如何获取 "reset"张量板数据

machine-learning - TensorFlow 中的堆叠 RNN 模型设置