## 3 Materials and Methods
### Adaptive Anchor Module  
Inspired by GA [25], an adaptive anchor module (AAM) is proposed in this work which could yield more suitable anchor boxes for different surface defects. Given an image \(I\), the probability of a surface defect can be expressed as  
\[p(x,y,w,h|I)=p(x,y|I)p(w,h|x,y,I) \tag{13}\]  
Figure 4: Adaptive convolution module (ACM).  
where \((x,y)\) denotes the center of surface defect, and \((w,h)\) is the width an height respectively. This equation indicates that the shape of a surface defect is closely related to its location. Following this formulation, AAM first identifies locations where the centers of surface defects are likely to exist and then predicts the shapes at different locations. Furthermore, we devise a location-guided shape adaptation component in this work, which can utilize the location information to yield more suitable anchors.  
As demonstrated in Figure 5. Firstly, given a feature map from the neck of detector, the subnet Csubnet and BSubnet is utilized to yield class features (RF) and box features (CF), respectively. Next, a \(1\times 1\) convolution with Sigmoid function is employed to yield a probability map which indicates the locations where the centers of surface defects are likely to exist. The probability map is the same size as CF. The value of each entry of probability map denotes the probability that the center of a surface defect may exist at that location. Based on the probability map, the regions where surface defects may exist could be selected. Therefore, there is no need to take those excluded regions into account.  
Then, the shapes of the anchors where surface defects may exist at each location is determined. As shown in Equation (13), the shape of an anchor closely relates to its location. Therefore, a location-guided shape adaptation module is designed in this work to yield more suitable anchors. Specifically, the shape adaptation module consists of two parts: (1) A probability map is input two \(3\times 3\) convolutions to yield shape offsets; (2) A \(3\times 3\) deformable convolution (DC) is utilized to improve regression features by using the shape offsets. By these operations, the shapes of anchors can be adapted via location information. Afterwards, the shapes of anchors can be predicted via a \(1\times 1\) convolutional layer. It is also worth noting that just one anchor box is placed at each available location.  
Finally, feature adaptation is adopted to transform the original feature map (i.e., CF and BF) according to the anchor shape information. It utilizes a \(1\times 1\) convolutional layer to obtain location offsets from the shape map, and then applies a \(3\times 3\) deformable convolution to the original features, similar to the shape adaptation module.  
Figure 5: Adaptive anchor module (AAM).  
A multi-task loss function as in GA [25] is utilized to optimize the framework in an end-to-end way. The multi-task loss function can be defined as  
\[L=\lambda_{1}L_{loc}+\lambda_{2}L_{shape}+L_{cls}+L_{reg} \tag{14}\]  
where \(L_{loc}\) is a focal loss [38] to optimize the locations. As for \(L_{shape}\), we use a variant bounded iou loss as in [25] to only optimize the shape of anchor. \(L_{cls}\) is a focal loss [38] and \(L_{reg}\) is \(L_{1}\) loss [44]. In our experiments, \(\lambda_{1}=1\) and \(\lambda_{1}=0.1\).