GithubHelp home page GithubHelp logo

zhangyuxin621 / amsl Goto Github PK

View Code? Open in Web Editor NEW
45.0 2.0 1.0 166.12 MB

Adaptive Memory Networks with Self-supervised Learning for Unsupervised Anomaly Detection (AMSL) -open source

Python 100.00%

amsl's Introduction

AMSL

Code implementation for : Adaptive Memory Networks with Self-supervised Learning for Unsupervised Anomaly Detection(TKDE 2021)

Installation

Requirements

  • Python == 3.6
  • Cuda == 9.1
  • Keras ==2.2.2
  • Tensorflow ==1.8.0

Usage

We use DASADS dataset(refer to UCI) as demo example.

Data Preparation

# run preprocessing.py to generate normal and abnormal datasets.

data
 |-DASADS
 | |-a01  
 | | |-p1  
 | | | |-s01.txt
 | |-...
 | |-a09
 |-generate_dataset
 | |-normal.npy
 | |-abnormal.npy

 # run transformation.py to transform all the data and then separate them into training and testing datasets.

 data
 |-generate_dataset
 | |-normal.npy
 | |-abnormal.npy
 |-transform_dataset
 | |-train_dataset
 | | |-data_raw_train.npy  # raw data
 | | |-data_no_train.npy   # noise data
 | | |-data_ne_train.npy   # negated data
 | | |-data_op_train.npy   # opposite_time data
 | | |-data_pe_train.npy   # permuted data
 | | |-data_sc_train.npy   # scale data
 | | |-data_ti_train.npy   # time_warp data
 | |-test_dataset
 | | |-normal data
 | | | |-data_raw_test.npy  # raw data
 | | | |-data_no_test.npy   # noise data
 | | | |-data_ne_test.npy   # negated data
 | | | |-data_op_test.npy   # opposite_time data
 | | | |-data_pe_test.npy   # permuted data
 | | | |-data_sc_test.npy   # scale data
 | | | |-data_ti_test.npy   # time_warp data
 | | |-abnormal data
 | | | |-data_raw_abnormal.npy  # raw data
 | | | |-data_no_abnormal.npy   # noise data
 | | | |-data_ne_abnormal.npy   # negated data
 | | | |-data_op_abnormal.npy   # opposite_time data
 | | | |-data_pe_abnormal.npy   # permuted data
 | | | |-data_sc_abnormal.npy   # scale data
 | | | |-data_ti_abnormal.npy   # time_warp data

Run

Train model

You can get results of the MSE loss after running train.py.


results
 |-train_normal_loss_sum_mse.csv  #the MSE loss of training data
 |-normal_loss_sum_mse.csv  #the MSE loss of normal data in the testing dataset
 |-abnormal_loss_sum_mse.csv #the MSE loss of abnormal data in the testing dataset

Evaluation

Run evaluate.py to compute the threshold by the MSE loss of training data and achieve the accuracy, precision, recall and F1 score of testing data.

Paper introduction

Unsupervised anomaly detection aims to build models to effectively detect unseen anomalies by only training on the normal data. Although previous reconstruction-based methods have made fruitful progress, their generalization ability is limited due to two critical challenges. First, the training dataset only contains normal patterns, which limits the model generalization ability. Second, the feature representations learned by existing models often lack representativeness which hampers the ability to preserve the diversity of normal patterns (see Fig.1). In this paper, we propose a novel approach called Adaptive Memory Network with Self-supervised Learning (AMSL) to address these challenges and enhance the generalization ability in unsupervised anomaly detection. Based on the convolutional autoencoder structure, AMSL incorporates a self-supervised learning module to learn general normal patterns and an adaptive memory fusion module to learn rich feature representations. Experiments on four public multivariate time series datasets demonstrate that AMSL significantly improves the performance compared to other state-of-the-art methods. Specifically, on the largest CAP sleep stage detection dataset with 900 million samples, AMSL outperforms the second-best baseline by 4%+ in both accuracy and F1 score. Apart from the enhanced generalization ability, AMSL is also more robust against input noise.

1|center

Proposed Approach

1|center

Fig.2: The structure of the proposed AMSL.

We propose a novel Adaptive Memory Network with Self-supervised Learning (AMSL) for unsupervised anomaly detection. AMSL consists of four novel components as shown in Fig. 2: 1) a self-supervised learning module, 2) a global memory module, 3) a local memory module and 4) an adaptive fusion module.

Comparison Methods

1|center

TABLE 3 The comparison of mean precision, recall, F1 and accuracy of AMSL and other baselines.

TABLE 3 reports the overall performance results on these public datasets. It can be observed that the proposed AMSL method achieves significantly superior performance over the baseline methods in all the datasets. Specifically, compared with other methods, AMSL significantly improves the F1 score by 9.07% on PAMAP2 dataset, 4.90% on CAP dataset, 8.77% on DSADS dataset and 2.35% on WESAD dataset. The same pattern goes for precision and recall. Especially for the largest CAP dataset with over 900 Millon samples, AMSL dramatically outperforms the second-best baseline (OCSVM) with an F1 score of 4.90%, indicating its effectiveness.

amsl's People

Contributors

zhangyuxin621 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jc0624

amsl's Issues

Why is class ```Memory_global``` not called after it is defined in #train.py#?

Hi~

  1. I was wondering in

    AMSL/train.py

    Lines 203 to 205 in b72a886

    #############################global memory########################
    inp = Input(shape = (32, 12, filter_size2), name='global_input')
    memory_output, att_weight = Memory_local(mem_dim=filter_size2, fea_dim=global_mem_dim)(inp)
    class Memory_global should have been called on here after it was defined rather than Memory_local , yes?

  2. Also, the definitions of class Memory_local and Memory_global are almost identical, at the same time, (if Q1 is no exception) APIs of

    AMSL/train.py

    Lines 208 to 214 in b72a886

    memory_output_g1, att_weight_g1 = model_global(x1_)
    memory_output_g2, att_weight_g2 = model_global(x2_)
    memory_output_g3, att_weight_g3 = model_global(x3_)
    memory_output_g4, att_weight_g4 = model_global(x4_)
    memory_output_g5, att_weight_g5 = model_global(x5_)
    memory_output_g6, att_weight_g6 = model_global(x6_)
    memory_output_g7, att_weight_g7 = model_global(x7_)
    and

    AMSL/train.py

    Lines 220 to 226 in b72a886

    memory_output1, att_weight1 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_1')(x1_)
    memory_output2, att_weight2 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_2')(x2_)
    memory_output3, att_weight3 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_3')(x3_)
    memory_output4, att_weight4 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_4')(x4_)
    memory_output5, att_weight5 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_5')(x5_)
    memory_output6, att_weight6 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_6')(x6_)
    memory_output7, att_weight7 = Memory_local(mem_dim=filter_size2, fea_dim=local_mem_dim,name='memory_local_7')(x7_)
    are also identical, so I don't know that "global memory module to learn the common representations contained in all transformations, and the local memory module to learn augmentation-specific representations for each transformation" in paper.

Thank you for your attention.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.