# Scene Text Detection Using Attention with Depthwise Separable Convolutions
## 3 Proposed Methodology
### The Loss Function  
The **MobileTDNet** is trained in multitask learning accounting the predictions from both output layers. The training loss functions is defined as follows:  
\[L=L_{seg}+\lambda_{r}L_{reg} \tag{1}\]  
Figure 1: **MobileTDNet** scene text detection architecture.  
The \(L_{seg}\) component in Equation (1) represents the segmentation loss, measuring the network's ability to identify text and non-text regions in the input. Simultaneously, the loss component \(L_{reg}\) measures the network's ability to correctly predict the geometric position of text bounding boxes around text lines in the input. Here, \(\lambda_{r}\) represents the regularization parameter. Throughout all the experiments in this work, the parameter \(\lambda_{r}\) is set equal to 1, i.e., both loss components contribute equally.  
The cross-entropy loss, commonly applied in semantic image segmentation tasks, is used for evaluating the segmentation loss \(L_{seg}\). The \(out_{1}\) values are used for calculating \(L_{seg}\). In this case, the loss function measures the difference between the predicted probability distribution and the actual distribution. The conventional cross-entropy loss does not consider the difference between the densities of relevant and non-relevant samples. However, the text/non-text class imbalance is a practical challenge in scene text detection, which limits the detector training performance. To address the issue, online hard example mining [60] has been a popular method for maintaining the balance between positive and negative classes. However, the method increases the number of computational steps and memory requirements in the network training process. In the present formulation, the focal loss function by [PERSON] et al. [61] is applied to measure the segmentation error, which accounts for the text and non-text sample distribution in scene detection. The focal loss incorporates an additional weight factor in the conventional cross-entropy function, which balances the positive and negative classes.  
\[\begin{split} L_{seg}(c_{t})=&-\alpha y^{*}(1-c_{ t})^{\gamma}log(c_{t})\\ &-(1-\alpha)(1-y^{*})c_{t}^{\gamma}log(1-c_{t})\end{split} \tag{2}\]  
The focal loss expression for output \(c_{t}\) with \(y^{*}\)as the ground truth is represented by Equation (2). The term \((1-c_{t})^{\gamma}\) contributes as the density modulating factor in the loss function, with \(\gamma\) as the tunable parameter. As observed, the modulating factor scales down the contribution of easy samples in \(L_{seg}\) based on the selected value of \(\gamma\). Following the analysis presented in [61], the parameter \(\gamma\) is set equal to 2 to conduct all experiments discussed in this work. Furthermore, the expression also incorporates the parameter \(\alpha\) as a density-based balancing factor between two classes, which is computed as follows.  
\[\alpha=1-\frac{\#\text{of text pixels in ground truth}}{\#\text{of pixels in ground truth}} \tag{3}\]  
The component \(L_{reg}\) accounts for the quadrilateral text bounding box prediction error. The \(i\)th position in \(out_{2}\) represents corners of the predicted quadrilateral bounding box in the ordered set  
\[q_{i}=\{(h_{j},w_{j}),\cdots|j\in 0,1,2,3\}\]  
The position loss \(L_{reg}\) refers to the geometric error in bounding box coordinate prediction with respect to the corresponding ground truth \(\hat{q}_{i}\). The loss is calculated using the smooth \(L1\) loss function as follows  
\[L_{reg}(\hat{q}_{i},q_{i})=\sum_{\hat{h}_{j}\in\hat{q}_{i},h_{j}\in q_{i}} \text{smooth}_{L_{1}}(\hat{h}_{j}-h_{j}) \tag{4}\]  
\[\text{where, }\text{smooth}_{L_{1}}(x)=\begin{cases}0.5x^{2}&\text{if }|x|<1,\\ |x-0.5|&\text{otherwise}\end{cases}\]