If you don’t know the targets beforehand, you would need to iterate all samples once and count all class occurrences. Once this is calculated, you could use the sklearn.utils.class_weight.compute_class_weight or just these two lines of code:
I was trying to understand how to account for class imbalance while performing semantic segmentation.
So when you say
"If you don’t know the targets beforehand, you would need to iterate all samples once and count all class occurrences. Once this is calculated, you could use the "
do you mean how many pixels in a label map database correspond to a certain class or how many times does a given unique label occur in a dataset?