首页 > 解决方案 > “仅整数、切片 (`:`)、省略号 (`...`)、tf.newaxis (`None`) 和标量”出错

问题描述

我正在尝试使用 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>

标签: tensorflow

解决方案


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

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

推荐阅读