## 3 Materials and Methods
### First-Frame Localization Model Based on Improved RFBNet
#### 3.1.2 Loss Function  
To enhance the efficacy of the model and augment the performance of the lightweight model for first-frame localization, we pursue optimization based on the SSD loss function. The expression is as follows:  
\[L(x,c,l,g)=\frac{1}{N}(L_{\text{conf}}(x,c)+\alpha L_{\text{loc}}(x,l,g)) \tag{1}\]  
where \(L(x,c,l,g)\) denotes the loss function, \(N\) denotes the number of matches to the default box, \(x\) denotes the input sample, \(c\) denotes the confidence level, \(l\) denotes the prediction box, \(g\) denotes the true box, and \(a\) denotes the weight coefficients for classification and regression. The loss function is the sum of the confidence loss and the position loss. The confidence loss is \(L_{\text{conf}}(x,c)\). To make the perforation machine arm more distinguishable from the tunnel background, the focal loss is introduced and the positive and negative sample weight coefficients are increased. The focal loss formula is  
\[FL(p_{t})=-\alpha_{t}(1-p_{t})^{\gamma}\log(p_{t}) \tag{2}\]  
Confidence losses are specified as follows:  
\[L_{\text{conf}}(x,c)=-\sum_{i\in\text{Pos}}^{N}\omega_{p}\kappa_{lj}^{p}(1- \epsilon_{i}^{p})^{\gamma}\log(\epsilon_{i}^{p})-\beta\sum_{i\in\text{Neg}} \log(\epsilon_{i}^{p}) \tag{3}\]  
\[\epsilon_{i}^{p}=\frac{\exp(c_{i}^{p})}{\sum_{p}\exp(c_{i}^{p})} \tag{4}\]  
where \(L_{\text{conf}}(x,c)\) is the confidence loss, \(\epsilon_{i}^{p}\) is the probability value of the category predicted by the first prediction box, \(c_{i}^{p}\) is the confidence prediction value of the category predicted by the first prediction box, \(\kappa_{lj}^{p}\) is the match value of the first prediction box and the first true box of the category \(p\), where taking 1 means that the first prediction box matches the first true box and taking 0 means that it does not match, \(l\) is the serial number of the prediction box, \(j\) is the serial number of the true box, \(p\) is the serial number of the category, Pos is a positive sample, Neg is a negative sample, \(\omega_{p}\) is the weight of the category \(p\), and \(\beta\) is the weight coefficient between positive and negative samples. The position loss is \(L_{\text{loc}}(x,l,g)\). To increase the sensitivity of the punching machine arm target frame to errors and to more accurately locate the position of the punching  
Figure 4: Comparison of tracking results of the proposed method with the baseline algorithm and the classical algorithm. machine arm target frame, the position loss is rooted for the width and height values of the prediction frame:  
\[ \begin{split} L_{\text{loc}}(x,l,g)=\sum_{i\in\text{Pos}}^{N}x_{j}^{ p}\bigg{(}&\text{smooth}_{L1}(l_{i}^{cx}-\mathcal{G}_{j}^{cx})\\ &+\text{smooth}_{L1}(l_{i}^{cy}-\mathcal{G}_{j}^{cy})\\ &+\text{smooth}_{L1}\bigg{(}\sqrt{w_{i}^{l}}-\sqrt{\hat{g}_{j}^{ uv}}\bigg{)}\\ &+\text{smooth}_{L1}\bigg{(}\sqrt{h_{l}^{l}}-\sqrt{\hat{g}_{j}^{ u}}\bigg{)}\bigg{)}\end{split}  \tag{5}\]  
\[\text{smooth}_{L1}(x)= \begin{cases}0.5x^{2}&\text{if }|x|<1\\ |x|-0.5&\text{otherwise}\end{cases}  \tag{6}\]  
\[ \begin{split}\hat{g}_{j}=\begin{bmatrix}\mathcal{G}_{j}^{cx}\\ \hat{g}_{j}^{cy}\\ \hat{g}_{j}^{y}\\ \hat{g}_{j}^{y}\end{bmatrix}=\begin{bmatrix}\left(\frac{\mathcal{G}_{j}^{cx}- \mathcal{G}_{j}^{cx}}{\mathcal{G}_{j}^{y}}\right)\\ \left(\frac{\mathcal{G}_{j}^{cy}-\mathcal{G}_{j}^{cy}}{\mathcal{G}_{j}^{y}} \right)\\ \log\left(\frac{\mathcal{G}_{j}^{cy}}{\mathcal{G}_{j}^{y}}\right)\\ \log\left(\frac{\mathcal{G}_{j}^{y}}{\mathcal{G}_{j}^{y}}\right)\end{bmatrix} \end{split}