## 3 Transformer Tank Cover Disassembly Algorithm
### Disassembly of Screw-Fastened Cover Plate
#### 3.3.5 Multi-Head Self-Attention Mechanism  
1. Generate Query, Key, and Value vectors: First, the feature map \(\widehat{S_{i}^{(l)}}\) is mapped into the Query vector \(Q_{i}^{(l)}\), key vector \(K_{i}^{(l)}\), and value vector \(V_{i}^{(l)}\) through linear transformations using the learnable weight matrices \(W_{Q}^{(l)}\), \(W_{K}^{(l)}\), and \(W_{V}^{(l)}\), respectively. \[Q_{i}^{(l)}=W_{Q}^{(l)}Q_{i}^{\text{init}}+W_{Q}^{(l)}\widehat{S_{i}^{(l)}}, \ K_{i}^{(l)}=W_{K}^{(l)}\widehat{S_{i}^{(l)}},\ V_{i}^{(l)}=W_{V}^{(l)} \widehat{S_{i}^{(l)}}.\] (16) 2. Compute the Attention Scores: Attention scores are calculated using the Query vector \(Q_{i}^{(l)}\) and key vector \(K_{i}^{(l)}\). These attention scores are applied to the value vector \(V_{i}^{(l)}\) after normalization through the Softmax function. \[\text{Attention}(Q_{i}^{(l)},K_{i}^{(l)},V_{i}^{(l)})=\text{Softmax}(\frac{Q_ {i}^{(l)}(K_{i}^{(l)})^{T}}{\sqrt{d_{k}}})V_{i}^{(l)}\] (17) where \(d_{k}\) is the dimension of the Query and Key vectors to scale the attention score. (3) Multi-head Attention Fusion: The multi-head self-attention mechanism concatenates the results and generates the final feature representation \(Z_{i}^{(l)}\) using a linear transformation: \[Z_{i}^{(l)}=W_{O}^{(l)}\text{Concat}(\text{Attention}_{1}^{(l)},\text{Attention}_{2}^{(l)}, \dots,\text{Attention}_{h}^{(l)})\] (18) where \(W_{O}^{(l)}\) is the linear transformation matrix of the output and \(h\) is the number of attention heads. (4) Residual Concatenation and Normalization: To preserve the information of input features, the input feature maps \(S_{i}^{(l)}\) are summed with the multi-head attention output \(Z_{i}^{(l)}\) using residual concatenation, followed by normalization by the LayerNorm layer. \[\widetilde{Z_{i}^{(l)}}=\text{LayerNorm}(Z_{i}^{(l)}+S_{i}^{(l)})\] (19) where \(\widetilde{Z_{i}^{(l)}}\) is the normalized feature map.  
5. Feed-forward Network (FFN): The output of each layer \(\widetilde{Z_{i}^{(I)}}\) is further processed by FFN, which consists of two linear layers and a ReLU activation function. \[\text{FFN}(\widetilde{Z_{i}^{(I)}})=W_{2}^{(I)}\text{ReLU}(W_{1}^{(I)}\widetilde {Z_{i}^{(I)}})\] (20) where \(W_{1}^{(I)}\) and \(W_{2}^{(I)}\) is the linear transformation matrices in FFN. 6. Calculation of Bounding Box: After processing through the Mask Transformer, the output includes the center coordinates \((x,y)\), width and height \((w,h)\), and category confidence \(p\) of each prediction frame. The specific calculations are as follows: \[\hat{x} =\sigma(\text{output}_{x}),\quad\hat{y}=\sigma(\text{output}_{y}),\] \[\hat{w} =\exp(\text{output}_{w})\times w_{a},\quad\hat{h}=\exp(\text{ output}_{h})\times h_{a},\] (21) \[p =\sigma(\text{output}_{p})\] where \(\sigma\) is the sigmoid function, \(\text{output}_{x}\), \(\text{output}_{y}\), \(\text{output}_{w}\), \(\text{output}_{h}\), \(\text{output}_{p}\) are the outputs of the network and \((w_{a},h_{a})\) are the width and height of the anchor frame. 7. Output: The final detection result contains the location and category confidence of the nut. \[\text{output}=\{(x,y,w,h,p)\}\] (22) where \((x,y)\) is the center coordinate of the nut. \(w\) and \(h\) are the width and height of the nut. \(p\) is the category confidence.  
After the target detection model outputs the 2D detection frame along with the center point, the coordinates are transformed into the world coordinate system using the camera's intrinsic and extrinsic parameters [37]. During the transformer disassembly process, a camera is mounted on top to capture real-time images of the transformer cover. The improved YOLOv8 model is employed to localize the screw positions, outputting their coordinate positions based on the camera's intrinsic and extrinsic references. These coordinates are then provided to the screwing robotic arm for the disassembly operation. The diagram of the target detection effect is shown in Figure 7.