  Anomaly detection (AD) is a crucial machine learning task that aims to learn
patterns from a set of normal training samples to identify abnormal samples in
test data. Most existing AD studies assume that the training and test data are
drawn from the same data distribution, but the test data can have large
distribution shifts arising in many real-world applications due to different
natural variations such as new lighting conditions, object poses, or background
appearances, rendering existing AD methods ineffective in such cases. In this
paper, we consider the problem of anomaly detection under distribution shift
and establish performance benchmarks on four widely-used AD and
out-of-distribution (OOD) generalization datasets. We demonstrate that simple
adaptation of state-of-the-art OOD generalization methods to AD settings fails
to work effectively due to the lack of labeled anomaly data. We further
introduce a novel robust AD approach to diverse distribution shifts by
minimizing the distribution gap between in-distribution and OOD normal samples
in both the training and inference stages in an unsupervised way. Our extensive
empirical results on the four datasets show that our approach substantially
outperforms state-of-the-art AD methods and OOD generalization methods on data
with various distribution shifts, while maintaining the detection accuracy on
in-distribution data. Code and data are available at
https://github.com/mala-lab/ADShift.
