使用VLFEAT实现Bags of Words对象识别

时间:2012-06-18 22:25:56

标签: computer-vision svm sift

我正在尝试在matlab中实现BOW对象识别代码。这个过程有点复杂,我在找到有关程序的正确文档方面遇到了很多麻烦。那么有人可以仔细检查下面我的计划是否有意义? 我在这里广泛使用VLSIFT library

Training:
1. Extract SIFT image descriptor with VLSIFT
2. Quantize the descriptors with k-means(vl_hikmeans)
3. Take quantized descriptors and create histogram(VL_HIKMEANSHIST)
4. Create SVM from histograms(VL_PEGASOS?)

我理解第1-3步,但我不太确定SVM的功能是否正确。 VL_PEGASOS采用以下内容:

W = VL_PEGASOS(X, Y, LAMBDA)

我如何将此功能与我创建的直方图一起使用?

最后在识别阶段,如何将图像与SVM定义的类匹配?

1 个答案:

答案 0 :(得分:2)

您是否看过他们的Caltech 101 example code,即全面实施BoW方法。

以下是他们用pegasos分类并评估结果的部分:

% --------------------------------------------------------------------
%                                                            Train SVM
% --------------------------------------------------------------------

lambda = 1 / (conf.svm.C *  length(selTrain)) ;
w = [] ;
for ci = 1:length(classes)
  perm = randperm(length(selTrain)) ;
  fprintf('Training model for class %s\n', classes{ci}) ;
  y = 2 * (imageClass(selTrain) == ci) - 1 ;
  data = vl_maketrainingset(psix(:,selTrain(perm)), int8(y(perm))) ;
  [w(:,ci) b(ci)] = vl_svmpegasos(data, lambda, ...
                                  'MaxIterations', 50/lambda, ...
                                  'BiasMultiplier', conf.svm.biasMultiplier) ;

  model.b = conf.svm.biasMultiplier * b ;
  model.w = w ;

% --------------------------------------------------------------------
%                                                Test SVM and evaluate
% --------------------------------------------------------------------

% Estimate the class of the test images
scores = model.w' * psix + model.b' * ones(1,size(psix,2)) ;
[drop, imageEstClass] = max(scores, [], 1) ;

% Compute the confusion matrix
idx = sub2ind([length(classes), length(classes)], ...
              imageClass(selTest), imageEstClass(selTest)) ;
confus = zeros(length(classes)) ;
confus = vl_binsum(confus, ones(size(idx)), idx) ;