{'fraction_non_alphanumeric': 0.03261565318591795, 'fraction_numerical': 0.006720977596741344, 'mean_word_length': 4.73997995991984, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Posterior Re-calibration for Imbalanced Datasets

Neural Networks can perform poorly when the training label distribution is heavily imbalanced, as well as when the testing data differs from the training distribution. In order to deal with shift in the testing label distribution, which imbalance causes, we motivate the problem from the perspective of an optimal Bayes classifier and derive a post-training prior rebalancing technique that can be solved through a KL-divergence based optimization. This method allows a flexible post-training hyper-parameter to be efficiently tuned on a validation set and effectively modify the classifier margin to deal with this imbalance. We further combine this method with existing likelihood shift methods, re-interpreting them from the same Bayesian perspective, and demonstrating that our method can deal with both problems in a unified way. The resulting algorithm can be conveniently used on probabilistic classification problems agnostic to underlying architectures. Our results on six different datasets and five different architectures show state of art accuracy, including on large-scale imbalanced datasets such as iNaturalist for classification and Synthia for semantic segmentation. Please see https://github.com/GT-RIPL/UNO-IC.git for implementation.


Introduction
Applications of deep learning algorithms in the real world have fueled new interest in research beyond well-constructed datasets where the classes are balanced and the training distribution faithfully reflects the true (testing) distribution.
However, it is unlikely that one can anticipate all possible scenarios and construct well-curated datasets consistently. Therefore it is important to study robust algorithms that can perform well with such imbalanced datasets and unseen situations during testing. The aforementioned problems can be categorized as distributional shift between the training and testing conditions, specifically:label prior shift and non-semantic likelihood shift.
In this paper, we focus on label prior shift, which can arise when i) the training class distribution does not match the true (test) class distribution due to the inherent difficulty in obtaining samples from certain classes, or ii) the distribution of classes does not reflect their relative importance. For example, the natural world is inherently imbalanced such that a collected dataset may exhibit a long-tailed distribution. Similarly, in semantic segmentation, the pixel percentage of pedestrains does not reflect their importance in prediction (e.g. for safety).
In order to deal with such shift in the testing label distribution, which imbalance causes, a number of methods have been developed such as class-balanced loss (CB) [1] and Deferred Reweighting (DRW) [2], as well as methods that scale the margin in a fixed way as a function of the amount of data per class through a label-distribution-aware loss (LDAM) [2] . However, such methods do not allow for a flexibly trade-off between precision and recall across the classes, and require re-training to target a testing label distribution.
In this paper, we instead motivate the problem from the perspective of an optimal Bayes classifier and derive a rebalanced posterior by introducing test priors and showing that it is the optimal Bayes classifier on the test distribution under ideal conditions. To compensate for imperfect learning in practice, an approximation can be solved through a KL-divergence based optimization by treating the rebalanced and original posteriors as approximations to a true posterior.
This method, which does not require re-training the original imbalanced classifiers, allows a flexible hyper-parameter to be efficiently tuned on a validation set and effectively modify the classifier margin to target a desired test label distribution. We further combine this method with existing methods dealing with non-semantic likelihood shift, which occurs when the representation of samples from a certain class changes due to changes in lighting, weather, sensor noise, modality, etc. We re-interpret these methods from the same Bayesian perspective, and demonstrate that our method can deal with both problems in a unified way.
We demonstrate our method on six datasets and five different neural network architectures, across two different imbalanced tasks: classification and semantic segmentation. Using a toy dataset that allows for visualizations of the classifier margins, we show that our method effectively shifts the decision boundary away from the minority class towards the over-represented class. We then demonstrate that our method can achieve state of the art results on imbalanced variants of CIFAR-10 and CIFAR-100, and can scale to larger datasets such as iNaturalist which has extreme imbalance. For semantic segmentation, which is an inherently imbalanced task, we show that our unified method can support both imbalance and likelihood shift in the form of unknown weather conditions encountered during testing (but not during training).
In summary, the main contributions of the paper are the following: • We derive a principled imbalance calibration algorithm for models trained on imbalanced datasets. The method requires no re-training to target new test label distributions and can flexibly trade-off between precision and recall on under-represented classes via a single hyper-parameter.
• We introduce an efficient search algorithm for this hyper-parameter. Unlike cost sensitive learning, an optimal hyperparameter can be searched efficiently on a validation set posttraining.
• We test the algorithm on six datasets and five different architectures and outperforms state-of-the-art models on classification accuracy (recall) across all tasks and models while maintaining good precision.
• We further combine our method with non-semantic likelihood shift methods, re-motivate it from the Bayesian perspective, and show that we can tackle both problems in a unified way on a RGB-D semantic segmentation dataset with unseen weather conditions. We show significant improvement on mean accuracy while maintaining good mean IOU performance with both qualitative and quantitative results.

