I would like to integrate the weighted_cross_entropy_with_logits to deal with data imbalance. I am not sure how to do it. Class 0 has 10K images, while class 1 has 500 images. Here is my code.
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3, 3), input_shape=(dim, dim, 3), activation='relu'),
....
tf.keras.layers.Dense(2, activation='softmax')
])
model.compile(optimizer="nadam",
loss=tf.keras.losses.CategoricalCrossentropy(),
metrics=['accuracy'])
class_weight = {0: 1.,
1: 20.}
model.fit(
train_ds,
val_ds,
epochs=epc,
verbose=1,
class_weight=class_weight)