Skip to content Skip to sidebar Skip to footer

Is It Possible To Change Class Indices Of Keras Flow From Directory

I am using my own image data generator. It generates 0 ,90, 180 and 270 degrees rotated versions of image batches and returns them with their classes. I use built in ImageDataGener

Solution 1:

looks like you can do

flow_from_directory(directory, 
                    classes={'0': 0, 
                             '90': 1, 
                             '180': 2, 
                             '270': 3}
                   )

Solution 2:

Absolutely you should be able to, and you can.

From Keras official document: https://keras.io/api/preprocessing/image/: There's an argument name classes for both flow_from_directory and flow_from_dataframe method.

For flow_from_directory it explained:

classes: Optional list of class subdirectories (e.g. ['dogs', 'cats']). Default: None. If not provided, the list of classes will be automatically inferred from the subdirectory names/structure under directory, where each subdirectory will be treated as a different class (and the order of the classes, which will map to the label indices, will be alphanumeric). The dictionary containing the mapping from class names to class indices can be obtained via the attribute class_indices.

This means, when indicated in your flow_from_directory method classes=['dogs', 'cats'], label "dogs" then "cats" will be mapped into label indices by list order, i.e., 0, 1...

By not doing so, they will be in alphanumeric order, "dogs" is 1 then "cats" is 0.

Post a Comment for "Is It Possible To Change Class Indices Of Keras Flow From Directory"