tensorflow 中 softmax 上的 InvalidArgumentError

优素福

我有以下功能:

def forward_propagation(self, x):
                # The total number of time steps
                T = len(x)
                # During forward propagation we save all hidden states in s because need them later.
                # We add one additional element for the initial hidden, which we set to 0
                s = tf.zeros([T+1, self.hidden_dim])
                # The outputs at each time step. Again, we save them for later.
                o = tf.zeros([T, self.word_dim])


                a = tf.placeholder(tf.float32)
                b = tf.placeholder(tf.float32)
                c = tf.placeholder(tf.float32)

                s_t = tf.nn.tanh(a + tf.reduce_sum(tf.multiply(b, c)))
                o_t = tf.nn.softmax(tf.reduce_sum(tf.multiply(a, b)))
                # For each time step...
                with tf.Session() as sess:
                        s = sess.run(s)
                        o = sess.run(o)
                        for t in range(T):
                                # Note that we are indexing U by x[t]. This is the same as multiplying U with a one-hot vector.
                                s[t] = sess.run(s_t, feed_dict={a: self.U[:, x[t]], b: self.W, c: s[t-1]})
                                o[t] = sess.run(o_t, feed_dict={a: self.V, b: s[t]})
                return [o, s]

self.U、self.V 和 self.W 是 numpy 数组。我尝试打开 softmax

o_t = tf.nn.softmax(tf.reduce_sum(tf.multiply(a, b)))

图形,它在这一行给了我错误:

o[t] = sess.run(o_t, feed_dict={a: self.V, b: s[t]})

错误是:

InvalidArgumentError(回溯见上文):当 input.dim_size(0) == 0
[[Node: Slice = Slice [Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](Shape_1, Slice/begin, Slice/size)]]

我应该如何在 tensorflow 中获得 softmax?

致霍夫曼

问题出现是因为您调用tf.reduce_sum了 的参数tf.nn.softmax结果,softmax 函数失败,因为标量不是有效的输入参数。您的意思是使用tf.matmul的,而不是组合tf.reduce_sumtf.multiply

编辑:Tensorflow 不提供开箱即用的等效项np.dot如果要计算矩阵和向量的点积,则需要明确地对索引求和:

# equivalent to np.dot(a, b) if a.ndim == 2 and b.ndim == 1
c = tf.reduce_sum(a * b, axis=1)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Tensorflow中带有model.fit的InvalidArgumentError

来自分类Dev

Tensorflow:占位符的InvalidArgumentError

来自分类Dev

在Tensorflow中,sampled_softmax_loss和softmax_cross_entropy_with_logits有什么区别

来自分类Dev

(使用Keras)的Tensorflow中``InvalidArgumentError:不兼容的形状:[10,2]与[10]”的原因是什么?

来自分类Dev

Tensorflow - 在经过训练的 softmax 分类模型上检测多个对象

来自分类Dev

如何在tensorflow中打印张量的值mnist_softmax.py

来自分类Dev

如何在tensorflow中打印张量的值mnist_softmax.py

来自分类Dev

Tensorflow错误:InvalidArgumentError:不同数量的组件类型。

来自分类Dev

Tensorflow:带有MNIST的InvalidArgumentError,[55000]与[10000]

来自分类Dev

tensorflow.python.framework.errors_impl.InvalidArgumentError:预期的大小[0]在[0,512]中,但得到891 [Op:Slice]

来自分类Dev

如何使用Tensorflow.JS实现softmax

来自分类Dev

激活='softmax'时了解tensorflow keras LSTM

来自分类Dev

Tensorflow SoftMax不会忽略掩码值

来自分类Dev

Tensorflow:用于自定义 softmax 的 NaN

来自分类Dev

消除类似DeepMNIST的网络中的softmax饱和度,以便在TensorFlow中进行彩色图像分类

来自分类Dev

在OSX上的Virtualenv中安装TensorFlow

来自分类Dev

在Windows上无法在Docker中启动TensorFlow

来自分类Dev

tensorflow.python.framework.errors_impl.InvalidArgumentError如何解决?

来自分类Dev

TensorFlow InvalidArgumentError/Value 错误随着代码的微小变化而发生

来自分类Dev

Keras LSTM在每个单元上使用softmax

来自分类Dev

在神经元子集上应用 softmax

来自分类Dev

对象检测上的 Sigmoid 与 Softmax 交叉熵

来自分类Dev

InvalidArgumentError:默认MaxPoolingOp仅在设备类型CPU上支持NHWC

来自分类Dev

Tensorflow softmax_cross ...()函数浮点类型错误

来自分类Dev

Tensorflow对于简单的softmax模型,参数值没有变化

来自分类Dev

如何在Tensorflow中使用sampled_softmax_loss

来自分类Dev

Tensorflow CNN - 密集层作为 Softmax 层输入

来自分类Dev

为什么 tensorflow 对 softmax 函数使用“dim”参数?

来自分类Dev

在 Tensorflow 和 Keras 的两个通道上生成 softmax

Related 相关文章

  1. 1

    Tensorflow中带有model.fit的InvalidArgumentError

  2. 2

    Tensorflow:占位符的InvalidArgumentError

  3. 3

    在Tensorflow中,sampled_softmax_loss和softmax_cross_entropy_with_logits有什么区别

  4. 4

    (使用Keras)的Tensorflow中``InvalidArgumentError:不兼容的形状:[10,2]与[10]”的原因是什么?

  5. 5

    Tensorflow - 在经过训练的 softmax 分类模型上检测多个对象

  6. 6

    如何在tensorflow中打印张量的值mnist_softmax.py

  7. 7

    如何在tensorflow中打印张量的值mnist_softmax.py

  8. 8

    Tensorflow错误:InvalidArgumentError:不同数量的组件类型。

  9. 9

    Tensorflow:带有MNIST的InvalidArgumentError,[55000]与[10000]

  10. 10

    tensorflow.python.framework.errors_impl.InvalidArgumentError:预期的大小[0]在[0,512]中,但得到891 [Op:Slice]

  11. 11

    如何使用Tensorflow.JS实现softmax

  12. 12

    激活='softmax'时了解tensorflow keras LSTM

  13. 13

    Tensorflow SoftMax不会忽略掩码值

  14. 14

    Tensorflow:用于自定义 softmax 的 NaN

  15. 15

    消除类似DeepMNIST的网络中的softmax饱和度,以便在TensorFlow中进行彩色图像分类

  16. 16

    在OSX上的Virtualenv中安装TensorFlow

  17. 17

    在Windows上无法在Docker中启动TensorFlow

  18. 18

    tensorflow.python.framework.errors_impl.InvalidArgumentError如何解决?

  19. 19

    TensorFlow InvalidArgumentError/Value 错误随着代码的微小变化而发生

  20. 20

    Keras LSTM在每个单元上使用softmax

  21. 21

    在神经元子集上应用 softmax

  22. 22

    对象检测上的 Sigmoid 与 Softmax 交叉熵

  23. 23

    InvalidArgumentError:默认MaxPoolingOp仅在设备类型CPU上支持NHWC

  24. 24

    Tensorflow softmax_cross ...()函数浮点类型错误

  25. 25

    Tensorflow对于简单的softmax模型,参数值没有变化

  26. 26

    如何在Tensorflow中使用sampled_softmax_loss

  27. 27

    Tensorflow CNN - 密集层作为 Softmax 层输入

  28. 28

    为什么 tensorflow 对 softmax 函数使用“dim”参数?

  29. 29

    在 Tensorflow 和 Keras 的两个通道上生成 softmax

热门标签

归档