kdf
kdf

Reputation: 368

Error with "Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar"

I am trying to train a deep learning algorithm in Keras with a Tensorflow backend. I am trying to do the following:

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

Where image is the input and eta is a coordinate. I am trying to flatten theta, but I get the error

 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>

Upvotes: 4

Views: 6884

Answers (1)

zihaozhihao
zihaozhihao

Reputation: 4475

I guess you want to get the theta values according to the K.argmax(image). You cannot directly use fancy indexing style in the tensorflow. tf.gather can achieve this instead.

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

Upvotes: 8

Related Questions