# Advanced Text Detection of Container Numbers via Dual-Branch Adaptive Multi-Scale Network
## 3 Methods
### Dual-Loss Strategy
#### 3.3.2 Loss Function  
The proposed text detection method involves generating probability maps and threshold maps from input natural scene images. Subsequently, a differentiable binary module is employed to binarize the probability map. Finally, the text detection regions are obtained through post-processing. The loss function is defined as the weighted sum of three loss functions, it can be expressed as follows:  
\[L=L_{s}+\alpha L_{t}+\beta L_{b} \tag{5}\]  
where \(L_{s}\) represents the loss function for the probability map, \(L_{t}\) the threshold map, and \(L_{b}\) is the loss of binary graph. \(\alpha\) is initialized to 1.0, and \(\beta\) is assigned to 10. If BCE loss is directly employed for both the probability map and the binary map, the non-text regions tend to dominate, potentially resulting in insufficient attention to the smaller text regions. This could bias the probability map predictor and binary classifier towards favoring non-text regions over text regions of interest. To tackle the imbalance issue of positive and negative samples, the Dice loss function is often deemed a superior alternative. However, in the specific context of text detection, wherein text often manifests as small foreground objects, the direct application of Dice loss can introduce instability. Once some pixels of the small object are incorrectly predicted, the loss value will change dramatically, leading to drastic fluctuations in gradients. This situation poses a significant challenge for the stable training of text detection models. Accordingly, we employ a compromise strategy by solely applying the Dice loss function to the probability map loss computation, aiming to balance the impact of positive and negative samples. Regarding the binary map, BCE loss is maintained to guarantee higher accuracy in predicting text regions. This way, we not only address the imbalance issue but also ensure the stability and accuracy of text detection. The loss \(L_{s}\)[34] for the probability map is defined as follows:  
\[L_{s}=\sum_{i\in S_{l}}y_{i}\log x_{i}+(1-y_{i})\log(1-x_{i}) \tag{6}\]  
where the cross-entropy is calculated between the predicted value \(x_{i}\) and the ground truth \(y_{i}\) for each pixel \(i\) within the text region \(S_{l}\) in the probability map. The loss \(L_{b}\) for the binary map is defined as follows:  
\[L_{b}=1-D_{b} \tag{7}\]  
\[D_{b}=\frac{2\sum_{i}(P_{b}(i)\cdot G_{b}(i))}{\sum_{i}P_{b}(i)^{2}+\sum_{i}G_ {b}(i)^{2}} \tag{8}\]  
where the Dice coefficient is used in the probability map to quantify the similarity between predicted and ground truth text regions. In this context, \(D_{b}\) represents the Dice coefficient, indicating the degree of overlap between the predicted and ground truth text regions. The output of the probability map predictor, \(P_{b}(i)\) represents the predicted probability value for the pixel at position \(i\), while \(G_{b}(i)\) represents the ground truth label for the pixel at position \(i\), where 1 indicates a text region and 0 indicates the background. \(L_{t}\) represents an extended metric that calculates the total distance between the true label values and the predicted values in the expanded text polygon \(G_{d}\). The calculation formula for \(L_{t}\), which represents this distance, is defined as follows:  
\[L_{t}=\sum_{i\in\mathcal{R}_{l}}\left|y_{i}^{*}-x_{i}^{*}\right| \tag{9}\]  
where \(R_{d}\) denotes the set of pixels comprising the expanded polygon \(G_{d}\), whereas \(y^{*}\) signifies the label value assigned to the threshold map.