【问题标题】:Error with "Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar"“仅整数、切片 (`:`)、省略号 (`...`)、tf.newaxis (`None`) 和标量”出错
【发布时间】:2019-10-28 14:04:08
【问题描述】:

我正在尝试使用 Tensorflow 后端在 Keras 中训练深度学习算法。我正在尝试执行以下操作:

x = tf.reshape(theta, [-1])[K.argmax(image)]

image 是输入,eta 是坐标。我正在尝试使 theta 变平,但出现错误

 Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf.int64 tensors are valid indices, got <tf.Tensor 'loss_42/dense_264_loss/ArgMax:0' shape=(25,) dtype=int64>

【问题讨论】:

  • 你的 theta 形状和图像形状是什么?您不能直接使用 (25,) 形状张量切片张量。
  • theta 形状是 25*25,我的图像形状是 (1,25,25)。

标签: tensorflow


【解决方案1】:

我猜你想根据K.argmax(image) 获取 theta 值。您不能直接在张量流中使用花哨的索引样式。 tf.gather 可以实现这一点。

res = tf.gather(tf.reshape(theta, [-1]), K.argmax(image))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-05
    • 2022-01-09
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 2019-06-25
    • 2021-04-16
    • 1970-01-01
    相关资源
    最近更新 更多