## 3 Proposed Method
### Proposed Post-Processing Optimization Method  
Figure 3 illustrates our proposed optimization process for OOD segmentation models, in which an SVM classification model is integrated after the baseline defect detection model to filter out false alarms from positive prediction patches. The detection process of the baseline OOD segmentation model is illustrated in Figure 3 with blue arrows. In this process, the model takes the input image \(\chi\) and maps it to anomaly maps \(K\), which are then transformed into a segmentation mask using a binary threshold \(\tau\). The proposed method operates on the binary segmentation results during the testing phase, as illustrated by the red arrows. This conceptualization stems from an observation made during our experiments: a trained segmentation model tends to produce false positives exhibiting distribution patterns similar to those of high-score regions when provided with anomaly-free images as inputs. Such a scenario is commonplace in industrial settings, where images often follow specific acquisition patterns. Consequently, different positions in an image hold corresponding real-world significance, potentially aligning with a component of the system under inspection. Thus, we leverage the distribution characteristics of positive patches to eliminate false alarms. During the testing phase, the baseline OOD model generates a binary candidate mask, where white pixels indicate positives. This candidate mask undergoes connected-component analysis, resulting in multiple subregions, namely positive patches. Bounding boxes are then generated for each patch. Following this, the devised classification model systematically identifies false alarms from these patches based on their distribution characteristics, specifically considering the centroid and scale of each bounding box. Positive patches exhibiting distribution characteristics consistent with those high-score regions in the anomaly maps of anomaly-free images are classified as false positives. Subsequently, their predictions are corrected to negative. Figure 2: Density probability distributions of prediction scores. (**a**) depicts the distribution of anomaly-free targets \(P_{K1}\) produced by the segmentation model in the training process. (**b**) shows the ideal condition of OOD models: When the distribution of the anomalies \(P_{K2}\) is shown as a solid orange line, one threshold exists for successful detection with a perfect AUROC score. Similarly, more thresholds exist for distant distributions like the dotted orange line. (**c**) presents an actual condition that distributions intersect due to inferior discrimination ability. False alarms arise and are present in the red region. To underscore the effectiveness of post-processing using patch-level features in our work, the selection of the binary classification model primarily hinges on its efficiency rather than complex architecture. This choice is grounded in the recognition that the dimensionality of the input vectors is considerably limited compared to image data. The classification model is a soft-margin SVM model capturing the distribution characteristics of false alarm patches. Donate the input vector as \(o_{n}\) and the label indicating a false alarm or a defect as \(y_{n}\), and thus the distance between the closest sample to the hyperplane is:  
\[margin(w)=\underset{n=1,\dots,N}{\text{min}}\text{distance}(o_{n},w) \tag{1}\]  
Hence, the objective function of the classifier is:  
\[\underset{w}{\text{max}}\text{margin}(w) \tag{2}\] \[\quad s.t.\text{ }y_{n}w^{T}x_{n}>0\]  
The kernel of feature transformation is the radial basis function, also known as Gaussian kernel, which improves the computation efficiency of this quadratic programming problem. Kernel learning maps the original linear indivisibility distributions into separable higher dimensions with limited computation cost. The original input space consistent with \(n\) input samples may turn into the separable feature dimension with a maximum of \(n\) dimensions through transformation.