Software Documentation, Greg 2009

From Vision Wiki
Jump to navigation Jump to search

Back to Greg's Main Wiki Page

The Short Answer

cd ~/256/images
makesift('~/256/sift/80x60',getcategories,0,1,'xy',[80 60]);
makehist('~/256/spm/80x60/200',getcategories,15,15,200);
makesvm(15,15,200);


SIFT

Images → Features

cd ~/256/images
makesift('~/256/sift/80x60',getcategories,0,1,'xy',[80 60]);

For Caltech256 this will take about 2 days, so you might want to spread it across multiple CPUs. This is what the 3rd and 4th arguments (i and n) are for. The ith file will be processed only if mod(i,n)==0 This keeps multiple processes from working on the same files, e.g.

vision317>> makesift('~/256/sift/80x60',getcategories,0,4,'xy',[80 60]);
vision318>> makesift('~/256/sift/80x60',getcategories,1,4,'xy',[80 60]);
vision319>> makesift('~/256/sift/80x60',getcategories,2,4,'xy',[80 60]);
vision320>> makesift('~/256/sift/80x60',getcategories,3,4,'xy',[80 60]);

The resulting files in ~/256/sift/80x60 mirror the file structure of ~/256/images, with each image replaced by a corresponding .mat file containing SIFT features for that image.


SPM

Features → Histograms → Match Kernels

cd ~/256/sift/80x60;
rand_seed(1);
makehist('~/256/spm/80x60/200',getcategories,15,15,200);

This will use 15 train and 15 test files per category, and a feature vocabulary of 200 words.

You only need to set rand_seed if you want the same randomly chosen sets of training and test files each time (reproducibly).

Corresponding 4x4x200 histograms are stored in

~/256/spm/80x60/hist15_15_200.mat

The Spatial Pyramid Match kernels are also generated and stored in

~/256/spm/80x60/match15_15_200.mat

This last step (turning a hist file into a match file) can be done manually like so :

cd ~/256/spm/80x60; makematch(15,15,200);

but makehist does this for you automatically after the histogram file is generated. So you don't have to worry about it.

Match Kernels → SVM Results

makesvm(15,15,200);

A good way to look at the results over may directories is to use scansvm. Possibly in conjunection with multirun, e.g.

>> cd ~/101/spm/80x60
>> multirun('x=%d; cd(num2str(x)); makesvm(15,15,x); cd ..',[50 100 200 400],1);   
>> multirun('cd %d; scansvm; cd ..',[50 100 200]);

ntrain ntest nword      performance
   15    15    50          47.9 %
ntrain ntest nword      performance
   15    15   100          52.3 %
ntrain ntest nword      performance
   15    15   200          53.9 %
ntrain ntest nword      performance
   15    15   400          57.1 %


NBNN

Features → NN's

You definitely gain some speed advantages running this on a multiprocessor machine. The nn search process is embarrassingly parallel, so if you run matlabpool first you will gain an n-fold increase, where n is the number of cpus in your worker pool. On vision401 the below code takes about 4 hours to run using the matlabpool, and 12 hours otherwise.

>> cd ~/101/sift/80x60
>> rand_seed(1);
>> makenn('~/101/nn/80x60',getcategories,15,15);

NN's → Class Distances

Compute distances between each test image's SIFT features and its nearest neighbor in each.

>> makenbnn('~/101/nbnn/80x60',15,15,25);
>> cd ~/101/nbnn/80x60
>> runnbnn(15,15,25);

When exploring the xyscale parameter or some other set of parameters, multirun can be useful:

>> cd ~/101/sift/80x60; 
>> xyscales= [1 2 3 5];
>> multirun(' makenn(''~/101/nn/80x60'',getcategories,15,15,''teston'',''test'',''xyscale'',%f)',xyscales);
>> multirun(' makenn(''~/101/nn/80x60'',getcategories,15,15,''teston'',''train'',''xyscale'',%f)',xyscales);
>> cd ~/101/nbnn/80x60
>> multirun('runnbnn(15,15,%d);',[10 20 25 30 50]);