To handle unbalanced data, I would like to weight each class according to their data distribution.
It is very straightforward in Tensofrflow as the foloowing
from sklearn.utils.class_weight import compute_class_weight
generator_train = datagenerator_train.flow_from_directory(directory=train_dir,
                                                          target_size=input_shape,
                                                          batch_size=batch_size,
                                                          shuffle=True)
cls_train = generator_train.classes
class_weight = compute_class_weight(class_weight='balanced',
                                    classes=np.unique(cls_train),
                                    y=cls_train)

Does pytorch have similar native support? It seems I have to write some function to compute the weights