Computer Science
Computer Science-2021.gz:143457
Computer Science
b2705bdd2d367f7f6b7682594c74d2d15a42eac8
Energy Aligning for Biased Models

Training on class-imbalanced data usually results in biased models that tend to predict samples into the majority classes, which is a common and notorious problem. From the perspective of energy-based model, we demonstrate that the free energies of categories are aligned with the label distribution theoretically, thus the energies of different classes are expected to be close to each other when aiming for ``balanced'' performance. However, we discover a severe energy-bias phenomenon in the models trained on class-imbalanced dataset. To eliminate the bias, we propose a simple and effective method named Energy Aligning by merely adding the calculated shift scalars onto the output logits during inference, which does not require to (i) modify the network architectures, (ii) intervene the standard learning paradigm, (iii) perform two-stage training. The proposed algorithm is evaluated on two class imbalance-related tasks under various settings: class incremental learning and long-tailed recognition. Experimental results show that energy aligning can effectively alleviate class imbalance issue and outperform state-of-the-art methods on several benchmarks.


Introduction
Deep neural networks (DNNs) have achieved tremendous success on a variety of challenging tasks [19,10,33,47,18]. The standard DNNs are usually reliable and powerful when the training data is representative of the evaluation data, i.e., the joint distribution of the observed training data p o (x, y) is consistent with that of the test data p t (x, y) (x represents the data variable, and y stands for the label variable). However, the ideal condition p o (x, y) = p t (x, y) is not always satisfied in realworld applications. The degradation of model performance in realistic scenario due to distribution shift [43,35,38] has been considered to be a main obstacle in the application and development of DNNs. In various distribution shift problems, class imbalance [17,24] in training data is a common and intractable issue, which can be typically formulated as p o (y) = p t (y) [7,25,43]. The huge class imbalance will lead to a biased model, which shows a strong tendency towards the majority classes.
The classical methods for tackling the biased models include re-sampling and re-weighting. Resampling attempts to rebalance the training data by oversampling the minority classes and/or undersampling the majority classes, but may result in overfitting to the minority classes or underutilization of the precious training data [50,4,17,25]. Re-weighting assigns different weights to different classes or training samples, which may cause optimization difficulty [24,57,5,46,73]. Recent studies reveal that decoupling the training procedure into representation learning and classification learning brings about improved overall performance [27,71,69,53,40]. However, most of these methods [27,71,69] are intuitive and heuristic, lacking theoretical foundations.
This paper endeavours to rectify the biased models from the theoretical perspective of energy-based models (EBMs) [31], leading to a simple and effective approach called Energy Aligning. EBMs assign a scalar energy to each configuration of the variables (e.g., the pair (x, y)) -low energies for compatible configurations while high energies for incompatible configurations conventionally. In this work, we reveal that the free energy of a specific category is theoretically aligned with the probability density of the class. Therefore, under the goal of pursuing "balanced" performance, the free energies of different classes are potentially expected to be similar since the target label distribution p t (y) is actually uniform for each class. However, as to a model trained on imbalanced data, we discover that a severe bias is hidden in the free energies: namely the minority classes commonly possess higher free energies while the majority classes usually hold lower free energies. Consequently, we put forward an algorithm -Energy Aligning (EA) to combat the bias. EA attempts to align the free energies of the minority classes to those of the majority classes, which is simply achieved by correcting the predicted logits with the theoretically calculated shift scalars. We delineate that energy aligning can be applied to a purely discriminative classification model, meaning that one can easily obtain a corrected model without modifying the network architectures or altering the standard training procedure. EA is evaluated on two tasks related to class imbalance: class incremental learning [32,45] and long-tailed recognition [37,27], and surpasses state-of-the-art methods with simple operations.
Our key contributions can be summarized as follows: (i) Different from previous work, we theoretically derive a straightforward solution to deal with class imbalance from the energy-based perspective.
(ii) We interpret the bias in models trained on imbalanced data from the view of energy values. Starting from this observation, we propose energy aligning for correcting biased models, which is not only a simple but also a principled approach. (iii) We demonstrate the effectiveness of energy aligning on class incremental learning and long-tailed recognition tasks, from which the experimental results indicate that energy aligning achieves wide applications and significant performance without tedious hyper-parameter tuning.

