I have a saved keras model. How can I get back the labels from the model ?

Because right now, I can use the predict method to get back the probability for a sample to belong to a certain class e.g. class 1, 2, 3.

But how can I know what class 1, 2, 3 correspond to in the model e.g. cat, dog, bird ?

  • the labels are not loaded with the model, so if you don't have any information of the model, you have no way to get the labels. If you have information about it, then Олег answer is right. There is also a method 'decode_prediction' in keras.applications.imagenet_utils that return a dict with label for IMAGENET – Jérémy Blain Oct 11 at 13:02
  • Ok. This is what I feared. Thanks for confirming my feeling. – FenryrMKIII Oct 11 at 14:10

You can use the argmax function to get the class labels. Please refer to this link for more information. Hope this answers your question.

  • No because that does not tell me anything about the labels in a human way. Imagine I load a model I know nothing about. How do I know which labels he was trained on ? – FenryrMKIII Oct 7 at 18:55

Create list of labels ["dog", "cat"] and use argmax as index to get value from list.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.