I want integer output (boolean exactly) not real number

hello,

i have a little code that try to predict a vector of boolean values (output layer of neural network should produce that) but instead i have a vector of real numbers, what can i change in my code to do that?

my code contains this:

model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(1,)),
tf.keras.layers.Dense(lgt, activation=‘relu’),
tf.keras.layers.Dense(lgt),
tf.keras.layers.Softmax()
])

model.compile(optimizer=“Adam”, loss=“mse”, metrics=[“mae”])

model.fit(traj_train_input,traj_train_output , epochs=100)

i train the model with data having output like : [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
and when i use the model i have output with reals, like that:

model.predict([5])
array([[0.00326481, 0.01493612, 0.00951447, 0.00575305, 0.00644396,
0.00941434, 0.00674182, 0.00505168, 0.03497467, 0.04624736,
0.25262812, 0.5352649 , 0.02151884, 0.01447066, 0.00728487,
0.01637338, 0.01011696]], dtype=float32)

basically what i want is 1 instead of 0.5352649 and other insignifiant little values like 0.00326481 to be at 0 to have a vector of booleans values

what can be changed in code? activation function ?? other?

Regards,
Damien

@Damien_Mattei,

Welcome to the Tensorflow Forum!

First use model.predict() to extract the class probabilities. For binary classification use a threshold to select the probabilities that will determine class 0 or 1

np.where(y_pred > 0.5, 1,0)

Or build a custom activation function as per usecase.

Thank you.

thank you

it the idea i had in mind.
For a custom activation function it has been notified to me that if i do a boolean function as activation function il will not be differentiable

regards,
damien