Home > database >  ValueError: `decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples,
ValueError: `decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples,

Time:11-29

I am using a model trained by myself to translate braille digits into plain text. As you can see this is a classification problem with 26 classes, one for each letter in the alphabet.

This is the dataset that I used to train my model: enter image description here

So we need a way to map the prediction value to the respective letter. A simple way to do this could to create a list of all the 26 possible letters and search the max value in the prediction array. Example:

#Create prediction labels from a-z
alpha="a"
labels=["a"]
for i in range(0, 25): 
    alpha = chr(ord(alpha)   1)
    labels.append(alpha)
#Search the max value in prediction
labels[np.argmax(prediction)]

The output should be the character with the highest probability:

enter image description here

  • Related