Search code examples
pythondeep-learningtypeconverter

Convert Output of Model.Predict to integer


devs I'm using a simple convolutional neural network for binary classification, everything working very well, I'm looking for a method to convert the output of my model prediction to integer (0 or 1).

in the last step I have this instruction :

res_f = my_model.predict(test_img)

and when i print the value of res_f , the result looks like : [[0. 1.]] my problem is about converting res_f to an integer ?


Solution

  • The output of the model is in One Hot Encoded format. You can use argmax to get the integer equivalent from One Hot Encoded Array.

    Code Snippet:

    import numpy as np
    
    res_f = my_model.predict(test_img)
    result = np.argmax(res_f)
    

    Output:

    1