Related Work
In this paper, we focus on prior (label) distribution shift resulting from various degrees of imbalance in the training label distributions, and testing on a different distribution or emphasizing a different distribution in the testing metrics (e.g. class-averaged accuracy). We therefore summarize methods for dealing with such imbalance.
Imbalance -Data Level Methods The simplest methods for dealing with label imbalance during training are random under-sampling (RUS) which discards samples from the majority classes and random over-sampling (ROS) which re-samples from the minority classes [3]. While ROS is infeasible when the data imbalance is extreme, RUS tends to overfit the minority classes [4]. Synthetic generation [5] or interpolation [6] to increase the number of samples in the minority class are also used. However, these methods are sensitive to imperfections in the generated data.
Imbalance -Algorithm-Level Methods The majority of work in this category modify the training procedure by introducing cost-sensitive losses. For example, median frequency balancing has been used in dense prediction tasks such as surface normal and depth prediction [7] as well as semantic segmentation [8]. DRW [2] is a variant of the frequency balancing algorithm. It re-weights the loss function at a latter training stage not from the beginning. We specifically compare our method to three state-of-the-art cost sensitive losses LDAM [2], Class-Balanced Loss (CB) [1], and Focal Loss (FL) [9]. LDAM derives a generalization error bound for the imbalanced training and proposes a margin-aware multi-class weighted cross entropy loss. CB motivates the concept of effective number of samples and derives a weighted cross entropy loss with approximation. FL is another weighted cross entropy loss with a sample-specific weight (1 − p i ) γ , where p i is the model output probability for class i. A contemporary work Bilateral-Branch Network (BNN) [10] proposes a two branch approach with one branch learning the original distribution and the the other learning a rebalanced distribution. Our method can be combined with algorithm-level methods to yield better performance.
Imbalance -Classifier Level Methods The most common method in this category is thresholding or post scaling. The process happens at the test phase and changes the output class probabilities. The simplest variant compensates for prior class probabilities, i.e. dividing the output for each class by its training set prior probabilities. This method can often improve the performance for imbalanced classification [11] [12]. The same technique under the name maximum likelihood [13] is also used in semantic segmentation which is a naturally class-imbalanced task. While this decision rule was able to improve recall on minority classes, it deteriorates overall performance by introducing substantially more false detection. Our method belongs to this category and improves on previous works. For a more comprehensive review on dataset imbalance in deep learning, we refer readers to [4].

Background: A Unified Perspective on Label Prior and Non-Semantic Likelihood shift
Let P s (X, Y ) define a training (source) distribution and P t (X, Y ) define a test (target) distribution where X is the input and Y ∈ C = {1, ..K} is the corresponding label. In a multi-class classification task, the final decision on the target distribution is often made by following the Bayes decision rule: where f t (x|y) is the class conditional probability density function and P t (y) is the prior distribution.
Label prior shift refers to the prior (label) distribution changing between training and testing, i.e, P s (Y ) = P t (Y ); in this paper, we focus on the case where the training distributions have varying degrees of imbalance (e.g. long-tailed) and the testing distribution shifts (e.g. is uniformly distributed). Note, however, that the method we develop is not limited to this case. Note also that some metrics during testing implicitly emphasize a uniform distribution over labels, regardless of the actual label distribution in the testing dataset; see Appendix Section 6.3 for a proof for one popular class of metrics, namely class-averaged metrics.
Non-semantic likelihood shift refers to shift without introducing new semantic labels such as sensor degradations, changes in lighting, or presentation of the same categories in a different modality, i.e. f s (X|Y ) = f t (X|Y ).
In this paper, we focus on the label prior shift, commonly known as class imbalance. In sec. 3.2, to deal with prior label shift, we motivate the problem from the perspective of the optimal Bayes classifier and derive a prior rebalancing equation and a KL-divergence based optimization method.
In addition, we re-motivate temperature scaling [14] for dealing with likelihood shift, starting with a similar Bayesian perspective, as a likelihood flattening process instead of as a confidence calibration technique. In the same section, we propose a unified algorithm to simultaneously handle both types of shifts.

