0

I used the ImagedataGenerator and flow from directory to train a CNN model for the task and saved into a .h5 file. While prediction the logits or an array of numbers are being displayed and not the labels.

I need the labels to be displayed while prediction.

One possible way I tried was to reassign value of each logit to the desired label or string but I think it could be a tediuos task

what I got:

[[1 0 0]]

what I need: "steve rogers"

Krunal V
  • 1,255
  • 10
  • 23
Harsh Ris
  • 11
  • 1
  • 5
  • PutText(currentImageFrame, name + " ", new System.Drawing.Point(facesDetected[i].X, facesDetected[i].Y), Emgu.CV.CvEnum.FontFace.HersheyComplex, 1.0, new Bgr(255, 255, 0).MCvScalar); We use like that. You should search something like that. – Hafsa Elif Özçiftci May 06 '19 at 12:18

1 Answers1

0

You need the string labels for the predictions you receive from the Keras model. That's easy using np.argmax(x, axis=0 )

If pred is the output of the Keras model ( predictions ) then,

import numpy as np

max_indices = np.argmax( pred , axis=1 )

Define a Python list which has the str labels. Like,

labels = [ 'NAME1' , 'NAME2' , 'NAME3' ]

Then, we iterate over the max_indices array and fetch the objects from labels,

for i in max_indices:
    print( 'Label is {}'.format( labels[i] ) )
Shubham Panchal
  • 4,061
  • 2
  • 11
  • 36