The problem — In most biological imaging datasets, the classes of interest are not evenly represented. Rare cell types, mitotic figures, micronuclei, or early-stage pathological morphologies may constitute fewer than one percent of all objects in a field. A model trained with standard cross-entropy on such data can reach high aggregate accuracy by ignoring those minority classes entirely — a failure mode that is invisible until the biology you care about is precisely the rare event.
What it is / how it works — Class-weighted loss rescales the contribution of each class to the total training objective by the inverse of its frequency. If a mitotic cell appears ten times less often than an interphase cell, its misclassification is penalized ten times more heavily per example. This forces the gradient signal from rare classes to remain competitive with the gradient from common ones, preventing the optimizer from collapsing to a majority-class solution. In practice, weights are derived from the empirical class distribution in the training set, or from a user-specified prior when the desired detection sensitivity is known. Hagos et al. (2021) demonstrated the approach in a pathology setting with extreme class imbalance, showing that abundance-aware weighting consistently recovered rare-cell detection that standard training missed.
Class-weighted loss is most consequential at the segment and readout stages, and it is a core technique for the challenge described in The Challenge of Rare Events and Mutants: the rarest phenotypes are usually the most biologically meaningful, and a model that cannot detect them is unfit for purpose regardless of its headline accuracy on balanced benchmarks.
Where it breaks — Weighting alone does not conjure signal from absent examples. If a rare class has too few training instances — say, fewer than fifty objects — even heavy upweighting produces an overfit detector with poor generalization. The correct diagnosis is to distinguish between a class-imbalance problem (weighting helps) and a data-scarcity problem (more annotations or synthetic augmentation is required first). Downstream, Validation Without a Ground Truth highlights why evaluating rare-class performance is itself hard: expert-annotated holdout sets are expensive to produce at the scale needed for reliable rare-class precision-recall estimates.