implementing Bags of Words object recognition using VLFEAT

拈花ヽ惹草 提交于 2019-12-04 14:05:35

Did you look at their Caltech 101 example code, that is full implementation of an BoW approach.

Here is the part where they classify with pegasos and evaluate the results:

% --------------------------------------------------------------------
%                                                            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) ;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!