Energy-Based Models and Discriminative Deep Neural Networks
Energy-Based Models. Considering a model with two sets of variables x (e.g., images) and y (e.g., labels) (x ∈ X , y ∈ Y, X and Y denote the whole space of x and y, respectively), energy-based models (EBMs) capture compatibility by associating a non-probabilistic, scalar energy to each configuration of the variables [31]. Generally, EBMs build an energy function E θ (x, y) that maps each configuration (x, y) to an energy value, where θ is a trainable parameter set. Conventionally, the small energy values represent highly compatible configurations of the variables (when y is suitable for x), while large energy values signify highly incompatible configurations of the variables (when y is incorrect for x). For the decision-making tasks, the system only needs to map the correct answer with the lowest energy, regardless of the magnitude of the energy value. Nevertheless, the uncalibrated energies from separate EBMs are probably not commensurate, so that the energies are required to be normalized in the scenario that the model is going to be used in combination with others. The most common approach is utilizing the Boltzmann distribution (also called Gibbs distribution) to turn the collection of energy values into a probability density: Discriminative Deep Neural Networks. In recent years, a classification task with C classes is typically optimized with a discriminative deep neural network f θ (x) where θ means the learnable parameter set, by which the input variable x is mapped to C scalar values, known as logits. Then, these logits are employed to parameterize a posterior probability distribution over C classes via the softmax function: where f θ (x)[y] represents the y th index of f θ (x), i.e., the logit corresponding to the y th class.
Connection. Compared Eq. (2) with Eq. (1), energy-based models are inherently connected with discriminative neural networks [13,36]. Without changing the parameterization of the neural network f θ (·), we can re-use the logits to represent an energy of the configuration (x, y) as In fact, the negative logit −f θ (x)[y] does reflect the degree of compatibility between x and y -small value of −f θ (x)[y] corresponds to a "good" configuration while large value of −f θ (x)[y] corresponds to a "bad" one, which is exactly what energy-based models require.

