How to get labels in face recognition in Keras


I am building a facial recognition system. The model is complete but I am having minor issues during prediction. I used the Image data generator to load images from train and test folders and trained the CNN with 98% accuracy. However, when I predict the images, instead of labels, logits are being displayed. I tried the manual method of assigning labels to each logit, but that appears to be a tedious task and requires more time to be processed.

E.g., what is being displayed is:

[[1 0 0]]

What I need is:

recognized person is "steve rogers".

Harsh Ris

Posted 2019-05-06T06:51:03.550

Reputation: 1



As you are trying to solve Facial Recognition problem the best approach is to use Siemese Network or Triplet Loss type Network.

But to answer your question in case of Facial Recognition problem as a classification problem you need to sort your categories according to alphabetically order & map it to your one hot encoded output values to it.

For proper implementation of Facial Recognition software watch following playlist

Swapnil Pote

Posted 2019-05-06T06:51:03.550

Reputation: 181


datagen = ImageDataGenerator()
trainData = datagen.flow_from_directory(...)
LABELS= trainData.class_indices.keys()
pred = model.predict([image_data])[0] # For first image!
print("Detected :", LABELS[np.argmax(pred)] )

The array of 0 and 1 is the prediction metrics.

You need a list of label arranged in same manner as your output layer. So that the column with highest probability (in your case 1st column with probability 1).


Posted 2019-05-06T06:51:03.550

Reputation: 219