what does class_mode parameter in Keras image_gen.flow_from_directory() signify?


train_image_gen = image_gen.flow_from_directory('/Users/harshpanwar/Desktop/Folder/train',

In the above code snippet what does class_mode=’binary’ signify. I think it is for the number of categories of images. I am using this code for training a image recognition classifier in Keras to classify between 2 different categories like dog and cat. So if class_mode=’binary’ is for signifying two categories how do we make it for three or more?


class_mode: One of "categorical", "binary", "sparse", "input", or None. Default: "categorical". Determines the type of label arrays that are returned: – "categorical" will be 2D one-hot encoded labels, – "binary" will be 1D binary labels, "sparse" will be 1D integer labels, – "input" will be images identical to input images (mainly used to work with autoencoders). – If None, no labels are returned (the generator will only yield batches of image data, which is useful to use with model.predict_generator()). Please note that in case of class_mode None, the data still needs to reside in a subdirectory of directory for it to work correctly.

Answered By – Soheil Hosseini

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.