## 3 Methods
### Feature Completion Mechanism
#### 3.1.2 Self-Attention Mechanism Enhancement Strategy  
Traditional self-attention computation is often performed in pairs, leading to exponential growth in input image size and computational complexity, reaching O(n\({}^{2}\)). Although, theoretically, self-attention has a low-rank for long sequences [40], most pixels in feature maps of images have similar features, making pairwise self-attention computation redundant and inefficient. This study adopts a more efficient self-attention mechanism, as shown in Figure 4, using 1\(\times\)1 convolution and bilinear interpolation [41] to downsample the keys and values, avoiding redundant computation and reducing the size of H and W to h and w, lowering the computational complexity to O(n).  
The specific computation is shown in Equation (3).  
\[SimplifyAttention(Q,\overline{K},\overline{V})=\underbrace{\underset{\overline{ P}_{n}\times k}{\underbrace{soft\text{max}\left(\frac{Q\overline{K}^{T}}{\sqrt{d}} \right)}}}_{\overline{P}_{n}\times k}\underbrace{\overline{V}}_{k\times d} \tag{3}\]  
Here, \(SimplifyAttention(Q,\overline{K},\overline{V})\) represents the simplified self-attention, \(Q\) represents the query vector, \(\overline{K}\) represents the key vector, \(\overline{K}^{T}\) represents the transpose of the key vector, \(\overline{V}\) represents the learned information vector, \(\overline{P}\) is the context aggregation matrix, \(d\) is the dimension of embedding in each head, \(n\) represents the value of HW, \(k\) represents the dimension after bilinear interpolation of the input vector, and k << n. Simultaneously, for relative position encoding in cell microscopy images, this study adds relative height and width information to construct two-dimensional relative position encoding [27]. As shown in Figure 5, taking the pixel point \(i=(Cell_{i_{x}},Cell_{i_{y}}),j=(Cell_{j_{y}},Cell_{j_{y}})\) as an example, the calculation process of position encoding is shown in Equation (4).  
\[l_{Cell_{i},Cell_{j}}=\frac{q_{Cell_{i}}^{T}}{\sqrt{d}}(k_{Cell_{j}}+r_{Cell_{ i_{x}}-Cell_{i_{x}}}^{W}+r_{Cell_{i_{y}}-Cell_{i_{y}}}^{H}) \tag{4}\]  
where \(Cell_{i}\) is the \(i\)-th pixel of the cell image; \(Cell_{i_{x}},Cell_{i_{y}}\) represent the horizontal and vertical coordinates of the i-th pixel of the cell image; \(Cell_{j}\) is the \(j\)-th pixel of the image; \(Cell_{j_{x}},Cell_{j_{y}}\) represent the horizontal and vertical coordinates of the \(j\)-th pixel of the cell image; \(Cell_{i_{x}},Cell_{i_{y}}\) is the relative position encoding of the i-th and \(j\)-th pixels of the cell image;  
Figure 4: Optimized Self-Attention Mechanism.  
\(r^{W}_{Cell_{ij}-Cell_{ix}}\) and \(r^{II}_{Cell_{ij}-Cell_{iy}}\) are the relative width and relative height of the \(i\)-th and \(j\)-th pixels of the cell image calculated after low-dimensional projection; \(k_{Cell_{j}}\) is the key vector of the \(j\)-th pixel of the cell image; \(q^{T}_{Cell_{i}}\) is the transpose of the query vector of the \(i\)-th pixel of the cell image; and the multi-head selective self-attention with two-dimensional relative position encoding is shown in Equation (5).  
\[\begin{split} SimplifyAttention(Q,\overline{K},\overline{V})= \underbrace{softmax\left(\frac{Q\overline{K}^{T}+S^{rel}_{H}+S^{rd}_{W}}{ \sqrt{d}}\right)}_{\overline{P}:\pi\times k}\underbrace{\overline{V}}_{k \times d}\\ S^{rel}_{W}\left[\text{Cell}_{i},Cell_{j}\right]=q^{T}_{Cell_{i}}r^ {W}_{Cell_{j}-Cell_{ix}}S^{rel}_{H}\left[Cell_{i},Cell_{j}\right]=q^{T}_{Cell_{i} }r^{H}_{Cell_{ij}-Cell_{iy}}\end{split} \tag{5}\]  
Equation (6) shows that the multi-head self-attention is finally calculated.  
\[MultiHead(Q,\overline{K},\overline{V})=Concat(head_{1},\dots,head_{h})W^{0} \tag{6}\]  
Here, \(head_{i}=Attention(Q_{i},\overline{K}_{i},\overline{V}_{i})\) and \(head_{i}\) are the outputs of the i-th head; \(W^{0}\) is the output layer; \(Qi\) is the query vector; \(\overline{K}_{i}\) is the key vector; \(\overline{V}_{i}\) is the value vector; and after concatenating all heads, a linear transformation is performed to obtain the output.