Energy Aligning for Biased Models
When learning on a class-imbalanced dataset, the trained model will be biased towards the majority classes [37,27]. In this work, we derive a novel algorithm to rectify the biased model from the perspective of energy-based models, and achieve state-of-the-art performance.
Bias in Energies. Similar to Eq. (1), for EBMs, the joint distribution of x and y can be formulated by using the Boltzmann distribution again, which is expressed as Then, by marginalizing the joint distribution Eq. (4) over x, we obtain where the Helmholtz free energy E θ (y) = − log x ∈X e −E θ (x ,y) . Then, by taking the logarithm of both sides of Eq. (5), we obtain As shown in Eq. (6), the negative free energy −E θ (y) is linearly aligned with log p θ (y), i.e., −E θ (y) ∝ log p θ (y). When it comes to the discriminative neural network f θ (·), combined with Eq. (3), we obtain the negative free energy with model f θ (·): −E θ (y) = log x ∈X e f θ (x ) [y] .
Due to class imbalance, the label distribution of the observed training set is different from that of the target (test) set, which are written as p o (y) and p t (y) respectively. Though the observed training data is imbalanced, it is still expected to achieve balanced predictions and superior overall results during test. In fact, in the popular and common evaluation protocols for class imbalance issue, models are evaluated on the corresponding balanced test data after learning on the imbalanced training data, which alludes a hidden condition that the target label distribution p t (y) is exactly uniform for all classes of interest. Ideally, the model parameterized with θ is expected to reflect the target label distribution, i.e., p θ (y) ≈ p t (y). Therefore, it is desirable to have Moreover, combined with Eq. (6), we expect to have:  Unfortunately, the model trained on imbalanced data actually tends to manifest the label distribution of the training data set, i.e., p o (y) instead of p t (y). To verify the above hypothesis, we conduct an experiment on CIFAR10-LT (the class-imbalanced version of CIFAR10 with label distribution of its training data illustrated in Fig. 1a). Based on the learned model, we estimate the free energies of the ten categories, bringing to light that the majority classes tend to have lower energies whereas the minority classes usually hold higher energies as shown in Fig. 1a. This phenomenon does not conform to Eq. (8), exposing the bias in the trained model from the perspective of energy-based learning.
Energy Aligning. The above analysis have pointed out that the prior label distribution p t (y) hidden in the goal is actually uniform for classes of interest. However, the free energies E θ (y) of the model trained on imbalanced data does not match the prior knowledge (Eq. (8)). Instead of intervening the training process of f θ (·), we propose a simple and effective method, called Energy Aligning (EA), to correct the biased model directly. In EA, the logits are refined to make the energies satisfy Eq. (8).
Without loss of generality, considering the free energies of the i th and j th class (1 ≤ i ≤ C, 1 ≤ j ≤ C, i = j), we view the i th category as the "anchor class" and rebalance the two free energies with a shift scalar α j , which is formulated as Assuming that the shift scalar α j has already been calculated (will be described later), the right side of Eq. (9) can be reformulated as = log x ∈X As shown in Eq. (10), for any input data point, the j th logit can be adjusted by straightforwardly adding a non-learned scalar α j , leading to the advantage that the negative free energies −E θ (y = i) and −E θ (y = j) of the i th and j th classes could be equalized. Intuitively, when In terms of any other category j (j = i), we can adjust the j th logit with corresponding scalar α j to satisfy Eq. (8) similarly, hence the model with energy aligning would treat all categories equally and make Eq. here. The proposed energy aligning strategy is illustrated in Fig. 2. As an example, for the experiment on CIFAR10-LT, the negative free energies of the corrected model is depicted in Fig. 1b, which shows that energy aligning can indeed balance the energies.
Approximation of Shift Scalar α j . In order to acquire α j , the remaining essential problem is how to calculate the terms x ∈X e f θ (x )[i] and x ∈X e f θ (x ) [j] . Avoiding directly computing the intractable integrals, in this work, we employ Monte Carlo integration [6,16] to estimate the integrals. Specifically, for the i th category, the integral is approximated by x ∈X where X ⊂ X is the input space of categories of interest. Since e f θ (x)[i] with the trained θ usually outputs very low response to samples that are almost unrelated to the categories of interest, it suffices to estimate the integral on the subspace X . Data points {x s } S s=1 are sampled from the proposal distribution q(x), which is assumed to assign uniform values to samples from the input space X (i.e., q(x) is a uniform distribution). The same is true for another integral x ∈X e f θ (x ) [j] . Then, we have where LSE S s=1 (z s ) = log S s=1 e zs .
In practice, as to the chosen of samples {x s } S s=1 related to categories of interest, two possible strategies are feasible. The first one is to prepare a balanced validation set on which α j can be calculated. Another more data-saving option is to re-sample a balanced set from the training data (we adopt this strategy here). Different augmentations can be applied to obtain abundant samples that is beneficial for alleviating the estimation error caused by overfitting. Besides augmentations, to further mitigate the insufficient sample issue, we can divide the categories into M clusters within which the same shift scalar is shared, based on the number of training samples per class. Specifically, for class clusters O i and O j with C i and C j categories respectively, similar to Eq. (9), Eq. (10) and Eq. (11), we view cluster O i as the "anchor cluster" and rebalance the average energies for the two clusters with a shared shift scalar α j , which can be formulated as And the estimation of α j is given by Moreover, from the below equation one can still adjust the logits of classes in cluster O j by the shared α j directly for any input data to obtain a corrected model, written as Even though more sophisticated integral approximation methods can be introduced to estimate the shift scalars, we demonstrate that surprising performance can be achieved by employing above simple strategies in comprehensive experiments described in the following sections.

