You can easily handle imbalanced datasets when training or fine-tuning generative models by referring to following code:

In the above code techniques like Class Weights and SMOTE were implemented to modify loss to handle imbalance and oversampling the minority class to balance dataset.