Coder Social home page Coder Social logo

abhijitbendale / osdn Goto Github PK

View Code? Open in Web Editor NEW
234.0 13.0 56.0 195 KB

Code and data for the research paper "Towards Open Set Deep Networks" A Bendale, T Boult, CVPR 2016

License: Other

Python 42.34% Makefile 0.10% C++ 16.13% Shell 0.79% C 40.65%
extract-features openmax deep-learning open-set softmax-regression softmax

osdn's Introduction

This software package contains code used for conducting experiments in following work:

A. Bendale, T. Boult “Towards Open Set Deep Networks” IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016 pdf

Authors: Abhijit Bendale ([email protected]) Terrance Boult ([email protected]) Vision and Security Technology Lab University of Colorado at Colorado Springs

Citing the paper

@InProceedings{bendale-boult-cvpr2016,
title={Towards Open Set Deep Networks},
author={Bendale, Abhijit and Boult, Terrance},
booktitle={Computer Vision and Pattern Recognition (CVPR), 2016 IEEE Conference on},
year={2016},
organization={IEEE}
}

The code is provided "as is", without any guarantees. Please refer COPYRIGHT.txt and libMR/COPYRIGHT_Libmr.txt for more details about license and usage restrictions.

The package is divided into two parts: LibMR and OpenMax.

  1. LibMR contains code for Extreme Value Theory based Weibull fitting (and other code used in the work for Meta-Recognition). Weibull fitting performed by LibMR is slightly different than that done by other popular packages such as MATLAB's wblfit() function. We have added a short tutorial to illustrate these differences.

  2. OpenMax contains code used in the CVPR 2016 paper on "Towards Open Set Deep Networks". The software packages for OpenMax code calls LibMR functions for performing Weibull fitting. In this code, we are providing code to compute OpenMax probabilities from pre-computed Mean Activation Vectors and Softmax probabilities. Mean Activation Vectors and Softmax probabilities are obtained by passing images through Caffe's architecture.

Usage:

1) Compiling LibMR

Compile LibMR and python interface to LibMR using following commands. For pythong interfaces to work, you would require Cython to be pre-installed on your machine

cd libMR/
chmod +x compile.sh
./compile.sh

2) Precomputed Features

2.a) Extract features using a pre-trained AlexNet network. The extracted features

are saved in a mat file. We save fc7, fc8, prob and scores from Caffe framework. Example of saved files can be found in data/train_features/

E.g. loading the file data/train_features/n01440764/n01440764_9981.JPEG.mat in ipython will lead to

>>> from scipy.io import loadmat
>>> import scipy as sp
>>> features = loadmat('data/train_features/n01440764/n01440764_9981.JPEG.mat')
>>> print features.keys()
['fc7', 'fc8', '__header__', '__globals__', 'scores', 'IMG_NAME', '__version__', 'prob']
>>> print features['fc8'].shape
(10, 1000)
>>> print sp.mean(features['prob'], axis=0)[0]
0.999071
>>> print features['scores'][0][0]
0.9990708

where fc7, fc8, prob, scores are outputs of respective layers provided by Caffe Library. Further, fc8 layer contains 10 channels for 1000 classes of ImageNet. These channels are referred to as crops in Caffe library classifier.py, check the function predict() ). The average of prob layer (i.e. SoftMax layer) is the final probability value reported by AlexNet as architected in Caffe Library. In the paper (and code), each of these 10 crops is referred to as channel. Hence, average of features['prob'], is essentially features['scores'].

You will have to install Caffe library on your machine with python interface activated. If you do have it configured, then features for entire ImageNet data can be extracted using the script, python preprocessing/imageNet_Features.py

2.b) Compute Mean Activation Vector

Mean Activation Vector is defined as the Mean Vector in the pen-ultimate layer. In our paper, we considered fc8 as the pen-ultimate layer. Hence, MAV is the mean of features in fc8. The Mean is computed for each channel. The script to compute mean can be found in

python preprocessing/MAV_Compute.py

Since this process is very time consuming, we are proving pre-computed mean activation vectors on ILSVRC 2012 dataset with this code repository. You can download the mean activation vectors using following command

wget http://vast.uccs.edu/OSDN/data.tar
tar -xvf data.tar

The structure of Mean Files is very simple. For e.g.

>>> from scipy.io import loadmat
>>> mav = loadmat('data/mean_files/n01440764.mat')
>>> print mav['n01440764'].shape
(10, 1000)