Theoretical Motivation
To motivate the framework for dealing with learning in an imbalanced setting, we start from the assumption that a discriminative model can learn the posterior distribution P s (Y |X) of the source dataset perfectly. The corresponding Bayes Classifier is defined as the following.
The classifier h s (x) is the optimal classifier on the training distribution, P s (X, Y ). Now let's assume that the test distribution has the same class conditional likelihood as the training set, i.e. f t (X|Y ) = f s (X|Y ) and differs only on the class priors P t (Y ) = P s (Y ). We show the following result: is the optimal Bayes classifier on This partition defines the decision region of a classifier for K classes.
and 0 otherwise. To avoid notational clutter, we abbreviate y = k as k. By choice of the decision rule h t (x) defined in Thm. 1, the function inside the integral is at its maximum and any other decision rules will result in higher risk. We note that the rebalancing technique in Thm. 1 is not new and has been studied before in [15]. Our contribution is proving its optimality under the ideal setting with Bayes risk.
The theorem sheds light on the weakness of this approach: in reality, we do not have access to either P t (X, Y ) or P s (X, Y ). We merely have samples from those hidden distributions. In other words, we do not have perfect modeling nor learning of the generating distribution. We learn an approximation of the distribution according to relative entropy between a parametrized distribution P d (Y |X), denoting the learned discriminative posterior, and P s (Y |X). Therefore, the resulting classifier with proper substitution to Thm. 1, is not optimal and the corresponding partition Γ(h s ) is not the optimal decision boundary on the test distribution. We will now show that we can obtain a better classifier thanh t (x) by exploring some observations.
We introduce a terminology rebalanced posterior, P r (y|x) to describe eq. 5 because the discriminative posterior P d (y|x) is rebalanced by P t (y)/P s (y). As we have discussed, the parametrization and learning of the training distribution are not perfect. It is unlikely that a direct application of theorem 1 leads to a good classifier on the test distribution. The weighting P t (y)/P s (y) in eq. 5 might be too large or too small for different setups. For example, in semantic segmentation, directly using eq. 5 results in excessive false positives for small classes as reported by [13]. We also show in the experiment section that eq. 5 yields inferior performance on imbalanced classification datasets. Figure 1: Left: log-linear dependency on source prior ratio with λ ≤ 1. Right: log-linear dependency on source prior ratio with λ > 1. x axis is the ratio P s (c i )/P s (c gt ) and y axis denotes the ratio raised to the power of λ. The amplification effect of the source prior ratio is reduced when λ ≤ 1 and increased when λ > 1 Hypothesis 1 A better classifier can be found by finding a trade off between the discriminative classifier P d (y|x) and the derived rebalanced classifier P r (y|x).
Intuitively, if the weighting P t (y)/P s (y) is too large and P r (y|x) biases too much towards small classes, we might want to weigh in the original prediction P d (y|x) where no weighting is applied; if the weighting is too small, we can encourage a stronger weighting to move further away from P d (y|x). Based on this intuition, a natural distance metric for distributions is KL-divergence (or relative entropy). Therefore, we propose the following optimization problem based on minimizing the KL-divergence between the final calibrated posterior P f (y|x) and P d (y|x), P r (y|x).
where λ ≥ 0 is a hyperparameter. The optimization problem tries to find an interpolated distribution between P d (y|x) and P r (y|x) with a regularizing parameter λ. The information-theoretic justification for this formulation is that assuming P f represents the true distribution which we want to approximate, KL(P f , P d (y|x)) + KL(P f , P r (y|x)) captures the number of bits lost when encoding P f with both P d and P r . It is clear that when λ = 0 we recover the discriminative classifier and when λ = 1 we have the rebalanced classifier. More generally, there exists a closed form solution to this optimization problem [16].
where Z(x) is the normalization factor. This completes an extremely simple calibration method with only a single hyperparameter for class imbalance in classification. It can effectively adjust a classifier's decision boundary and outperform more sophisticated training methods on image classification tasks. Further more, unlike many existing class imbalance methods, we will show that the proposed method can adjust the trade-off between precision and recall. This is especially important for semantic segmentation which uses Intersection over Union (IOU) as criterion.

