GithubHelp home page GithubHelp logo

lukasruff / deep-svdd Goto Github PK

View Code? Open in Web Editor NEW
241.0 12.0 64.0 67 KB

Repository for the Deep One-Class Classification ICML 2018 paper

License: MIT License

Python 96.57% Shell 3.43%
anomaly-detection deep-learning one-class-learning theano python machine-learning deep-anomaly-detection icml-2018

deep-svdd's Introduction

Deep One-Class Classification

Update: We now also have implemented Deep SVDD in PyTorch which can be found at https://github.com/lukasruff/Deep-SVDD-PyTorch

This repository provides the implementation of the soft-boundary Deep SVDD and one-class Deep SVDD method we used to perform the experiments for our ”Deep One-Class Classification” ICML 2018 paper. The implementation uses the
Theano and Lasagne libraries.

Citation and Contact

You find the PDF of the Deep One-Class Classification ICML 2018 paper at http://proceedings.mlr.press/v80/ruff18a.html.

If you use our work, please also cite the ICML 2018 paper:

@InProceedings{pmlr-v80-ruff18a,
  title     = {Deep One-Class Classification},
  author    = {Ruff, Lukas and Vandermeulen, Robert A. and G{\"o}rnitz, Nico and Deecke, Lucas and Siddiqui, Shoaib A. and Binder, Alexander and M{\"u}ller, Emmanuel and Kloft, Marius},
  booktitle = {Proceedings of the 35th International Conference on Machine Learning},
  pages     = {4393--4402},
  year      = {2018},
  volume    = {80},
}

If you would like to get in touch, please contact [email protected].

Abstract

Despite the great advances made by deep learning in many machine learning problems, there is a relative dearth of deep learning approaches for anomaly detection. Those approaches which do exist involve networks trained to perform a task other than anomaly detection, namely generative models or compression, which are in turn adapted for use in anomaly detection; they are not trained on an anomaly detection based objective. In this paper we introduce a new anomaly detection method—Deep Support Vector Data Description—, which is trained on an anomaly detection based objective. The adaptation to the deep regime necessitates that our neural network and training procedure satisfy certain properties, which we demonstrate theoretically. We show the effectiveness of our method on MNIST and CIFAR-10 image benchmark datasets as well as on the detection of adversarial examples of GTSRB stop signs.

Installation

This code is written in Python 2.7 and requires the packages listed in requirements.txt in the given versions. We recommend to set up a virtual environment in which the packages are then installed, e.g. using virtualenv:

virtualenv -p python2 env
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
pip install requests
pip install -r requirements.txt

We install Lasagne first as the 0.2.dev1 version is only available from the GitHub Lasagne repository.

To acitvate/deactivate the environment, run

source env/bin/activate
source deactivate

Make sure that Theano floats are set to float32 by default. This can be done by adding

[global]
floatX = float32

to the ~/.theanorc configuration file that is located in your home directory (you may have to create the .theanorc-file if you have not used Theano before).

Repository structure

/data

Contains the data. We implemented support for MNIST and CIFAR-10:

To run the experiments, the datasets must be downloaded from the original sources in their original formats into the data folder.

/src

Source directory that contains all Python code and shell scripts to run experiments.

/log

Directory where the results from the experiments are saved.

To reproduce results

Change your working directory to src and make sure that the respective datasets are downloaded into the data directory. The src directory has two subfolders src/experiments and src/scripts. The scripts directory provides interfaces to run the implemented methods on different datasets with different settings.

The interface for our Deep SVDD method is given by:

sh scripts/mnist_svdd.sh ${device} ${xp_dir} ${seed} ${solver} ${lr} ${n_epochs} ${hard_margin} ${block_coordinate} ${pretrain} ${mnist_normal} ${mnist_outlier};

For example to run a MNIST experiment with 0 as the normal class (mnist_normal = 0) and all other classes considered to be anomalous (mnist_outlier = -1), execute the following line:

sh scripts/mnist_svdd.sh cpu mnist_0vsall 0 adam 0.0001 150 1 0 1 0 -1;

This runs a one-class Deep SVDD (hard_margin = 1 and block_coordinate = 0) experiment with pre-training routine (pretrain = 1) where one-class Deep SVDD is trained for n_epochs = 150 with the Adam optimizer (solver = adam) and a learning rate of lr = 0.0001. The experiment is executed on device = cpu and results are exported to log/mnist_0vsall. For reproducibility, we set seed = 0.

You find descriptions of the various script options within the respective Python files that are called by the shell scripts (e.g. baseline.py).

The experiments directory can be used to hold shell scripts that start multiple experiments at once. For example

sh experiments/mnist_svdd_exp.sh

starts all MNIST one-class Deep SVDD experiments (i.e. ten one-class classification setups each for ten seeds). This particular script runs the experiments on 10 CPUs in parallel.

Disclosure

This implementation is based on the repository https://github.com/oval-group/pl-cnn, which is licensed under the MIT license. The pl-cnn repository is an implementation of the paper Trusting SVM for Piecewise Linear CNNs by Leonard Berrada, Andrew Zisserman and M. Pawan Kumar, which was an initial inspiration for this research project.

deep-svdd's People

Contributors

lukasruff 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

deep-svdd's Issues

How to run soft-boundary Deep SVDD?

I want to run soft-boundary Deep SVDD,but it looks like there's only an implementation of algorithm one-class Deep SVDD. How to run soft-boundary Deep SVDD?

STOP sign dataset

Hello,

I would like to compare with your method in the gtsrb STOP sign database. Could you please direct me to the exact version you tested in your paper? Thanks.

Pram

How to run the mainpy?

Hi sir
When I run the main.py code,it has a mistake ---ValueError: 'default' must be a list when 'multiple' is true.
I think it's the version of 'Click' module, but I don't know why, looking for your reply,thanks a lot.

AssertionError: AbstractConv2d Theano optimization failed:

Hello Authors

I have followed the exact steps mentioned in the guide to setup the working environment
I am working on Ubuntu 18.10 VM on virtual box within mac

Could you please help how to resolve this error below

AssertionError: AbstractConv2d Theano optimization failed: there is no implementation available supporting the requested options. Did you exclude both "conv_dnn" and "conv_gemm" from the optimizer? If on GPU, is cuDNN available and does the GPU support it? If on CPU, do you have a BLAS library installed Theano can link against?

result for MNIST

Dear author.
In MNIST, we use the original training and test splits in our experiments and only train with training set examples from the respective normal class. When I use IF in sklearn package, i find when i choose 0 as normal class, i get auroc is 0.9296.Did I get it wrong?
We look forward to your reply,thank you very much.

GTSRB dataset‘s adversarial example

I'm sorry to bother you, but I'd like to know how you generated the boundary attack adversarial samples of the stop dataset. Or what tools did you use.I'm very confused about this and I hope to get your advice and discuss with you.

Could you please explain how to do prediction using One-Class Deep SVDD?

Thanks for your great work!
There is a point that I do not understand clearly. Since that the objective function of One-Class Deep SVDD (OC-SVDD) is $$\min \limits_{W} \frac{1}{n} \sum_{i=1}^n ||\phi (x_i; W) - c||^2 + regularization_term$$, and the anomaly score is $s(x) = ||\phi(x; W^*) - c||^2$, how to know whether an input $x$ is anomaly or not by this score $s(x)$? It seems that there should be a threshold for $s(x)$ to make determination, but how to calculate this threshold?
Thanks a lot for your reply!

Training epchs

Hello. I have a question regarding the number of epochs you are training for. In the paper, you mention that DCAE is trained for "250+100 epochs" and DSVDD is trained for "150+100" epochs.

Does this mean that:

  • For DCAE, you trained for 250 total epochs, with a learning rate adjustment at epoch 150?
  • For DSVDD, you pretrained the AE for 150 total epochs (pretraining), with a LR adjustment at epoch 50, then trained the DSVDD portion for 150 additional epochs, with a LR adjustment at epoch 50?

Why is my experimental cifar10 result far worse than your paper shows?

Hi, Sir!
Thanks for your excellent idea! I download your code and plan to recreate your experiment results. But when i set the parameters with
'sh scripts/cifar10_svdd.sh gpu cifar 0 adam 0.0001 150 0.1 1 1 0 exp 3 1 -1 ' ,
I got a bad result
Train objective: 1.69638
Train accuracy: 90.02%
Val objective: 1.75854
Val accuracy: 88.90%
Test objective: 3.78288
Test accuracy: 31.02%
Test AUC: 60.71%

I think that something wrong happened, but I dont know how to improve the result. I am looking forward to your reply!

Why I got two different results when all parameters are same? the results can not be reproduced.

Hi, sir. Thanks for your excellent idea!
Now I download your code and re-implement your experiment. But I get tow different results when all parameters are same in two experiment:

sh scripts/cifar10_cae.sh gpu cifar_cae 0 adam 0.0001 350 3 1 -1
sh scripts/cifar10_svdd.sh gpu cifar 0 adam 0.0001 150 0.1 1 1 0 cifar_cae/weights_final 3 1 -1

In first model, I got result:
Train objective: 0.12176
Train accuracy: 90.03%
Val objective: 0.11618
Val accuracy: 91.10%
Test objective: 0.13841
Test accuracy: 23.58%
Test AUC: 62.60%

and then, I set all parameters of the second model exactly the same as the first model, I got the result:
Train objective: 0.12050
Train accuracy: 90.02%
Val objective: 0.11537
Val accuracy: 90.80%
Test objective: 0.13548
Test accuracy: 22.60%
Test AUC: 62.23%

I got the same situation in other classes of cifar-10 dataset. In some class, the difference between the results of two identical models can even reach 2.3%.

I think that something wrong happened, but I don‘t know how to improve the result. I am looking forward to your reply!

Training and testing on custom data?

Thanks for the great work! May I ask if you can provide any guidelines or tutorials on how to use Deep SVDD on custom image datasets?

Any suggestion is highly appreciated!

Possible hard margin R bug?

I've noticed when using hard margin for SVDD, you're resetting R after training each epoch according to the outlier ratio nu.

Written in the code comments:

'set R to be the (1-nu)-th quantile of distances'

However, in

R_new = nnet.diag['train']['scores'][sort_idx, epoch][-out_idx] + nnet.Rvar.get_value()

the first component is getting the (1-nu)-th quantile, but the second component is the original R. Won't this make R exploding?

Thanks.

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.