Is it possible to use class_weights
with a one-hot encoding?
I've tried sparse_categorical_crossentropy
and, for some reason, it's significantly worse than my classic categorical_crossentropy
with one hot encoding model.
This is how I'm calculating the class_weights with sparse:
unique_class_weights = np.unique(labels)
class_weights = class_weight.compute_class_weight('balanced', unique_class_weights, labels)
class_weights_dict = { unique_class_weights[i]: w for i,w in enumerate(class_weights) }
Training like:
full_model.compile(loss='sparse_categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
full_model.fit_generator(line_generator(data_train, labels_train),
validation_data=line_generator(data_test, labels_test),
validation_steps=1,
steps_per_epoch=len(data)/GENERATOR_BATCH_SIZE,
class_weight=class_weights_dict,
epochs=1)