Skip to content

dawnvince/MTS_CAD

Repository files navigation

MTS_CAD

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:

  1. Add data preprocess function like gen_SMD in gen_data.py. MaxMinScaler and clip are needed.
  2. Add your own dataset in the main function in get_score.py like SMD.
  3. Write your own script like run_SMD.sh.

If the dataset contains only one entity like SWaT:

  1. Add data preprocess function like gen_SWaT in gen_data.py. MaxMinScaler and clip are needed.
  2. Add your own dataset in the main function in get_score.py like SWaT.
  3. Write your own script like run_SWaT.sh.

The other processes are just like above.

About

The implementation of CAD which is used in anomaly detection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors