Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tensorflow

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>
like image 377
kdf Avatar asked Mar 03 '23 06:03

kdf


1 Answers

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))
like image 101
zihaozhihao Avatar answered May 24 '23 01:05

zihaozhihao