Application I: Class Incremental Learning
In class incremental learning (CIL), models are expected to be able to learn new categories from streaming data without forgetting old categories that they have mastered. Unfortunately, DNNs undergo a serious problem known as catastrophic forgetting [12,39], which reveals that DNNs can hardly recollect old knowledge after learning new knowledge. Many approaches for catastrophic forgetting fail in this scenario [23], while the simple rehearsal strategy, which uses a very small amount of old data to complement training data, has been demonstrated to be effective in CIL [23,54]. Nevertheless, the class imbalance problem that the number of old-classes data is much smaller than that of new-classes data is severe, which is proved to be a vital factor for catastrophic forgetting in CIL [22,58,69]. Even some previous studies [58,69,2,3] focus on the problem of class imbalance in CIL, most of these methods are intuitive and lack a fundamental theory.
In this section, we make an effort to ameliorate the heavily biased models in CIL by the proposed energy aligning. We adopt the algorithm described in [58,69] as baseline, which utilizes rehearsal [45] and distillation [21,32] strategies. After training of each incremental step, we rectify the current model based on energy aligning. Specifically, the old and new categories in each step are regarded as two clusters (M = 2), and the "old cluster" is viewed as the "anchor cluster" O i described in Sec. 3. Then the shift scalar is calculated by Eq. (12), and finally the model is corrected as Eq. (13). The details and pseudo-code for CIL with energy aligning are presented in Appendix A.1.
Datasets. Experiments are conducted on the widely-used ImageNet ILSVRC 2012 [48] and CI-FAR100 [30]. ImageNet ILSVRC 2012 includes about 1.2 million images for training and 50,000 images for validation in which two settings are provided -ImageNet100 which contains 100 randomly selected classes and ImageNet1000 which consists of the whole 1,000 classes. CIFAR100 is comprised of 50,000 images for training and 10,000 images for evaluating with 100 classes.  Protocols. For fair comparisons, in accordance with the conventional experiment settings proposed in previous work [58,45,8,69], ImageNet100 and ImageNet1000 are split into 10 incremental steps with 10 and 100 classes per step, respectively. In addition, 2,000 and 20,000 images are stored for old classes in the experiments on ImageNet100 and ImageNet1000, respectively. CIFAR100 is split into 2, 5, 10 and 20 steps, and 2,000 samples are stored in these experiments. We select rehearsal exemplars randomly. Some frequency distributions are illustrated in Fig. 3a, Fig. 3b and Fig. 3c, indicating the heavily imbalanced training data. More distributions are presented in Appendix B.1.
As new classes arrive, the number of samples can be retained for each class decreases gradually. Thus, the class imbalance problem becomes more serious, while the target label distribution remains exact uniform for each class consistently. For each incremental step, the trained model is evaluated on all seen classes and reported on accuracy. After all, the average accuracy (Avg) over all incremental steps except the first step is calculated (as the first step is actually not related to "incremental").
Effect of Energy Aligning. We perform experiments on ImageNet100 and ImageNet1000 with 10 incremental steps respectively. As shown in Fig. 4a and Fig. 4b, EA significantly improves the performance (the gain in terms of top-5 accuracy in the last incremental step is more than 24% on ImageNet100 and 29% on ImageNet1000). We further plot the confusion matrices (after logarithmic transformation) for the models in the last incremental step on ImageNet100. From Fig. 5a, plain method (without EA) tends to predict objects as new classes, i.e., many samples from old classes   (1~90) are misclassified as new classes (91~100). With the help of EA, the model treats new classes and old classes fairly as shown in Fig. 5b. These results intuitively show that EA can effectively alleviate class imbalance in CIL.
Comparisons with State-of-the-Art. Comparison results with the competitive and representative methods on ImageNet100 and Imagenet1000 are listed in Tab. 1 and Tab. 2, respectively, which apparently substantiate that our proposed algorithm achieves better performance when compared to state-of-the-art approaches, thereby demonstrating the effectiveness of EA again. Similarly, the proposed method also perform well under different settings on CIFAR100 (shown in Appendix C.1).

