diff --git a/src/anomalib/utils/visualization/image.py b/src/anomalib/utils/visualization/image.py index 3f79283a14..2947af3938 100644 --- a/src/anomalib/utils/visualization/image.py +++ b/src/anomalib/utils/visualization/image.py @@ -263,6 +263,11 @@ def generate(self) -> np.ndarray: """ num_cols = len(self.images) figure_size = (num_cols * 5, 5) + + # Use Agg backend. This method fails when using backend like MacOSX which might be automatically selected + # The dimension of image returned by tostring_rgb() does not match the dimension of the canvas + matplotlib.use("Agg") + self.figure, self.axis = plt.subplots(1, num_cols, figsize=figure_size) self.figure.subplots_adjust(right=0.9)