how to use to_categorical when using ImageDataGenerator

It might be useful (even after two years) to also mention that if you want specific order for one-hot vectors, you can feed that through classes argument.
For example if you want "dog"=[1,0] and "cat"=[0,1], then explicitly set:
classes=["dog", "cat"].


Since you are passing class_mode='categorical' you dont have to manually convert the labels to one hot encoded vectors using to_categorical().

The Generator will return labels as categorical.