# Image Anomaly Detection Using Normal Data Only by Latent Space Resampling
## 4 Experiment
### Comparison Results  
We present separately the results calculated according to the three different evaluation metrics and compared with the baseline methods listed in [PERSON] et al. (2015) as well as with other recent related methods to evaluate the performance of the proposed method. Table 1 shows the average accuracy of correctly classified anomalous and normal images, which demonstrates the ability of the method in the image-level classification task. Our proposed method yields better classification results in 10 of the 15 categories, with improvements ranging from 1% to 35%. It is not as good as CAVGA-D\({}_{u}\)([PERSON] et al., 2016) in both pill and capsule categories due to some anomalies similar to the normal random fine-grained pattern like spots that make the distinction more difficult, but the results are still superior to the baseline method. Tables 2 and 3 show the results of the comparison at the pixel level. Our proposed method is better than other methods as a whole on all metrics. PRO is highly demanding on the segmentation performance of the model under test, and even small areas of anomalous region prediction errors can reduce the value of this metric. We achieve the best results on grid, leather, and zipper, and leading results in the other seven categories as well. It is feasible to restore the anomalous portion of the image by resampling in low-dimensional latent space. Since [PERSON] et al. (2016) does not list specific AUROC, we selected VAE with Attention ([PERSON] et al., 2016) for comparison. Our results at AUROC were better than the second AE\({}_{SSIM}\)([PERSON] et al., 2016) with an 8% improvement as Table 3 showed. Benefiting from the strong reconstruction capability of VQ-VAE and the constraint of resampling operations, the score of anomalies portion in the image is much larger than the normal portion. This leads to better results than other reconstruction-based methods, which mostly suffer from false detection due to insufficient reconstruction of the normal portion. Figure 5: Examples of a negative sample image. We further calculate the the F1 Score at the image level and pixel level to evaluate the classification and segmentation performance of the model. As shown in Table 4, the average result at the image level is 0.89, showing that the proposed model is basically able to correctly distinguish between anomalous and normal images. For pixel-level classification, since the number of anomalous pixels is much smaller than normal pixels, this can greatly affect the precision and thus indirectly the F1 Score. For example, a screw may have anomalies only in the head, and the number of these anomalous pixels accounts for only 1-2% of the image. When the predicted anomaly area is enlarged a bit, the precision may drop by more than 50%, but the prediction is intuitively acceptable in terms of pixel continuity. Although the metric assigns equal weights to positive and negative classes, we think the proposed model gives relatively good results, with the mean value 0.17 higher than AE-L2. Furthermore, we present the distribution of anomaly score for leather/screw/pill in Figure 6. The proposed model tends to assign high anomaly scores to anomalous pixels and low anomaly scores to normal pixels. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline  & **Category** & **Proposed** & \begin{tabular}{c} **VAE with** \\ **Attention** \\ **[35]** \\ \end{tabular}  & \begin{tabular}{c} **AE\({}_{SSIM}\)** \\ **[9]** \\ \end{tabular}  & \begin{tabular}{c} **AE\({}_{L2}\)** \\ **[9]** \\ \end{tabular}  & \begin{tabular}{c} **AnoGAN** \\ **[39]** \\ \end{tabular}  & \begin{tabular}{c} **CNNFD** \\ **[21]** \\ \end{tabular}  \\ \hline \multirow{4}{*}{ \begin{tabular}{c} **CNNFD** \\ **Attention** \\ **[39]** \\ \end{tabular}  } & \ \begin{tabular}{c} Carpet \\ Grid \\ Wood \\ Leather \\ Tile \\ \end{tabular}