## 3 Dynamic Anchor
### Anchor Generator  
#### 3.1.1 Anchor Shape Targets  
As shown in Figure 3a, the pre-defined anchor box \(\text{B}=(x,y,w,h)\) is assigned as a positive sample for the ground-truth box \(\text{GT}=\left(x_{gt},y_{gt},w_{gt},h_{gt}\right)\) The distances from the central location \((x,y)\) to the four sides of GT are l, t, r, and b, respectively. As the width and height of B are empiric values, we believe that there is an anchor box \(B^{*}=(x,y,w^{*},h^{*})\) with the same center \((x,y)\) in theory, and the box \(B^{*}\) satisfies the condition: \(IoU(B^{*},\text{GT})>IoU(B,\text{GT})\). IoU means calculating the intersection over the union of two rectangle boxes, as:  
\[IoU(box1,box2)=\frac{box1\cap box2}{box1\cup box2} \tag{1}\]  
Figure 3: (**a**) The red box and the black box represent the ground-truth box \(\left(x_{gt},y_{gt},w_{gt},h_{gt}\right)\) and the corresponding pre-defined anchor \((x,y,w,h)\), respectively. \((x_{gt},y_{gt})\) is the coordinate of the center point of the ground-truth box. \(w_{gt}\) and \(h_{gt}\) represent the width and height of the of the ground-truth box, respectively. l, t, r and b are the distances from the location \((x,y)\) to the four sides of ground-truth box. The width \(w_{gt}\) and height \(h_{gt}\) are calculated by \(w_{gt}=l+r\) and \(h_{gt}=t+b\); (**b**) The yellow box \((x,y,2r,2b)\) represents the best anchor box of box \(\left(x_{gt},y_{gt},w_{gt},h_{gt}\right)\). Figure 2: Illustration of our framework. In dynamic anchor, we employ the anchor generator, a fully convolutional branch to predict the best anchor shape for each location in the feature maps. Then the feature enhancement module is used to enhance feature expression. Finally, we propose the quality branch to suppress low-quality anchors. Therefore, the critical issue is to determine the values of \(w^{*}\) and \(h^{*}\), which can lead to the highest IoU score with the ground-truth box GT. The optimization equation is established as follows:  
\[ \begin{split}\max: IoU\big{[}&(x,y,w^{*},h^{*}),~{} \big{(}x_{gt},y_{gt},w_{gt},h_{gt}\big{)}\big{]}\\ &\text{s.t.}w_{gt}\leq w^{*}\leq 2r\\ & h_{gt}\leq h^{*}\leq 2b\end{split}  \tag{2}\]  
where \(w^{*}\) and \(h^{*}\) are variables to be optimized. To maintain the consistency of the shape targets, the restriction conditions are set to \(w_{gt}\leq w^{*}\) and \(h_{gt}\leq h^{*}\). In fact, if we set \(0\leq w^{*}\) and \(0\leq h^{*}\), we will obtain two types of anchor box solutions. One is smaller than the ground-truth box, and the other is larger than the ground-truth box. Since the small anchor box is not conducive to subsequent feature enhancement, the limiting condition is set to \(w_{gt}\leq w^{*}\) and \(h_{gt}\leq h^{*}\). By transforming Equation (2) into the form of an optimization equation, we obtain Equation (3):  
\[ \begin{split}\min& f(w^{*},h^{*})\\ =&[w^{*}\cdot h^{*}+w_{gt}\cdot h_{gt}-(w^{*}/2+l) \cdot(h^{*}/2+t)]/[(w^{*}/2+l)\cdot(h^{*}/2+t)]\\ &\text{s.t.}w_{gt}-w^{*}\leq 0\\ & w^{*}-2r\leq 0\\ & h_{gt}-h^{*}\leq 0\\ & h^{*}-2b\leq 0\end{split}  \tag{3}\]  
Assuming that there are optimal solutions to Equation (3), and there are parameters defined as, \(\lambda_{1}\), \(\lambda_{2}\), \(\lambda_{3}\), \(\lambda_{4}\), satisfying the following KKT conditions:  
\[\left\{ \begin{array}{c}\left[h^{*}\cdot(w^{*}/2+l)-\frac{1}{2}\big{(}w^{*} \cdot h^{*}+w_{gt}\cdot h_{gt}\big{)}\right]/\left[(w^{*}/2+l)^{2}\cdot(h^{*}/ 2+t)\right]~{}+~{}\lambda_{2}-~{}\lambda_{1}=0\\ \left[w^{*}\cdot(h^{*}/2+t)-\frac{1}{2}\big{(}w^{*}\cdot h^{*}+w_{gt}\cdot h_{ gt}\big{)}\right]/\left[(w^{*}/2+l)\cdot(h^{*}/2+t)^{2}\right]~{}+~{}\lambda_{4}-~{} \lambda_{3}=0\\ \lambda_{1}\cdot(w_{gt}-w)=0\\ \lambda_{2}\cdot(w-2r)=0\\ \lambda_{3}\cdot(h_{gt}-h)=0\\ \lambda_{4}\cdot(h-2b)=0\\ \lambda_{i}\geq 0~{}i=1,~{}2,~{}3,~{}4\end{array} \right. \tag{4}\]  
By solving Equation (4), we obtain five sets of solutions, both feasible and infeasible. The solutions are as follows:  
Feasible solutions:  
\[\text{Solution 1}:~{}\left\{