In Keras (using TensorFlow as a backend) I am building a model which is working with a huge dataset that is having highly imbalanced classes (labels). To be able to run the training process, I created a generator which feeds chunks of data to the fit_generator
.
According to the documentation for the fit_generator, the output of the generator can either be the tuple (inputs, targets)
or the tuple (inputs, targets, sample_weights)
. Having that in mind, here are a few questions:
- My understanding is that
the
class_weight
regards the weights of all classes for the entire dataset whereas thesample_weights
regards the weights of all classes for each individual chunk created by the generator. Is that correct? If not, can someone elaborate on the matter? - Is it necessary to give both the
class_weight
to thefit_generator
and then thesample_weights
as an output for each chunk? If yes, then why? If not then which one is better to give? - If I should give the
sample_weights
for each chunk, how do I map the weights if some of the classes are missing from a specific chunk? Let me give an example. In my overall dataset, I have 7 possible classes (labels). Because these classes are highly imbalanced, when I create smaller chunks of data as an output from thefit_generator
, some of the classes are missing from the specific chunk. How should I create thesample_weights
for these chunks?