Application II: Long-Tailed Recognition
Long-tailed distribution of training data is extremely challenging for DNNs, which is natural and common in real world. In this section, we rectify the biased models in long-tailed recognition by energy aligning. We first perform clustering based on the number of training samples per class. The cluster with the smallest average number of samples is treated as "anchor cluster" O i , then for each other cluster O j , the shift scalar can be obtained via Eq. (12). Finally, the model can be corrected by Eq. (13) with the calculated shift scalars. The details and pseudo-code are presented in Appendix A.2. Datasets. Experiments are carried out on long-tailed datasets ImageNet-LT, iNaturalist 2018, CIFAR10-LT and CIFAR100-LT. ImageNet-LT [37], artificially truncated from the original balanced ImageNet ILSVRC 2012 [48], consists of 1000 classes with number of training images per class ranges from 1280 to 5 following a long-tailed distribution. The iNaturalist [55] contains 8,142 classes, which is a real-world, naturally long-tailed dataset. CIFAR10-LT, CIFAR100-LT [7] are the long-tailed versions of CIFAR10 and CIFAR100 [30] with specific degrees of data imbalance. The frequency distributions of ImageNet-LT is presented in Fig. 3d, and others are shown in Appendix B.2.
Protocols. After learning on the long-tailed training data, the models are evaluated on their corresponding balanced test (validation) data. In addition to the overall accuracy, the accuracies on three splits set based on class frequency -Many-shot, Medium-shot and Few-shot are also reported.
Implementation. We implement energy aligning for long-tailed recognition with Pytorch [42]. Following previous work [71,53], ResNet-50 and ResNeXt-50 (32x4d) [64] are employed as backbones for ImageNet-LT, ResNet-50 for iNaturalist and ResNet-32 for CIFAR10-LT and CIFAR100-LT. All implementation details are provided in Appendix A.2. Effect of Energy Aligning. The performance comparisons of models with or without energy aligning on iNaturalist (90 epochs, ResNet50) and ImageNet-LT (90 epochs, ResNeXt-50) are plotted in Fig. 6. With energy aligning, the model performs similarly on "Many", "Medium" and "Few" classes, and accomplishes better overall performance (5.25% and 4.51% gains in terms of top-1 accuracy on iNaturalist and ImageNet-LT, respectively), which demonstrates that the proposed energy aligning can effectively relieve the class imbalance problem in long-tailed recognition.

All Many Medium Few
Influence of number of clusters. We investigate the influence of the number of clusters when performing energy aligning for long-tailed recognition. As depicted in Fig. 7, the results on iNaturalist reveal that all choices for the number of clusters achieve similar performance, which indicates energy aligning in long-tailed recognition is insensitive to the number of clusters. In our experiments, we choose the number of clusters that make the model perform best on the sampled images {x s } S s=1 . More ablation studies are provided in Appendix, such as learning with different classifiers (Appendix D) and optimizers (Appendix E).
Comparisons with State-of-the-Art. We compare the performance of energy aligning to other recent studies that report state-of-the-art results on the commonly-used long-tailed benchmarks. The statistics are presented in Tab. 3 for iNaturalist and Tab. 4 for ImageNet-LT, respectively. For CIFAR10-LT and CIFAR100-LT, the results are provided in Appendix C.2. As evident from these tables, the proposed algorithm mostly surpasses the compared methods by a large margin.

