how to get discrete values as output in Keras?

Viewed 58

I'm trying to get an output just like [3,4,0,2,1] (discrete values between 0 and 4) without repetition. this is the code of my model:

inputs = tf.keras.Input(shape=(5,5))
x = tf.keras.layers.LSTM(500, activation=tf.nn.relu)(inputs)
output = tf.keras.layers.Dense(5, activation=tf.nn.sigmoid)(x)
output = tf.keras.layers.Lambda(ordre)(output1)
model = tf.keras.Model(inputs=inputs, outputs=[output1])
model.compile(loss="sparse_categorical_crossentropy",metrics=["accuracy"],optimizer="adam")

ordre function is implemented :

def ordre(tensor):
  return tf.argsort(tensor,direction='DESCENDING')

but I get as error

TypeError: Expected int32, but got 1e-07 of type 'float'.
1 Answers

Whatever your output tensor is, just round.

output = tf.math.round(output)
Related