Analysis of the Rebalancing Equation
We use the odd ratio form for analysis. Odd ratio has been used in logistic regression [17], where it is defined as the ratio of probability of success and probability of failure. Here odd ratio denotes ratio of the calibrated posteriors. Let c gt denote the ground truth class, c i denote one of the other classes. We rewrite Eq. 7 as the following ( detailed derivation is in appendix 6.1): For a ground truth class to be the selected (argmax) output, the odd ratio in eq. 8 needs to be greater than 1 ∀i = gt. We first analyze the dependency on λ by setting the test priors, P t (y), equal for all classes.
It is clear from Eq.8 that if c gt is a minority class then the ratio of priors under λ, P s (c i )/P s (c gt ), denoted source prior ratio, is greater than 1 and when c gt is a large class it is smaller than 1. Intuitively, this prior ratio amplifies the odd ratio for minority classes and downweights the odd ratio for large classes. However, as pointed out in [13], this scaling can be far too aggressive when λ = 1.
In other words, the prior ratio becomes too large when c gt is a minority class and too small when c gt is a large class.
As shown in the left part of Fig. 1, with λ ≤ 1 when the source prior ratio is greater than 1 in the case of c gt being a minority class, the growth is sublinear and when the source prior ratio is smaller than 1, the growth is superlinear. In the right section of fig. 1, we also see that the dependency is different when λ ≥ 1. When c gt is a minority class, the growth is superlinear and when c gt is a majority class, the growth is sublinear. In other words, the amplification effect of the source prior ratio is reduced when λ ≤ 1 and increased when λ ≥ 1. As we will show empirically, by finding a good λ on a validation set, we can strike a balance between recall and precision between large and small classes. The analysis validates our hypothesis that a better classifier can indeed be found through the trade-off of P d (y|x) and P r (y|x).

Search Algorithm and Time Complexity for λ
An efficient algorithm exists for searching λ based on an empirical observation of the dependency between accuracy and λ. Empirically, we found that performance metrics evaluated on a validation set vary with λ in a concave manner with a unique maximum. A modified binary search algorithm can find a maximum with a specified precision with O(log N ) time complexity where N is the number of λs in the search range. Due to space constraint, please refer to the appendix for the complete algorithm 6.2. Please refer to the experiments in sec. 4.1 for more detail.