Related Work
Class Imbalance. Class imbalance is naturally inherent in many tasks and applications. When learning on imbalanced dataset, the prediction results will erroneously tend to the majority classes while ignore the minority classes. The class imbalance problem is a classical and challenging topic, which has attracted extensive attention while it is still an open issue [67]. As described in Sec. 1, over-sampling and under-sampling [50,4,17,25] are the most common strategies among data-level methods. As to algorithm-level approaches, apart from the prevalent cost-sensitive learning [24,57,5,46,73], many recent studies incorporate transfer learning [65,37], metric learning [24,41,37], meta learning [57,37,51], hard negative mining [11,34], few-shot learning [37], disentangled representation learning [27,71] into the classical strategies to alleviate the severe bias.
Class Incremental Learning. In CIL, an ideal intelligent system is expected to be able to learn new knowledge continuously from the dynamic environment. However, the standard DNNs suffer from the notorious catastrophic forgetting problem [12,39], meaning that the DNNs tend to forget the old knowledge after learning the new ones. Recent methods alleviate catastrophic forgetting through parameter control [1,29,66], knowledge distillation [32,45,72] and rehearsal [45,59]. Another series of studies, like BiC [58], IL2M [2], WA [69] and ScaIL [3], view class imbalance as an essential factor that causes catastrophic forgetting in class incremental learning, and put forward different solutions to address it.
Long-Tailed Recognition. In a long-tailed dataset, the number of training samples among different categories varies drastically. Long-tailed recognition with DNNs have attracted tremendous attention recently, and some long-tailed benchmarks have been established, such as long-tailed CIFAR10/100 [7], long-tailed ImageNet [37] and iNaturalist [55]. Latest studies [27,71] disentangle the feature learning and the classifier training and achieve promising results. As to the understandings from other aspects, [53] deals with this problem from the perspective of causal inference and [40] presents a statistical framework to cope with the imbalanced label distribution of training data.
Energy-Based Models. EBMs supply a unified formulation for many probabilistic and nonprobabilistic methods [31]. Recent studies have applied EBMs to several unsupervised learning tasks in computer vision, such as generative models [70,60], video generation [63], 3D shape synthesis and analysis [62] and deep probabilistic regression [14,15]. In [61], the authors show that a generative random field model can be derived from a discriminative model. Then, in [13], a standard discriminative model of p θ (y|x) is reinterpreted as an energy-based model for the joint distribution p θ (x, y), and a generative model is incorporated into optimization. In the recent work on out-of-distribution detection [36], the energy-based model is utilized to obtain the probability density p θ (x) by marginalizing the joint distribution Eq. (4) over y: y ) . The above equation suggests that −E θ (x) is linearly aligned with the log probability density p θ (x) ideally. Thus, the free energy E θ (x) is considered more suitable for out-of-distribution detection than the softmax score shown in Eq. (2). The training objective is purely discriminative in [36]. Inspired by it, starting by marginalizing the joint distribution Eq. (4) over x, we derive an approach for correcting the biased models in this work.

Conclusion and Further Work
In this paper, we propose a straightforward and effective algorithm to deal with the model bias issue when training on imbalanced dataset. From the perspective of energy-based models, we systematically analyze the relationship between the free energies of categories and the label distribution. Based on theoretical calculation, we propose the Energy Aligning (EA) approach to adjust output energies of different classes during inference to achieve better overall performance. EA is insensitive to hyper-parameters and by no means intervene training process, and the comprehensive experiments conducted on class incremental learning and long-tailed recognition benchmarks demonstrate that it outperforms many state-of-the-art methods. Though EA has achieved promising results, there are still many efforts need to be done, such as advanced training strategies of EBMs (like [13]), more sophisticated methods to approximate the shift scalars. We hope that the work could encourage more studies to address class imbalance from the perspective of energy-based models.

