From 3ffc3f6001479d7471cfed7da9005e34605014eb Mon Sep 17 00:00:00 2001 From: Dick Ameln Date: Mon, 7 Aug 2023 16:33:19 +0200 Subject: [PATCH] Enable training with only normal images for MVTec (#1241) * ignore mask check when dataset has only normal samples * update changelog --- CHANGELOG.md | 1 + src/anomalib/data/mvtec.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b17e8d51..7cb433ff24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- Enable training with only normal images for MVTecv in https://github.com/openvinotoolkit/anomalib/pull/1241 - Improve default settings of EfficientAD ### Deprecated diff --git a/src/anomalib/data/mvtec.py b/src/anomalib/data/mvtec.py index 6a807aea57..e4aadfce0c 100644 --- a/src/anomalib/data/mvtec.py +++ b/src/anomalib/data/mvtec.py @@ -153,13 +153,14 @@ def make_mvtec_dataset( ] = mask_samples.image_path.values # assert that the right mask files are associated with the right test images - assert ( - samples.loc[samples.label_index == LabelName.ABNORMAL] - .apply(lambda x: Path(x.image_path).stem in Path(x.mask_path).stem, axis=1) - .all() - ), "Mismatch between anomalous images and ground truth masks. Make sure the mask files in 'ground_truth' \ - folder follow the same naming convention as the anomalous images in the dataset (e.g. image: '000.png', \ - mask: '000.png' or '000_mask.png')." + if len(samples.loc[samples.label_index == LabelName.ABNORMAL]): + assert ( + samples.loc[samples.label_index == LabelName.ABNORMAL] + .apply(lambda x: Path(x.image_path).stem in Path(x.mask_path).stem, axis=1) + .all() + ), "Mismatch between anomalous images and ground truth masks. Make sure the mask files in 'ground_truth' \ + folder follow the same naming convention as the anomalous images in the dataset (e.g. image: \ + '000.png', mask: '000.png' or '000_mask.png')." if split: samples = samples[samples.split == split].reset_index(drop=True)