Confidence Calibration with Likelihood Flattening
In the previous section, we explored a probabilistic way to deal with prior shift. In this section, we similarly look at likelihood shift and cast a different perspective on an existing technique, temperature scaling [14], as a likelihood flattening process which implicitly increases the uncertainty in the likelihood P d (X|Y ). The reasoning is hypothetical because a discriminative model does not learn a likelihood explicitly. Temperature scaling has been used in uncertainty calibration [18]. The basic temperature scaling takes the following form, where [l 1 , ..., l Nc ] are the pre-softmax logits and δ is a scalar.
Graphically, smaller δ will result in a flatter softmax output and larger δ will result in a more peaked softmax distribution. In Eq. 1, we showed that y * = arg max y∈C P t (y|x) = arg max y∈C f t (x|y)P t (y). Considering the equal prior situation, then we can remove P t (y) from the previous equation. Now, flattening the softmax probability, P t (y|x), is equivalent to flattening the likelihood, f t (x|y). We formalize the discussion in the following hypothesis.
Hypothesis 2 In light of the decomposition in Eq. 1, temperature scaling in a softmax-activated discriminative model is numerically equivalent to flattening the class conditional likelihood f (x|y) ∀y ∈ C implicitly and making the likelihood of belonging to any class more likely.
This behavior of temperature scaling is desirable especially in a multi-modal fusion setting. For example, if one modality is compromised, temperature scaling can flatten the output distribution from that modality to raise its uncertainty in the sense of entropy. More importantly, a flattened distribution has little power to affect the decision from other modalities.
UNO [19] introduced an uncertainty-aware temperature scaling factor δ(x) which depends on a network's input x. The uncertainty-aware scalar correlates with uncertainty in an input image. Intuitively, if an input image is degraded, δ(x) as the temperature parameter will be a scalar less than 1 and thus "softens" the distribution and makes the model less confident in its prediction.
Following the hypothesis, we view the uncertainty-aware temperature scaling in UNO as a likelihood flattening method. Together with the prior rebalancing method from the previous section, we develop a unified multi-modal fusion algorithm Alg. 1 for prior and likelihood shift and apply it to multimodal tasks. We use noisy-or operation as the final fusion layer as in UNO [19]. We demonstrate the performance of the algorithm on a RGB-D semantic segmentation task in Seq. 4.4.2. Please also see Appendix 6.6 for qualitative results.

Experiments
We conduct experiments to test our imbalance calibration (IC) algorithm described in sec. 3.2 on six datasets with five different architectures. A summary of datasets and architectures used for each one is shown in table 1.

Toy Dataset
To visualize the effect of our imbalance calibration algorithm on decision boundaries, we generate two binary imbalanced datasets for classification, two moon and circle and train a 3-layer fully connected classifier with logistic loss on each. Fig. 2 shows an overlay of the input data and decision boundary with different λs and the accuracy vs. lambda plots for both datasets. The original decision boundary λ = 0.0 cuts through the minority class, and varying λ shifts the decision boundary away from the minority class towards the larger class. We can find a better classifier empirically by searching λ values on a validation set. The accuracy vs. lambda curves exhibit concavity as shown on the right side of Fig. 2. This observation motivates an efficient modified binary search algorithm for λ in Appendix Sec. 6.2. The same concavity is also observed for more complex tasks subsequently.

Imbalanced CIFAR Classification
We compare our methods with the state-of-the-art methods [1] [2] [9] [10] on CIFAR-10 and CIFAR-100 dataset with two different imbalance types: long-tailed imbalance [1] and step imbalance [12] with two different imbalance ratios for each imbalance type. Following [2], we present the validation error in Table 2. We observe that Focal [9] is not as effective against imbalance and this is also   observed in the same set of experiments in [2]. BNN [10] achieves comparable performance with more complicated training strategy and architecture. Even though LDAM [2] improves the classification performance, DRW gives the most improvement. As a post-calibration method, our method can be combined with different learning losses and learning schedules to further improve performance. Our method combined with DRW and standard cross entropy loss, CE-DRW-IC, yields the best performance. The hyperparameter λ is searched on the validation set. Please refer to the Appendix Sec. 6.4 for the exact values.

iNaturalist Dataset Classification
iNaturalist2018 [21] is a large classification dataset for species with 437,513 training images and 24,426 validation images. We randomly split the validation set into three subsets and use 3-fold cross validation for tuning and testing our IC method. We compare our method with Focal [9], LDAM [2], DRW [2] and BNN [10] in Table 3. Again, IC methods yield the best performance. It outperforms BNN [10] which has a much more complicated training strategy. The result demonstrates the effectiveness of our method for extremely large number of classes and severe imbalance.

Synthia Multimodal Semantic Segmentation
For RGB-D semantic segmentation, we use the Synthia-Sequences dataset [25] which is a photorealistic synthetic dataset of traffic scenarios under different weather, illumination, and season conditions. The hyperparameter λ is tuned on a validation split and the algorithm is tested on a test set.

