YangYang-SHU / SAAE-DFR

This is a code implemention for paper "Self-Attention Autoencoder for Anomaly Segmentation"
MIT License
4 stars 1 forks source link

auc_score error, how to fix it? #1

Open leolin65 opened 3 years ago

leolin65 commented 3 years ago

Traceback (most recent call last): File "\SAAE-DFR-main\src\main.py", line 88, in dfr.train() File "\SAAE-DFR-main\src\anoseg_dfr.py", line 193, in train auc = self.validation(epoch) File "\SAAE-DFR-main\src\anoseg_dfr.py", line 582, in validation auc_score, roc = auc_roc(masks, scores) File "\SAAE-DFR-main\src\utils.py", line 190, in auc_roc auc_score = roc_auc_score(mask.ravel(), score.ravel()) File "D:\ProgramData\Anaconda3\envs\env1\lib\site-packages\sklearn\utils\validation.py", line 63, in inner_f return f(*args, *kwargs) File "D:\ProgramData\Anaconda3\envs\env1\lib\site-packages\sklearn\metrics_ranking.py", line 523, in roc_auc_score y_true = check_array(y_true, ensure_2d=False, dtype=None) File "D:\ProgramData\Anaconda3\envs\env1\lib\site-packages\sklearn\utils\validation.py", line 63, in inner_f return f(args, **kwargs) File "D:\ProgramData\Anaconda3\envs\env1\lib\site-packages\sklearn\utils\validation.py", line 726, in check_array raise ValueError("Found array with %d sample(s) (shape=%s) while a" ValueError: Found array with 0 sample(s) (shape=(0,)) while a minimum of 1 is required.

YangYang-SHU commented 3 years ago

Hi. I found there is a bug in the code. In MVTec.py line 194

mask_path = img_name.replace("test", "ground_truth").split(".")[-2] + "_mask.png"

should be changed into

 mask_path = img_name.replace("test", "ground_truth").rpartition(".")[0] + "_mask.png".

I have updated the code. You could download the latest version and see whether it solves your problem.