I'd like to use class_weight argument in keras model.fit to handle the imbalanced training data. By looking at some documents, I understood we can pass a dictionary like this: class_weight = {0 : 1, 1: 1, 2: 5} (In this example, class-2 will get higher penalty in the loss function.) The problem is that my network's output has one-hot encoding i.e. class-0 = (1, 0, 0), class-1 = (0, 1, 0), and class-3 = (0, 0, 1). How can we use the class_weight for one-hot encoded output? By looking at some codes in Keras, it looks like _feed_output_names contain a list of output classes, but in my case, model.output_names/model._feed_output_names returns ['dense_1'] Related: How to set class weights for imbalanced classes in Keras? Continue reading...