RGB Imbalance Experiment
Unlike previous classification problems which use only accuracy as the performance metric, semantic segmentation uses both mean intersection over union (IOU) and mean accuracy. Mean IOU considers the effect of false positive predictions while mean accuracy only considers true positives. The difference between the two metrics can be seen as the recall-precision trade-off. Table 4 shows the full evaluation against frequency weighted loss, Focal loss [9] and LDAM [2] on the in-distribution test splits. While the median and max frequency weighted losses achieve the best mean accuracy, their mean IOU performance drops considerably. LDAM [2] resembles the performance of the frequency losses with high accuracy but low IOU because it also emphasises the minority classes by maintaining a fixed margin. Focal loss [9], on the other hand, resembles the performance of unweighted cross-entropy loss because it adopts a per-example weighting scheme and does not explicitly reweight a certain class. BNN [10] does not generalize to segmentation due to its undersampling strategy for training a rebalancing branch. Overall, our method CE-IC and Focal-IC which use imbalance calibration on top of models trained with cross entropy and focal loss achieve significantly improved mean accuracy while maintaining a good mean IOU. Further analysis of the performance characteristics is in Appendix Sec. 6.5.

RGBD Fusion Experiment
To demonstrate the proposed unified Alg. 1 for prior and likelihood shift, we conduct RGB-D multimodal semantic segmentation experiments on Synthia out-of-distribution splits which consist of seven weather conditions not seen during training. In this experiment, we compare to a simple baseline, SoftAve, which simply adds RGB and Depth predictions and averages the two, and UNO [19] which is designed for unseen degradations. In Table 5, we report both mean IOU and mean accuracy. While UNO achieves the best mean IOU, our method combined with UNO results in significant improvement in mean accuracy with negligible drop in mean IOU. This experiment demonstrates the effectiveness of our algorithm against extreme dataset imbalance and unseen degradations. We also show qualitative results in Appendix Sec. 6.6. Our method UNO-IC is able to identify small objects in the distance such as poles and pedestrians even under severe visual degradations.

Conclusion
We proposed a unified perspective and algorithm to deal with label prior shift, and combine it with methods for non-semantic likelihood to tackle both types of shifts simultaneously. The major contribution is a novel imbalance calibration technique which is motivated from the concept of optimal Bayes classifier and optimization of KL divergence. To accompany the formula, we introduced a modified binary search algorithm for the hyperparameter (lambda) based on the empirical observation of a concave performance function as it is varied. Our method is also very computationally efficient because the hyperparameter is tuned during the validation stage whereas most SOTA methods require retraining. The final algorithm can be used in probabilistic classification tasks regardless of underlying architectures. We have shown the generality of the imbalanced calibration technique on six datasets and a number of different architectures, showing effectiveness of the unified algorithm against both extreme dataset imbalance and unseen degredations in multi-modal semantic segmentation.

Odd Ratio Derivation
In Sec. 3.2.2, we used odd ratio to analyze the behavior of the proposed imbalance calibration method.
Here we provide the full derivation of the odd ratio Eq. 8 from Eq. 7 and Eq. 7.
where c gt denotes the ground truth class, c i denotes one of the other classes. P f , P d and P r denote the final calibrated posterior, the original discriminative posterior and the rebalanced posterior respectively.

Search Algorithm for λ
Efficient algorithm exists for searching λ based on empirical observation of dependency on λ.
Empirically, we found that performance metrics evaluated on a validation set vary with λ in concave manner with a unique maximum. In other words, a function of λ first increases and then decreases. A modified binary search algorithm can find a maximum with a specified precision with O log(n) time complexity where n is the number of λs in the search range. We outline the algorithm in a Pythonic pseudo code format implemented with recursion. To assist efficient search, we define three hyperparameters in this algorithm, Low,High and Prec which is the lower bound, upper bound and quantization precision of λ to be searched. Based on our observation,the parameters are set to 0.0, 2.0 and 0.1 respectively. Another notation introduced is metric() which denotes a metric function that takes λ as input and evaluates a model with the given λ on a validation set. metric() returns a scalar representing the performance of the model with the current λ. The full algorithm is presented in Alg. 2.

