Giter Club home page Giter Club logo

alocc-cvpr2018's Introduction

Adversarially Learned One-Class Classifier for Novelty Detection (ALOCC-CVPR2018)

[CVPR Poster] [presentation] [Project] [Paper] [tensorflow code] [keras code]

This work was inspired by the success of generative adversarial networks (GANs) for training deep models in unsupervised and semi-supervised settings. We proposed an end-to-end architecture for one-class classification. The architecture is composed of two deep networks, each of which trained by competing with each other while collaborating to understand the underlying concept in the target class, and then classify the testing samples. One network works as the novelty detector, while the other supports it by enhancing the inlier samples and distorting the outliers. The intuition is that the separability of the enhanced inliers and distorted outliers is much better than deciding on the original samples.

Here is the preliminary version of the code on grayscale databases.

Please feel free to contact me if you have any questions.

overview

Note: The current software works well with TensorFlow 1.2

Prerequisites

  • Windows, Linux or macOS
  • Python 3
  • CPU or NVIDIA GPU + CUDA CuDNN

Getting Started

Installation

# GPU version
pip install tensorflow-gpu

#CPU version
pip install tensorflow
  • Install pillow,scipy,skimage,imageio,numpy,matplotlib
pip install numpy scipy scikit-image imageio matplotlib pillow
  • Clone this repo:
git clone https://github.com/khalooei/ALOCC-CVPR2018
cd ALOCC-CVPR2018

ALOCC train

  • Download a UCSD dataset:
mkdir dataset
cd dataset
wget http://www.svcl.ucsd.edu/projects/anomaly/UCSD_Anomaly_Dataset.tar.gz
tar -xzf UCSD_Anomaly_Dataset.tar.gz
  • Config path of dataset and dataset name :
# for train on UCSD and patch_size 45*45
python train.py --dataset UCSD --dataset_address ./dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train --input_height 45 --output_height 45 

# for train on MNIST
python train.py --dataset mnist --dataset_address ./dataset/mnist/ --input_height 28 --output_height 28

ALOCC's Cheat sheet

  • First, prepare your dataset similar to what we did for UCSD or MNSIT datasets in the code. Then, add the data loading code in models.py file from line 180 up to 190 as UCSD/MNIST. You can pass a parameter as bellow:
--dataset MyDataSetName --dataset_address ./pathOfMyDataSetName
  • Set the patch size:
--input_height 60 --output_height 60
  • See the 'train.py' file, for other hyperparameters of the method, and set them if need be.
  • To change architectures of submodules in ALOCC, refer to the model.py file. We have some pre/post processing functions in kh_tools.py and utils.py. Also, we have some abstract function of Conv or similar functions in ops.py. You can change the test process in test.py and also model.py from line 460 to the end.
  • If you have any further questions, please don't hesitate to contact me 🌹 .
  • Also, contributions are welcome. If you implement our paper in other framework or implementation style, you can contact me to publish your link on this page.

- To view the training results, access them within the export directory.

ALOCC test

  • You can run the following commands:
# for test on UCSD and patch_size 45*45 and some specific dir like ['Test004'], etc. We prefer to open test.py file and edit every thing that you want
python test.py --dataset UCSD --dataset_address ./dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train --input_height 45 --output_height 45 

# for test on MNIST
python test.py --dataset mnist --dataset_address ./dataset/mnist/ --input_height 28 --output_height 28

Apply a pre-trained model (ALOCC)

  • You can use a pretrained model and locate directory path to train.py or test.py file.
  • The pretrained model is saved at
./checkpoints/{datasetname}_{batch_size}_{patch_size}
  • To view test results you can access them from samples directory

MNIST

input:

Generated:

UCSD

input:

Generated:


Citation

If you use this code or idea for your research, please cite our papers.

@inproceedings{sabokrou2018adversarially,
  title={Adversarially Learned One-Class Classifier for Novelty Detection},
  author={Sabokrou, Mohammad and Khalooei, Mohammad and Fathy, Mahmood and Adeli, Ehsan},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  pages={3379--3388},
  year={2018}
}

alocc-cvpr2018's People

Contributors

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

alocc-cvpr2018's Issues

Some problems about the output of results_d

hello~
when I trained and tested on my own dataset, I got some weird output from results_d: there exists negative value and values which is bigger than 1.0, such as:

