EfficientAD Unofficial implementation
Download dataset
mkdir mvtec_anomaly_detection_2d
cd mvtec_anomaly_detection_2d
wget https://www.mydrive.ch/shares/38536/3830184030e49fe74747669442f0f282/download/420938113-1629952094/mvtec_anomaly_detection.tar.xz
报错Error parsing proxy URL socks5h://127.0.0.1:8080: Unsupported scheme ‘socks5h’.
修改 wget --no-proxy https://www.mydrive.ch/shares/38536/3830184030e49fe74747669442f0f282/download/420938113-1629952094/mvtec_anomaly_detection.tar.xz
可以了
–2024-05-31 05:23:36-- https://www.mydrive.ch/shares/38536/3830184030e49fe74747669442f0f282/download/420938113-1629952094/mvtec_anomaly_detection.tar.xz
Resolving www.mydrive.ch (www.mydrive.ch)… 91.214.169.64
Connecting to www.mydrive.ch (www.mydrive.ch)|91.214.169.64|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 5264982680 (4.9G) [application/x-xz]
Saving to: ‘mvtec_anomaly_detection.tar.xz’
100%[============================================================================================================================================================================================>] 5,264,982,680 5.36MB/s in 33m 16s
2024-05-31 05:56:54 (2.51 MB/s) - ‘mvtec_anomaly_detection.tar.xz’ saved [5264982680/5264982680]
tar -xvf mvtec_anomaly_detection.tar.xz
Download evaluation code:
cd /tmp/pycharm_project_947/
wget --no-proxy https://www.mydrive.ch/shares/60736/698155e0e6d0467c4ff6203b16a31dc9/download/439517473-1665667812/mvtec_ad_evaluation.tar.xz
tar -xvf mvtec_ad_evaluation.tar.xz
rm mvtec_ad_evaluation.tar.xz
环境配置
conda deactivate
conda create -n zgp_efficientpy38t113 python=3.10
conda activate zgp_efficientpy38t113
从官网历史版本https://pytorch.org/get-started/previous-versions/找到命令
conda install pytorch1.13.1 torchvision0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia(失败)
报错CondaError: Downloaded bytes did not match Content-Length
url: https://conda.anaconda.org/nvidia/linux-64/cuda-nvvp-12.5.39-0.tar.bz2
target_path: /home/cszx/miniconda3/pkgs/cuda-nvvp-12.5.39-0.tar.bz2
Content-Length: 120957289
downloaded bytes: 32160148
CondaError: Downloaded bytes did not match Content-Length
url: https://conda.anaconda.org/nvidia/linux-64/cuda-nvvp-12.5.39-0.tar.bz2
target_path: /home/cszx/miniconda3/pkgs/cuda-nvvp-12.5.39-0.tar.bz2
Content-Length: 120957289
downloaded bytes: 32160148
设置conda config --set remote_read_timeout_secs 6000
conda install pytorch1.13.1 torchvision0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
pip install tifffile==2021.7.30
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting tifffile2021.7.30
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/dc/f4/55ad3c6ffcf12fc5d06e8b361a08d1e9ac774f0c8e5cd74e4947a76794cb/tifffile-2021.7.30-py3-none-any.whl (171 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 171.4/171.4 kB 3.8 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.15.1 in ./miniconda3/envs/zgp_efficientpy38t113/lib/python3.10/site-packages (from tifffile2021.7.30) (1.26.4)
Installing collected packages: tifffile
Successfully installed tifffile-2021.7.30
pip install tqdm4.56.0 scikit-learn1.2.2
Installing collected packages: tqdm, threadpoolctl, scipy, joblib, scikit-learn
Successfully installed joblib-1.4.2 scikit-learn-1.2.2 scipy-1.13.1 threadpoolctl-3.5.0 tqdm-4.56.0
pip install tabulate==0.8.7
运行
pycharm设置
pycharm->setting->python interpreter
->完成SSH连接->system interpreter->选择虚拟环境地址中的bin/python,再设置远程目录保存
efficientad.py代码中修改数据集路径为
/home/cszx/zgp/mvtec_anomaly_detection_2d
{此外70000步太久,可以设置少一些:parser.add_argument(‘-t’, ‘–train_steps’, type=int, default=10000)}
pycharm运行efficientad.py
成功。
之后命令行运行评估代码
conda activate zgp_efficientpy38t113
cd /tmp/pycharm_project_947/
python mvtec_ad_evaluation/evaluate_experiment.py --dataset_base_dir ‘/home/cszx/zgp/mvtec_anomaly_detection_2d/’ --anomaly_maps_dir ‘./output/1/anomaly_maps/mvtec_ad/’ --output_dir ‘./output/1/metrics/mvtec_ad/’ --evaluated_objects bottle
=== Evaluate bottle ===
Parsed 83 ground truth image files.
Read ground truth files and corresponding predictions…
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 83/83 [00:00<00:00, 236.04it/s]
Compute PRO curve…
Sort 67230000 anomaly scores…
AU-PRO (FPR limit: 0.3): 0.9601617231421465
Image-level classification AU-ROC: 1.0
Wrote metrics to ./output/1/metrics/mvtec_ad/metrics.json
成功。
(另外,只迭代10000的结果
补充目录结构
(此外数据集的路径可以填写在efficientad.py代码中)