Keras classes are in what order?


#1

How do I know in what order are the Keras classes? I mean, how do I know class 1 is associated with dogs, and class 2 with cats?

With only 2 classes, in the lecture I think Jeremy just made a hand-wave, as it’s pretty easy to tell which class is which, just by showing the test image (and assuming the classification got it right). But what if there are a lot more than just 2 classes, say, 200 classes – I’m not going to look at 200 images to determine which number is which class, right? Or what if as a human I can’t tell which class is which from the image (e.g. in cancer detection, lacking expertise I’d not be able to tell which class it is just by looking at an image.)


#2

If you’re using an ImageDataGenerator and the flow_from_directory() method – which you are, currently – then the batches returned from the generator have a .classes attribute that lists all of the class labels in the order Keras is using them.


#3

If it’s a classification problem,then what the model outputs will corresponds to what you trained it on.
If you do flow from directory, then the classes will be in alphabetical order.


(Uyuz Kale) #4

Thanks for response @shawn


#5

Awesome. Thank you!


(Naren) #6

The class labels can be retrieved as a list from the class_indices.keys() of the ImageDataGenerator object.


(abdelhak) #7

If we use flow_from_directory and we deploy the model in tensorflow serving. How can we then know the true class in the client side ?