results d: [[-0.06518985]
 [ 0.01245594]
 [ 0.18250445]
 [ 0.14557755]
 [-0.12947509]
 [-0.32424578]
 [ 0.01147144]
 [-0.20546311]
 [ 0.38732064]
 [ 0.45803282]
 [ 0.22594012]
 [ 0.02803989]
 [ 0.43993357]
 [ 0.81624144]
 [ 0.5465872 ]
 [ 1.1168824 ]
 [ 0.4104824 ]
 [ 0.60788006]
 [ 0.68482363]
 [ 1.3565235 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [-0.06518985]
 [ 0.01245594]
 [ 0.18250445]
 [ 0.14557755]
 [-0.12947509]
 [-0.32424578]
 [ 0.01147144]
 [-0.20546311]
 [ 0.38732064]
 [ 0.45803282]
 [ 0.22594012]
 [ 0.02803989]
 [ 0.43993357]
 [ 0.81624144]
 [ 0.5465872 ]
 [ 1.1168824 ]
 [ 0.4104824 ]
 [ 0.60788006]
 [ 0.68482363]
 [ 1.3565235 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945145 ]
 [ 1.1945149 ]]

Did I miss something during training or testing process? Your any advices would be helpful, thanks!

test.py has some problems

For example,line 83 “ FLAGS.nStride ” nStride is not difined, line 161 "nd_patch_step" is not difined,
using glob.glob() instead of glob() may be better and so on.

Frame-level scores of your experiment on Ped2?

Hi Sabokrou,

Thank you for the source code of this good work!
I would like to explore more about your approach. Could you please provide the frame-level scores of Ped2 you obtained in your experiment (which you used to estimate the EER in Table 2)?

Thank you!

refinement loss

Dear Sir,
In the paper refinement loss is defined as euclidean loss but in the tensorflow code it is defined as crossentropy loss why is it different?
Also did you try L1 loss ?
Thanks

confusion about Discriminator

In my experiment, the output of the discriminator is about 0.49 after GAN convergence. How could you make the discriminator output probability larger than 0.5?

Something about the test.py file

Hello, I change the dataset for my own dataset, and the test.py file run well, but i dont kown how this file work, could you tell me what does this file do? How to use a trained model? Thanks in advance!

Discriminator Output Confusion

Is the output of the discriminator an anomaly score during the test of anomaly detection? Why is the output of the discriminator a very small value when I am testing, on the order of e-9 to e-20?

"nd_patch_step" variable is not define

Hello there,

In your "test.py" file the variable "nd_patch_step" is not defined. If I track down the variable it should be equal to "nStride", but with such setting the test does not seem to be working correct.

Am I missing some thing?

Thanks

Will it works for fine grained multi-class novelty detection?

Hi, khalooei:
Thanks for sharing your code, it's interesting.
I've a little confusion about the model, could you please explain it?
It seems the ALOCC can model generic single class(e.g. penguins) and others class(e.g. dogs, cats...) very well.
Will it works for these scenarios?
a. generic train-set multi-classes class and others class? i.e. R models a distribution for not only one explicit class but a complex distribution for all classes in train-set
b. for fine-grained dataset, one explicit class as base class and others as novelty classes? i.e. base class and novelty class may have more similar distributions than generic class dataset
c. fine-grained multi-classes as base class and others as novelty class?
Thanks.

Test program (test.py) not genering any output

Issue: No output sample is generated for “mnist” or “ucsd” (even when the pre-trained model provided in github is used)

We used following commands (separately) to run the test program on the dataset provided and using the pre-trained model provided as per the instructions. Neither "mnist" or "ucsd" output images are generated. The code fragment is copy-pasted below.

for test on UCSD and patch_size 45*45 and some specific dir like ['Test004'], etc. We prefer to open test.py file and edit every thing that you want

python test.py --dataset UCSD --dataset_address ./dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train --input_height 45 --output_height 45

for test on MNIST

python test.py --dataset mnist --dataset_address ./dataset/mnist/ --input_height 28 --output_height 28

Following is the copy-paste of the code in test.py file which is executed (after some bug fixing)

if FLAGS.dataset=='mnist':
mnist = input_data.read_data_sets(FLAGS.dataset_address)

        specific_idx_anomaly = np.where(mnist.train.labels != 6)[0]
        specific_idx = np.where(mnist.train.labels == 6)[0]
        ten_precent_anomaly = [specific_idx_anomaly[x] for x in
                               random.sample(range(0, len(specific_idx_anomaly)), len(specific_idx) // 40)]

        data = mnist.train.images[specific_idx].reshape(-1, 28, 28, 1)
        tmp_data = mnist.train.images[ten_precent_anomaly].reshape(-1, 28, 28, 1)
        data = np.append(data, tmp_data).reshape(-1, 28, 28, 1)

        lst_prob = tmp_ALOCC_model.f_test_frozen_model(data[0:FLAGS.batch_size])
        print('check is ok')
        exit()

else in UCDS (depends on infrustructure)

    for s_image_dirs in sorted(glob(os.path.join(FLAGS.dataset_address, 'Test[0-9][0-9][0-9]'))):
        tmp_lst_image_paths = []
        
        if os.path.basename(s_image_dirs) not in ['Test004']:
           print('Skip ',os.path.basename(s_image_dirs))
           continue
        for s_image_dir_files in sorted(glob(os.path.join(s_image_dirs + '/*'))):
            if os.path.basename(s_image_dir_files) not in ['068.tif']:
                print('Skip ', os.path.basename(s_image_dir_files))
                continue
            tmp_lst_image_paths.append(s_image_dir_files)

        #random
        #lst_image_paths = [tmp_lst_image_paths[x] for x in random.sample(range(0, len(tmp_lst_image_paths)), n_fetch_data)]
        lst_image_paths = tmp_lst_image_paths
        #images =read_lst_images(lst_image_paths,nd_patch_size,nd_patch_step,b_work_on_patch=False)
        
        nd_patch_step = 0              # we added this line (from the github to avoid an error)
       images = read_lst_images_w_noise2(lst_image_paths, nd_patch_size, nd_patch_step)

        lst_prob = process_frame(os.path.basename(s_image_dirs),images,tmp_ALOCC_model)
        print('pseudocode test is finished')

generator outputs minus values

return tf.nn.tanh(h4,name='g_output')

Hi, the output values of generator G is the one of tanh and thus it takes [-1,1] values.
But the true input takes [0,1] values (at least, MNIST case).
Thus, it will be too easy for discriminator D to classify True or False, by just checking if minus values being contained. The output of G should take sigmoid instead of tanh?

libpng error: Write Error

I ran training, but hit this error... Anyone getting this?

python train.py --dataset UCSD --dataset_address ./dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train --input_height 45 --output_height 45
{'attention_label': 1,
 'batch_size': 128,
 'beta1': 0.5,
 'checkpoint_dir': 'checkpoint',
 'dataset': 'UCSD',
 'dataset_address': './dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train',
 'epoch': 40,
 'input_fname_pattern': '*',
 'input_height': 45,
 'input_width': None,
 'learning_rate': 0.002,
 'log_dir': 'log',
 'output_height': 45,
 'output_width': None,
 'r_alpha': 0.2,
 'sample_dir': 'samples',
 'train': True,
 'train_size': inf}
2018-12-22 15:03:46.625140: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-12-22 15:03:46.948538: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2018-12-22 15:03:46.965900: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
Program is on Train Mode
libpng error: Write Error

Something about the evaluation

I can't reproduce the results in your paper,that is,D(G(z)), in your paper,all of them are between 0 and 1,I tried to print the variable 'D_',it turned out that all of them are negative,and so ,the results of variable 'D_logits_' are all too close to zero,which means the algorithm didn't go very well because all the test patches are abnormal,I was stuck for a long time,and I hope you can help me.

Problems with the MNIST experiment

Dear Sir:
I am very interested in your paper. But some problems occurred when I repeated MNIST experiment. I wrote the test code and adopted the same LOSS function as the training code. Visualize the LOSS value of G and D, but the normal samples and abnormal samples may not be distinguished.
For example, In the training,the number 1 is treated as a normal sample; in the test, the number 0,1,2 and 3 are visualized; the number 1 is red, the number 0 is blue, the number 2 is green, and the number 3 is yellow. The parameters are all default values. The results look good.
image
But if the number 2 is treated as a normal sample; in the test, the number 0,1,2 and 3 are visualized; the number 2 is red, the number 0 is blue, the number 1 is green, and the number 3 is yellow. The parameters are all default values. The results turned out badly.
image
I tried adding noise to the test sample and adjusted r_alpha, but none of the results improved significantly.
This question has been bothering me for a few days and How should the LOSS of the test sample be selected,Could you give me some advice. Thank you!
Best wishes!

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.