The above is the MAV for object category n01440764. MAV is computed in similar manner for each of the 1000 ImageNet Categories. Note, for computing MAV, only those images are considered that classified correctly by the network.

2.c) Compute Distances from Mean Activation Vector

Once the mean activation vector for each category is computed, the next step is to compute category specific distance distribution.

>>> from scipy.io import loadmat
>>> distance_distribution = loadmat('data/mean_distance_files/n01440764_distances.mat')
>>> print distance_distribution.keys()
['__header__', 'eucos', '__globals__', 'euclidean', 'cosine', '__version__']
>>> print distance_distribution['euclidean'].shape
(10, 1224)

Distances (e.g. euclidean or cosine or eucos) are computed from MAV to correctly classified training examples. In the above example, n01440764 category has 1300 training images. During training process, only 1224 images were classified correctly by the network. Thus, we build distance distribution using these correctly classified images. These distances are computed for each channel (for defn of channel see point 2.a). This process forms a distance distribution from the MAV. This distance distribution is used for Weibull fitting. In our experiments, we consider tail size for Weibull fitting as 20. This means, that 20 distances farthest away from MAV were used to estimate Weibull parameters. Again, since the distance computation process is very time comsuming, we are providing pre-computed distances for each class, so that you have access to the distance distribution from MAV for each category. It can be downloaded from

wget http://vast.uccs.edu/OSDN/data.tar

There are 1000 distance distributions, one for each category. The script used for computing distance distributions can be found in

python preprocessing/compute_distances.py
2.d) Details of Weibull tail fitting on distance distributions can be found in the

function weibull_tailfitting() in file evt_fitting.py . However, compute_openmax.py performs Weibull tailfitting for each category while computing probability for OpenMax

3) Computing Probability values using OpenMax algorithm

OpenMax probability for given image can be computed using following command.

python compute_openmax.py --image_arrname data/train_features/n01440764/n01440764_14280.JPEG.mat

The script accepts image feature files (features extracted from caffe as mentioned above). It computes openmax probability for the said image using default weibull tail sizes and other parameters. For more details, check the paper or get in touch with authors.

4) Fooling Images

Fooling images are generously provided by Anh Nguyen and Prof. Jeff Clune from University of Wyoming. We will upload the fooling images and features extracted for fooling images in few days. When you use fooling images, please be sure to cite the following paper

@InProceedings{nguyen2015deep,
title={Deep Neural Networks are Easily Fooled: High Confidence Predictions for Unrecognizable Images},
author={Nguyen, Anh and Yosinski, Jason and Clune, Jeff},
booktitle={Computer Vision and Pattern Recognition (CVPR), 2015 IEEE Conference on},
year={2015},
organization={IEEE}
}

Please download the images from

wget http://vast.uccs.edu/OSDN/fooling_images.tar

The images are made available under Creative Commons liecense. In case any questions about fooling images, please get in touch with Prof. Jeff Clune or Anh Nguyen from University of Wyoming. You can also find their fantanstic work on fooling images on their webpage

osdn's People

Contributors

abhijitbendale 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

osdn's Issues

Re-calibrate scores

Hello,

Please, the "channel_scores" is the feature vector of the "fc8" layer for a specific channel, then why did you loop over the "categoryid" to compute modified_fc8_score = channel_scores[categoryid] * ( 1 - wscore*ranked_alpha[categoryid] ) ?
Yet, the Len(channel_scores) is not equal to NCHANNELS.

Thank you.

Unable to reproduce the result

