Professional Documents
Culture Documents
Fisher Kernel Code Report
Fisher Kernel Code Report
.
apt-get install python2.7 cmake build-essential libgomp1
libeigen3-dev
python-scipy python-numpy python-skimage python-sklearn pythonjoblib python-nose
virtualenv
:
apt-get install python-virtualenv
:
wget http://www.famaf.unc.edu.ar/~jsanchez/efv/vrl-0.1.tar.gz
:
tar -xf vrl-0.1.tar.gz
virtualenv ... numpy scipy
:
cd vrl-0.1
virtualenv venv --system-site-packages
source venv/bin/activate
: vlfeat
mkdir build; cd build
cmake ../
make
make install
cd ../
: KTH
wget http://www.nada.kth.se/cvap/databases/kth-tips/kth-tips2a_col_200x200.tar
:
tar -xf kth-tips2-a_col_200x200.tar
:
/home/dmuser/anaconda/bin/python
bin/classification_demo_kth_tips_2a.py
5 51
. .
precision recall f1 :
support
f1-score
recall
precision
108
0.99
0.99
0.99
aluminium_foil
108
0.27
0.19
0.50
brown_bread
108
0.97
0.96
0.97
corduroy
108
0.88
0.99
0.80
cork
108
0.67
0.54
0.88
cotton
108
0.47
0.43
0.53
cracker
108
0.96
0.95
0.97
lettuce_leaf
108
0.83
0.95
0.73
linen
108
0.65
0.92
0.51
white_bread
108
0.98
1.00
0.96
wood
108
0.89
0.82
0.98
wool
1188
0.78
0.79
0.80
avg / total
--accuracy: 79.46
:
# -*- coding: utf-8 -*-
import os
import numpy as np
import vrl
import inspect
# dataset
DATASET_PATH = abspath('KTH-TIPS2-a')
# output cache
OUTPUT_PATH = abspath('.')
def whoami():
return inspect.stack()[1][3]
def kth_tips_2a_lbp_bmm():
vrl.utils.set_loglevel(vrl.utils.logging.INFO)
logger = vrl.utils.get_logger(whoami())
feat = vrl.cv.LBP()
feat.input_path = dataset.impath
feat.output_base_path = OUTPUT_PATH
# mixture model
bmm = vrl.ml.BernoulliMixture(ncomp=128, nvar=8)
bmm.input_path = feat.output_path
bmm.output_base_path = feat.output_path
# setup classifier
ovr = OneVsRestClassifier(LinearSVC(loss='l1', penalty='l2'))
clf = vrl.base.SKLEstimator(estimator=ovr,
to_show=('estimator',
'estimator__C',
'estimator__loss',
'estimator__penalty'))
clf.input_path = efv.output_path
clf.output_base_path = join(efv.output_path, split_id)
# fit BMM
bmm.fit(rnd_samples_file)
efv.transform(feat.transform(dataset.imlist))
x_train = dataset.get_images('train')
y_train = dataset.get_labels('train')
x_test = dataset.get_images('test')
y_test = dataset.get_labels('test')
# eval
scr = np.empty((len(x_test), dataset.nclasses))
for i, fname in enumerate(x_test):
x_test_ = vrl.io.load(efv.pass_through(fname))
scr[i, :] = clf.estimator.decision_function(x_test_)
dataset.eval(scr, y_test)
def kth_tips_2a_dsift_pca_gmm():
vrl.utils.set_loglevel(vrl.utils.logging.INFO)
logger = vrl.utils.get_logger(whoami())
# PCA projections
pca = vrl.ml.PCA(dim=64)
pca.input_path = feat.output_path
pca.output_base_path = feat.output_path
# mixture model
gmm = vrl.ml.GaussianMixture(ncomp=16, nvar=pca.dim)
gmm.input_path = pca.output_path
gmm.output_base_path = pca.output_path
# setup classifier
ovr = OneVsRestClassifier(LinearSVC(loss='l1', penalty='l2'))
clf = vrl.base.SKLEstimator(estimator=ovr,
to_show=('estimator',
'estimator__C',
'estimator__loss',
'estimator__penalty'))
clf.input_path = efv.output_path
clf.output_base_path = join(efv.output_path, split_id)
# fit GMM
gmm.fit(rnd_samples_file)
efv.transform(pca.transform(feat.transform(dataset.imlist)))
x_train = dataset.get_images('train')
y_train = dataset.get_labels('train')
x_test = dataset.get_images('test')
y_test = dataset.get_labels('test')
# eval
scr = np.empty((len(x_test), dataset.nclasses))
for i, fname in enumerate(x_test):
x_test_ = vrl.io.load(efv.pass_through(fname))
scr[i, :] = clf.estimator.decision_function(x_test_)
dataset.eval(scr, y_test)
if __name__ == "__main__":
#kth_tips_2a_lbp_bmm()
kth_tips_2a_dsift_pca_gmm()