A.1 Details for Class Incremental Learning
We present the learning process of class incremental learning with energy aligning in Algorithm 1. Assume that B batches of training data {D (b) } B b=1 from different categories are available gradually in which, for the b th incremental step, the new training data D (b) comes from C (b) new classes, and the rehearsal data D As described in Sec. 4, the number of rehearsal samples in each incremental step (except the first step, as there is no old data in the initial step) is constant, i.e., |D old |, so that as more categories are encountered, the number of rehearsal samples per old class decreases, and the problem of class imbalance becomes more serious.
The model f θ (·) is trained with a compound loss: where y * denotes the true label, (x, old , λ is used to balance the two losses which is set to with a hyper-parameter λ base . The cross-entropy loss is defined as where old , Ii=y * is the indicator function and p θ (i|x) is the predicted probability of the i th class defined as Eq. (2). The knowledge distillation loss is defined as old , T represents the temperature of knowledge distillation. The teacher model f θ t ;α (x) is obtained from the (b − 1) th incremental step, which is corrected by a shift scalar α (in class incremental learning, the old classes form the "old cluster" which is viewed as "anchor cluster" (described in Sec. 3), and the new classes form the "new cluster", then, a shift scalar α can be calculated for the "new cluster"). Save as the teacher model for the next incremental step; 5: a dummy shift scalar α is added here for the convenience of the following statement 6: D Select rehearsal samples for the next incremental step 7: for b ∈ 2, · · · , B do For each incremental step 8: Train with loss Eq. (14) 9: Select samples for energy aligning 10: α ← Shif tScalar(f θ , D ea ) Calculate shift scalar by Eq. (12) 11: f θt;α ← DetachCopy(Correct(f θ , α)) Save the model corrected by Eq. (13) as 12: teacher model used in the next step 13: Select rehearsal samples from current 14: new data and rehearsal data 15: end for 16: Output: Model f θt;α Unless otherwise specified, our implementation is based on Pytorch [42]. SGD is used to train models with momentum 0.9 and the cosine classifier is employed. Random crop and horizontal flip are utilized to augment training images. Since the model will be trained for several incremental steps, the base weight decay r base is reduced to r (b) in the b th incremental step by r (b) = r base · η b−1 . For ImageNet, we adopt ResNet-18 [19,20] as backbone with batch size set to 256, learning rate starting from 0.1 and attenuating by 1/10 successively after 30, 60, 80 and 90 epochs (100 epochs in total), λ base set to 1.0, r base set to 0.0005, η set to 0.5 for ImageNet100 and 0.25 for ImageNet1000, respectively. For CIFAR100, a 32-layer ResNet is employed as backbone with batch size set to 32, learning rate starting from 0.1 and attenuating by 1/10 successively after 100, 150 and 200 epochs (250 epochs in total); for 2 steps, λ base = 1.0, r base = 0.0001, η = 0.3; for 5 steps, λ base = 0.75, r base = 0.0002, η = 0.3; for 10 and 20 steps, λ base = 0.5, r base = 0.0004, η = 0.5. All models are trained on a single Tesla V100 GPU. T is set to 2.0 in all experiments. The augmentations employed on the sampled data for energy aligning are listed in Tab. 5 (all the used transformations for augmentation are implemented in torchvision, see in https://pytorch.org/vision/stable/transforms.html). It is worth noting that all the experiments on different datasets and settings for class incremental learning and long-tailed recognition are based on the same augmentation strategies, which shows that the proposed energy aligning is robust.
All the datasets used in our experiments for class incremental learning are available for free to researchers for non-commercial use, and do not contain personally identifiable information or offensive content.

A.2 Details for Long-Tailed Recognition
The detailed learning process of long-tailed recognition with energy aligning is described in Algorithm 2. Assume that training data D including C categories are prepared, the model f θ (·) is trained with the standard cross-entropy loss: where Ii=y * is the indicator function and p θ (i|x) is the predicted probability of the i th class defined as Eq. (2).
Unless otherwise specified, our implementation is based on Pytorch [42]. SGD is used to train models with momentum 0.9 and the cosine classifier is employed. Random crop and horizontal flip are utilized to augment training images. Weight decay is set to 0.0005. For ImageNet-LT, ResNet-50 and ResNeXt-50 (32x4d) [64] are adopted as backbones which are trained for 90 epochs with batch size set to 512. We use the cosine learning rate schedule gradually decaying from 0.2 to 0. For iNaturalist, ResNet-50 is employed as backbone which are trained for 90 epochs and 200 epochs, with batch size set to 512. We use the cosine learning rate schedule gradually decaying from 0.1 to 0. For CIFAR10-LT and CIFAR100-LT, ResNet-32 used in [71] are employed as the backbone which are trained for 200 epochs with batch size of 128. The initial learning rate is set to 0.1 and the first five epochs is trained with the linear warm-up learning rate schedule, and then the learning rate is decayed at the 120 th and 160 th epoch by 0.01 following [71,53]. We use the Jenks natural breaks algorithm 2 [26] to divide the categories into M clusters based on the number of training samples per class. The models for CIFAR10-LT and CIFAR100-LT are trained on a single Tesla V100 GPU, while for ImageNet-LT and iNaturalist are trained on two Tesla V100 GPUs.
All the datasets used in our experiments for long-tailed recognition are available for free to researchers for non-commercial use, and do not contain personally identifiable information or offensive content.

B.1 Frequency Distributions for Class Incremental Learning
For class incremental learning, we plot the frequency distributions of ImageNet1000 with 10 incremental steps in Fig. 8, ImageNet100 with 10 incremental steps in Fig. 9, and CIFAR100 with 20, 10, 5 and 2 incremental  Fig. 10. It can be seen that the problem of class imbalance becomes more serious as more classes are involved.

B.2 Frequency Distributions for Long-Tailed Recognition
For long-tailed recognition, we present the frequency distributions of ImageNet-LT in Fig. 11, iNaturalist in Fig. 13, CIFAR10-LT with different imbalance ratios (the imbalance ratio is defined as the ratio of the number of training samples in the least frequent class and the most frequent class) in Fig. 12, and CIFAR100-LT with different imbalance ratios in Fig. 14, which also show a severe class imbalance problem.
C More Results

C.1 Results for Class Incremental Learning
Additionally, we conduct the class incremental learning experiments on CIFAR100 with 20, 10, 5 and 2 incremental steps (5, 10, 20 and 50 classes per incremental step, respectively) with performance listed in Tab. 6, Tab. 7, Tab. 8 and Tab. 9 respectively. We find that energy aligning can be generalized to different datasets and settings, achieving improved or competitive results compared to state-of-the-art methods.

C.2 Results for Long-Tailed Recognition
We further perform the long-tailed recognition experiments on CIFAR10-LT and CIFAR100-LT with different imbalance ratios with results presented in Tab. 10, which once again demonstrate the effectiveness of the proposed method.

D Combined with Different Classifiers
We further confirm the robustness of energy aligning with different classifiers through experiments. As shown in Fig. 15, no matter whether using a cosine classifier or a linear classifier, the proposed energy aligning can bring significant improvements. It is worth noting that some previous methods, such as weight aligning [69] and τ -normalized [27], will no longer benefit the model trained with cosine classifier due to the weights in fully connected (FC) layers has been normalized by the cosine classifier. However, in this work, we show that even with cosine classifier, the trained model is also biased and the proposed energy aligning can still improve the strong baseline by a large margin.

E Combined with Different Optimizers
We also examine the effectiveness of energy aligning with different optimizers on ImageNet-LT. We use SGD with momentum [52], Adam [28] and SGD without momentum to train models, with statistics presented in Fig. 16. It can be seen that energy aligning achieves improvements on all three models trained with different optimizers. Recent study shows that when training with SGD (with momentum), the norms of weights in FC layers are strongly correlated with class frequency, while with Adam, this phenomenon does not exist [40], so that weight aligning [69] and τ -normalized [27] may fail in such scenarios. However, energy aligning does not suffer this issue. Besides, we also obtain the baseline results when training without momentum (200 epochs), and improve it by a large margin with the help of energy aligning. It can be seen that the model trained without momentum is still heavily biased which can not be fully explained by [53], whereas can be corrected by energy aligning as well.