# BWLM: A Balanced Weight Learning Mechanism for Long-Tailed Image Recognition
## 3 Method
### Bwlm  
We explain how BWLM works in our second stage starting by introducing the two important elements in BWLM: BFS loss function and weight decay. **BFS Loss** aims to solve the problem of training from long-tailed data by focusing on a reweighting strategy that simultaneously focuses on common and rare classes. We choose Class-Balanced (CB) [31] loss to focus on common classes. This method introduces a weight factor  
\[(1-\beta)/(1-\beta^{n_{j}}) \tag{5}\]  
We add it to the loss function to design a balanced loss function to solve the problem of data imbalance in the training. It is inversely proportional to the number of effective samples. As a hyperparameter \(\beta\in[0,1)\), \(n_{j}\) represents the total sample size contained in class \(j\) and the balanced focal loss is defined as:  
\[L_{CB}(z,y)=-\frac{1-\beta}{1-\beta^{n_{j}}}L_{FL(z,y)} \tag{6}\]  
The focal loss \(L_{FL(z,y)}\)[47] can reduce the weight of well-classified samples and make the model focus on difficult samples during training. \(p_{j}^{t}=1/(1+exp(-z_{j}^{t}))\) is the estimated probability of class \(j\), where \(t\) means the target. The focal loss is  
\[L_{FL}(z,y)=\sum_{j=1}^{\mathrm{C}}(1-p_{j}^{t})^{\gamma}log(p_{j}^{t}) \tag{7}\]  
where \(\gamma\) is the focusing parameter that can reduce the weight of simple samples. The balanced focal loss is expanded as:  
\[L_{CB}(z,y)=-\frac{1-\beta}{1-\beta^{n_{y}}}\sum_{j=1}^{\mathrm{C}}(1-p_{j}^{ t})^{\gamma}log(p_{j}^{t}) \tag{8}\]  
Overall, the idea can be summarized as follows: By estimating the number of effective samples and reweighting the focal loss, it captures the marginal decreasing effect of the data and reduces redundant information in the common samples. To remove the discrepancy between the test set's and the training set's posterior distributions [56], we use a balanced softmax [32]  
\[\phi_{j}=\frac{n_{j}e^{z_{j}}}{\sum_{i=1}^{\mathrm{C}}n_{i}e^{z_{i}}} \tag{9}\]  
In order to avoid bias in testing and training, it considers label distribution shifts and derives softmax suitable for the long-tailed problem using the exponential family form of Multinomial. This tends to focus on rare classes. Similarly, we obtain the Balanced Softmax (BS) loss:  
\[L_{BS}(z,y)=-log(\phi_{y})=-log(\frac{n_{y}e^{z_{y}}}{\sum_{i=1}^{\mathrm{C}}n _{i}e^{z_{i}}}) \tag{10}\]  
Based on the characteristics of class-balanced focal loss and balanced softmax loss, it can be analyzed that class-balanced focal loss pays more attention to selecting effective samples for the common classes. Balanced softmax loss reduces the preference of the classifier towards the common classes caused by the difference in posterior distributionsbetween the training and testing sets. Therefore, we propose a balanced loss function BFS loss that can address both common and rare classes. BFS is denoted as:  
\[L_{BFS} =\alpha\frac{1-\beta}{1-\beta^{n_{y}}}L_{FL(z,y)}+[-(1-\alpha)log( \phi_{y})] \tag{11}\] \[=\alpha\frac{1-\beta}{1-\beta^{n_{y}}}L_{FL(z,y)}+(\alpha-1)log( \phi_{y})]\] (12) \[=(\alpha-1)log(\frac{n_{y}e^{z_{y}}}{\sum_{i=1}^{C}n_{i}e^{z_{i}} })-\frac{\alpha(1-\beta)}{1-\beta^{n_{y}}}\sum_{j=1}^{C}(1-p_{j}^{t})^{\gamma} log(p_{j}^{t}) \tag{13}\]  
We discuss the selection of \(\alpha\) as a weight and hyperparameter in Section 4.3. **Weight Decay** is a relatively mature research [57, 58] that constrains the networks by limiting the growth of the network weights [52], which can reduce network complexity, reduce over-fitting, and improve the generalization ability of the network. Weight decay [52] applies the L2-norm to the network weights:  
\[\hat{\Theta}=\underset{\Theta_{fc}}{argmin}F\left(\Theta_{fc};\hat{D}\right)_ {\Theta^{*}}+\lambda\sum_{j}\
orm{\theta_{j}}_{2}^{2} \tag{14}\]  
We select the value of hyperparameter \(\lambda\) based on [52]. Weight decay increases the penalty for larger weights to prevent them from growing larger while emphasizing the learning of smaller weights.