The implementation of CAD which is used in anomaly detection.
clone the repo
git clone https://github.com/dawnvince/MTS_CAD.git && cd MTS_CAD
Our implementation uses pytorch-lightning framework with
Pytorch version 1.12.0 and Python 3.8+.
Conda is recommended to set environment.
Install by conda
conda create -n cad python=3.8
conda activate cad
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch -y
conda install -c conda-forge pytorch-lightning==1.8.0 -y
conda install tensorboardX -y
Other dependency or installed by pip please refer to requirement.txt
.
First, please put datasets(SMD, SWaT, WADI) under dataset folder. (Or modify path in gen_data.py
). SMD is available in https://github.com/NetManAIOps/OmniAnomaly; SWaT and WADI are available in https://itrust.sutd.edu.sg/itrust-labs_datasets/dataset_info/. SWaT and WADI needs to be transformed to csv file manually.
Attention: We choose latest SWaT.A2_Dec 2015(Version 1) and WADI.A2. Detailed information can be found in DatasetDetails.md.
python gen_data.py
Train and Test
./run_SMD.sh
Get F1 score
# get best F1 under point-adjustment
python get_score.py --dataset SMD
# get best F1 under k-th point-adjustment
python get_score.py --dataset SMD --kth
Train and Test
./run_SWaT.sh
Get F1 score
python get_score.py --dataset SWaT
Train and Test
./run_WADI.sh
Get F1 score
python get_score.py --dataset WADI
The original result files are saved in folder <dataset>/<data_name>/
, including y.npy
(orignal values in testset), y_hat.npy
(predicted values in testset), y_label.txt
(anomaly score of testsets)
- Add data preprocess function like gen_SMD in
gen_data.py
. MaxMinScaler and clip are needed. - Add your own dataset in the
main
function inget_score.py
like SMD. - Write your own script like
run_SMD.sh
.
- Add data preprocess function like gen_SWaT in
gen_data.py
. MaxMinScaler and clip are needed. - Add your own dataset in the
main
function inget_score.py
like SWaT. - Write your own script like
run_SWaT.sh
.