MTS_CAD
July 28, 2023 ยท View on GitHub
The implementation of CAD which is used in anomaly detection.
Getting started
clone the repo
git clone https://github.com/dawnvince/MTS_CAD.git && cd MTS_CAD
Environment
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.
RUN
Access to data
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.
preprocess data
python gen_data.py
SMD
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
SWaT
Train and Test
./run_SWaT.sh
Get F1 score
python get_score.py --dataset SWaT
WADI
Train and Test
./run_WADI.sh
Get F1 score
python get_score.py --dataset WADI
Score and Label file
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)
Run Your Own Data
If the dataset contains multiple entities like SMD:
- 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.
If the dataset contains only one entity like SWaT:
- 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.