# Tire Defect Detection via 3D Laser Scanning Technology
## 2 Materials and Methods
### Attention-Based Detector  
Inspired by the successful applications of transformers in 2D detection [8; 9; 17], we devise a novel attention-based detector that can effectively capture various forms of defects. The details of the proposed detector are illustrated in Figure 4.  
* **Deformable Attention** Applying vanilla-transformer-style attention on image feature maps necessitates looking over all spatial locations [9], which brings huge computational costs. To tackle this problem, we devise a deformable attention operation, where each pixel only needs to attend to its neighboring pixels. We follow the spirit of deformable convolutions [18; 19] to enlarge the receptive field and capture long-range dependency, where each pixel can attend to its neighboring pixels in a large range with adaptive offsets. Specifically, given an input feature map \(X\in\mathbb{R}^{C\times H\times W}\), let \(q\) denote the index of the query pixel with corresponding feature \(x_{q}\in\mathbb{R}^{C}\) and 2D coordinate \(p_{q}\in\mathbb{R}^{2}\), and the aggregated feature via deformable attention is calculated by \[\text{DeformAttn}(x_{q},p_{q})=\sum_{k=1}^{K}A_{qk}\cdot W(x_{p_{q}+\Delta_{qk }})\] (2) where \(k\) represents the index of the sampled key pixels and \(K\) is the total number of key pixels. Note that \(K\ll HW\) for efficiency. \(\Delta_{qk}\) and \(A_{qk}\), respectively, denote the adaptive offset and attention weight of the \(k\)th sampling point. \(A_{qk}\) is calculated by subtracting  
Figure 4: Our detector based on the proposed deformable attention. (**a**) DA-Detector consisting of a backbone (ResNet50), DA-FPN, and a decoder. (**b**) Details of DA-FPN, where deformable attention operation is used to replace the vanilla \(1\times 1\) convolution. (**c**) Cross-attention mechanism is used to extract the features of DA-FPN with object queries. With a self-attention mechanism, object queries interact with each other. For query generation, we use a top-k selection strategy instead of vanilla learnable queries.  
with \(x_{p_{q}+\Delta p_{qk}}\), followed by a multilayer perceptron (MLP). Following a previous study [20], the value of \(A_{qk}\) lies in the range \([0,1]\), which is normalized by the softmax function. Meanwhile, \(\Delta_{qk}\) is obtained via linear projection over the query feature \(x_{q}\) following a previous study [18]. As with deformable convolutions, \(p_{q}+\Delta_{qk}\) is fractional; therefore, bilinear interpolation is applied in computing \(x_{p_{q}+\Delta_{qk}}\). Note that our proposed deformable attention works like a deformable convolution but with adaptive weights determined by data.
* **Defect Detector Based on the Proposed Deformable Attention** As shown in Figure 4a, following the spirit of detection with transformer (DETR) [9] and fully convolutional one-stage (FCOS) detection [21], our detector mainly consists of a domain adaptive (DA) feature pyramid network (FPN) and DA-decoder. FPN [22] is one of the most important modules for detection. Following the top-down architecture of FPN, we replace the original \(1\times 1\) convolution with deformable attention operation to capture local properties (as shown in Figure 4b), dubbed as DA-FPN. With all pixels in the last feature map, we employ top-k selection to select object queries with the maximum activation value, which is adaptively generated by MLP. Then, we concat them with learnable queries [9] for object queries. The DA-decoder mainly consists of \(L\) DA-decoding blocks. There are cross-attention and self-attention modules in each block. In the cross-attention module, object queries extract features from the feature map, where the key elements are around the query pixels whose normalized coordinates are predicted by MLP. In each self-attention module, object queries interact with each other with the help of deformable attention without sampling. During training, we follow DETR [9] and utilize a bipartite matching algorithm to match GT and object queries.