While training a keras model for image classification (120 classes from DOG BREED IDENTIFICATION dataset, KAGGLE), I need to balance the classes using class weights which I read somewhere and in examples I have seen people using fit_generator's parameter, class_weight. But I found another parameter in model.compile, weighted_metrics whose description in docs is: 'List of metrics to be evaluated and weighted by sample_weight or class_weight during training and testing'. Shall I be using this? Please explain the purpose of this parameter with any example.
#Calculating Class weights
counter = Counter(train_generator.classes)
max_value = float(max(counter.values()))
CLASS_WEIGHTS = {classid: max_value / num_occurences
for classid, num_occurences in counter.items()}
# Model Compile
model.compile(optimizer=Adam(lr=LR),
loss=categorical_crossentropy,
metrics=[categorical_accuracy],
weighted_metrics=None) # <--------------- This parameter
STEPS_PER_EPOCH = train_generator.n//train_generator.batch_size
VAL_STEPS = val_generator.n//val_generator.batch_size
model.fit_generator(train_generator,
steps_per_epoch=STEPS_PER_EPOCH,
epochs=EPOCHS,
callbacks=callback_list,
verbose=1,
class_weight=CLASS_WEIGHTS,
validation_data=val_generator,
validation_steps=VAL_STEPS) # USED CLASS_WEIGHTS HERE