www.gusucode.com > Adaboost算法训练人脸图像和非人脸图像,通过迭代得到由多个弱分类器组合而成的强分类器,实现图片里的人脸检测。 > Adaboost算法训练人脸图像和非人脸图像,通过迭代得到由多个弱分类器组合而成的强分类器,实现图片里的人脸检测。/myfacedet02/ADABOOST_te.m
function [L,hits] = ADABOOST_te(adaboost_model,te_func_handle,test_set,... true_labels) % % ADABOOST TESTING % % [L,hits] = ADABOOST_te(adaboost_model,te_func_handle,test_set, % true_labels) % % 'te_func_handle' is a handle to the testing function of a % learning (weak) algorithm whose prototype is shown below. % % [L,hits,error_rate] = test_func(model,test_set,sample_weights,true_labels) % model: the output of train_func % test_set: a KxD dimensional matrix, each of whose row is a % testing sample in a D dimensional feature space. % sample_weights: a Dx1 dimensional vector, the i-th entry % of which denotes the weight of the i-th sample. % true_labels: a Dx1 dimensional vector, the i-th entry of which % is the label of the i-th sample. % L: a Dx1-array with the predicted labels of the samples. % hits: number of hits, calculated with the comparison of L and % true_labels. % error_rate: number of misses divided by the number of samples. % % It is the corresponding testing % module of the function that is specified in the training phase. % 'test_set' is a NxD matrix where N is the number of samples % in the test set and D is the dimension of the feature space. % 'true_labels' is a Nx1 matrix specifying the class label of % each corresponding sample's features (each row) in 'test_set'. % 'adaboost_model' is the model that is generated by the function % 'ADABOOST_tr'. % % 'L' is the likelihoods that are assigned by the 'ADABOOST_te'. % 'hits' is the number of correctly predicted labels. % % Specific Properties That Must Be Satisfied by The Function pointed % by 'func_handle' % ------------------------------------------------------------------ % % Notice: Labels must be positive integer values from 1 upto the number classes. % % Bug Reporting: Please contact the author for bug reporting and comments. % % Cuneyt Mertayak % email: cuneyt.mertayak@gmail.com % version: 1.0 % date: 21/05/2007 % hypothesis_n = length(adaboost_model.weights); sample_n = size(test_set,1); class_n = length(unique(true_labels)); temp_L = zeros(sample_n,class_n,hypothesis_n); % likelihoods for each weak classifier % for each weak classifier, likelihoods of test samples are collected for i=1:hypothesis_n [temp_L(:,:,i),hits,error_rate] = te_func_handle(adaboost_model.parameters{i},... test_set,ones(sample_n,1),true_labels); temp_L(:,:,i) = temp_L(:,:,i)*adaboost_model.weights(i); end L = sum(temp_L,3); hits = sum(likelihood2class(L)==true_labels);