While using the imageNetFeatures script, I ran into following errors:-

  1. the mean_file available in data folder is throwing the error during classifier stage
    [ValueError: number of channels incompatible with mean]
    We rectified it using the mean file provided through caffe for imagenet (Not sure if it's correct way to handle it)
  2. We also removed axis from squeeze function while adding fc8 and fc7 features into mat.

After making the script work we tried running compute_openmax.py with fooling_images data provided on the main page. Surprisingly probabilty for fooling image was around 90% .
Please suggest some solution to reproduce the result specified in the thesis paper.

Error statements-

  1. Error while using axis in squeeze:

File "imageNet_Features.py", line 302, in <module> main(sys.argv) File "imageNet_Features.py", line 299, in main extractFeatures(args) File "imageNet_Features.py", line 126, in extractFeatures compute_features(imgname,args) File "imageNet_Features.py", line 176, in compute_features feature_dict['fc7'] = sp.asarray(classifier.blobs['fc7'].data.squeeze(axis=(2,3))) ValueError: 'axis' entry 2 is out of bounds [-2, 2)

  1. Error while using given mean file:

Traceback (most recent call last): File "imageNet_Features.py", line 302, in <module> main(sys.argv) File "imageNet_Features.py", line 299, in main extractFeatures(args) File "imageNet_Features.py", line 126, in extractFeatures compute_features(imgname,args) File "imageNet_Features.py", line 151, in compute_features input_scale=args.input_scale, channel_swap=channel_swap) File "/home/ubuntu/deep-learning/caffe/python/caffe/classifier.py", line 37, in __init__ self.transformer.set_mean(in_, mean) File "/home/ubuntu/deep-learning/caffe/python/caffe/io.py", line 250, in set_mean raise ValueError('Mean channels incompatible with input.') ValueError: Mean channels incompatible with input.

I can't run ImagenetFeature.py

I tried to run ImagenetFeature.py. The imagenetFeature.py can't excute because caffe does't have gpu and mean_file parameter. The picture shows init method in caffe library.
image

In the imagenetFearute.py, that send the gpu and mean_file parameter to caffe library to create the object.

Question: How can i fixed it. Can I remove the gpu and mean_file parameter in ImagenetFeature.py.

unknown probs for negative logits

wscore = category_weibull[2][channel].w_score(channel_distance)
modified_fc8_score = channel_scores[categoryid] * ( 1 - wscore*ranked_alpha[categoryid] )
openmax_fc8_channel += [modified_fc8_score]
openmax_fc8_unknown += [channel_scores[categoryid] - modified_fc8_score ]

Can you explain how this works with negative fc8 scores?
As I understand, if v_i(x) is negative then even with w_i=1, v_0(x)=0, so v_i < v_0.
In fact a fc8 layer may contain negative logits, and it leads to a high unknown-unknown probability in my dataset.

features = loadmat('data/train_features/n01440764/n01440764_9981.JPEG.mat')
ch = 0
features['fc8'][ch]>0

array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
       False,  True,  True,  True,  True,  True,  True,  True,  True,
       False,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True, False,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True, False, False,  True,
       False, False, False, False,  True, False, False,  True,  True,
       False,  True,  True,  True,  True,  True,  True,  True,  True,
...

fit_high() function gives high scores for higher distances while low scores for low distances

In the paper "Towards Open Set Deep Networks" it is mentioned, that we have to do per class Weibull fit using FitHigh function. However, in the documentation html files it is written that FItHigh should be used if the data is such that larger is better, which I suppose is referred to large distances from the mean activation vector.

Using FitHigh function, gives larger scores for larger distances, but according to the paper, should it be the opposite? What I meant to say is that, should, we get low scores for larger distances from the mean activation vector?

And if I am not wrong, shouldn't FitLow function be used in place of FitHigh?

This is what I obtained

import libmr as mr
meta = mr.MR()
meta.fit_high(sorted_dist[-100:],100)
meta.w_score(0.0)
0.0
meta.w_score(10.0)
0.21476801948365665
meta.w_score(20.0)
0.9963975817523232
meta.w_score(30.0)
0.9999996470632248
meta.w_score(40.0)
0.9999999999978881
meta.fit_low(sorted_dist[-100:],100)
meta.w_score(0.0)
1.0
meta.w_score(10.0)
0.8115743914686449
meta.w_score(20.0)
1.665564614727888e-05
meta.w_score(30.0)
0.0
meta.w_score(40.0)
0.0

I am also attaching the plot of the sorted distances of all the 1011 correctly classified training examples of only one class, from the mean activation vector of that class.
figure_1

Not able to compile libMR

Hello,

I have some problems with the code.

When I use the command:

/compile.sh

, I got:

gcc: error: unrecognized command line option ‘-fstack-protector-strong’
gcc: error: unrecognized command line option ‘-fstack-protector-strong’
error: command 'gcc' failed with exit status 1
cp: cannot stat ‘libmr.so’: No such file or directory

Do you now what kind gcc is needed for this?

extracted features from fooling images

In readme, it is said 'We will upload the fooling images and features extracted for fooling images in few days'. I don't think the extracted features are uploaded. I am wondering if there is a plan to do so.

If not, I think we should modify imageNet_Features.py and generate the extracted features from there?

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.