Imbalance Due to Evaluation Metrics
We define two types of label prior shift: explicit and implicit. The shift occurs as a result of imbalance in the training data and they will lead to poor performance measured on certain metrics. We will discuss them in the general case of multi-class classification.
Explicit label prior shift refers to the prior (label) distribution changing between training and testing, i.e, P s (Y ) = P t (Y ) following the definition of prior shift in [26]; in this paper, we focus on the case where the training distributions have varying degrees of imbalance (e.g. long-tailed) and the testing distribution shifts (e.g. is uniformly distributed, Y ∼ U(1/K)). To see that the imbalance causes label prior shift which in turn, causes performance drop, let's analyze the popular metric, accuracy used in image classification.
As shown in eq. 11, the accuracy metric is equal to the expectation of accuracy w.r.t to the distribution of labels, P (Y ). When P s (Y ) = P t (Y ) = U(1/K), training with imbalanced data maximizes accuracy w.r.t P s (Y ) where large classes dominate, while on test dataset the accuracy metric calculates the expectation of accuracy w.r.t a uniform distribution . Consequently, training with imbalanced Implicit label prior shift is unconventional because it happens when P s (Y ) = P t (Y ) = U(1/K) . This is the case for semantic segmentation, where classes such as pedestrians, poles, etc. occupy a much smaller portion of an image in both training and test data. However, people tend to assign equal importance to all classes regardless of their actual pixel percentage. This is reflected by the popularity of class average metrics such as mean accuracy and mean Intersection over Union (mIOU). In other words, label prior shift is implicitly caused by using class average metrics even though the test distribution is equal to training. Let's look at the another popular metric, mean accuracy, which is often used when the test data is not uniform (in contrast to the first case).
As shown in eq. 12, mean accuracy is equal to the expectation of accuracy w.r.t a uniform label distribution. Mean accuracy is exactly the same as the accuracy metric on uniform test data in the first case. In other words, evaluating on non-uniform test data with mean accuracy is equivalent to evaluating on uniform test data with accuracy in expectation. Even though the training distribution is the same as the test distribution and both are non-uniform, using mean accuracy results in an implicit label prior shift.

Lambda Search on Validation Set for iNatrualist2018 and Synthia
The left side of Fig. 3 shows the performance curve of top1 and top5 accuracy on iNatrualist2018 with different λ. The right side of Fig. 3 shows the performance curve of both mean IOU and mean accuracy on a Synthia validation set with varying λ values. On the far right where λ = 1.0 we obtain the performance of the rebalanced posterior as in eq. 5 and on the left we recover the performance of the discriminative model. Intuitively, as we move towards the full rebalanced posterior by increasing λ, the algorithm gives more weight to minority classes and the mean accuracy continues to increase. However this comes at the cost of significant increase in false positives as the mean IOU drops. The trade-off between mean IOU and mean accuracy reflects the imperfect learning of the dataset discussed in sec. 3.2. By searching for a good balance, it is possible to improve mean accuracy while maintaining a good mean IOU. The performance curves in both experiments exhibit concavity as in the simpler 2D toy example 4.1. This further validates our proposed binary search algorithm in Appendix Sec. 6.2 which relies on the assumption of concavity. Our method UNO-IC is able to capture small details such as pedestrians in the distance even under severe visual degradations. Because the rain condition is not encountered during training, the rgb channel failed to cope with the degradation. UNO [19] dynamically shifts the fusion algorithms weight to the depth channel while our imbalance calibration method gives more weights to small objects. The qualitative and quatitative results in Sec 4.4.2 demonstrate the effectiveness of our unifed perspective 3.1 and Alg. 1. Figure 4: Qualitative results for Synthia Rain. The rain condition is not seen during training. Our algorithm UNO-IC can capture fine details in segmentation even under severe viusal degradation not encounted during training. Our method combined with UNO demonstrates is effective against extreme dataset imbalance and unseen degradations in semantic segmentation.