The implementation of CAD which is used in anomaly detection.
clone the repo
git clone https://github.com/dawnvince/MTS_CAD.git && cd MTS_CADOur 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.shGet 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 --kthTrain and Test
./run_SWaT.shGet F1 score
python get_score.py --dataset SWaTTrain and Test
./run_WADI.shGet F1 score
python get_score.py --dataset WADIThe 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
mainfunction inget_score.pylike 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
mainfunction inget_score.pylike SWaT. - Write your own script like
run_SWaT.sh.