# In Keras how to get the class_indices or prediction labels for an existing model

I know that keras provides a .class_indicies dictionary containing the mapping from class names to class as part of .flow_from_directory() from its ImageDataGenerator class (https://keras.io/preprocessing/image/).

HOWEVER, is there a way to access the corresponding class labels from an existing saved model (a model saved in as an .h5 file)? This seems important when putting my model into production and serving predictions since the classes are not known upfront and therefore the images are not separated in pre-labeled directories.

Similarly, are there any good examples of how a keras model should be deployed into production (especially for mobile)? Thanks!

Don't know if you solved already. I faced this problem yesterday, and the only solution that came to my mind is saving a dictionary to a numpy file after a train_generator is set; something like:

np.save('FILENAME', self.train_generator.class_indices)


when you finish your training. Then, when you do your single prediction:

single_pred = np.squeeze(self.model.predict(image))

if isfile('FILENAME.npy'):