资源简介
这里不光包含AdaBoost算法本身的实现,而且还有利用特征模板从人脸提取特征值的代码,可以让大家轻松掌握AdaBoost用于人脸识别的全过程。其实设计模板(Haar特征)并提取特征值是整个过程中最累的环节。
代码片段和文件信息
function [test_targets E] = ada_boost(train_patterns train_targets test_patterns params)
% Classify using the AdaBoost algorithm
% Inputs:
% train_patterns - Train patterns
% train_targets - Train targets
% test_patterns - Test patterns
% Params - [NumberOfIterations Weak Learner Type Learner‘s parameters]
%
% Outputs
% test_targets - Predicted targets
% E - Errors through the iterations
%
% NOTE: Suitable for only two classes
%
[k_max weak_learner alg_param] = process_params(params);
[NiM] = size(train_patterns);
W = ones(1M)/M;
IterDisp = 10;
full_patterns = [train_patterns test_patterns];
test_targets = zeros(1 size(test_patterns2));
%Do the AdaBoosting
for k = 1:k_max
%Train weak learner Ck using the data sampled according to W:
%...so sample the data according to W
randnum = rand(1M);
cW = cumsum(W);
indices = zeros(1M);
for i = 1:M
%Find which bin the random number falls into
loc = max(find(randnum(i) > cW))+1;
if isempty(loc)
indices(i) = 1;
else
indices(i) = loc;
end
end
%...and now train the classifier
Ck = feval(weak_learner train_patterns(: indices) train_targets(indices) full_patterns alg_param);
%Ek <- Training error of Ck
E(k) = sum(W.*(Ck(1:M) ~= train_targets));
if (E(k) == 0)
break
end
%alpha_k <- 1/2*ln(1-Ek)/Ek)
alpha_k = 0.5*log((1-E(k))/E(k));
%W_k+1 = W_k/Z*exp(+/-alpha)
W = W.*exp(alpha_k*(xor(Ck(1:M)train_targets)*2-1));
W = W./sum(W);
%Update the test targets
test_targets = test_targets + alpha_k*(2*Ck(M+1:end)-1);
if (k/IterDisp == floor(k/IterDisp))
disp([‘Completed ‘ num2str(k) ‘ boosting iterations‘])
end
end
test_targets = test_targets > 0;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 55045 2009-02-01 20:32 AdaBoost完整实现\AdaBoost.rar
文件 1892 2003-06-26 20:48 AdaBoost完整实现\Ada_Boost.m
文件 38627 2009-02-25 17:22 AdaBoost完整实现\MyFistProgamme2.rar
目录 0 2009-02-27 18:58 AdaBoost完整实现
----------- --------- ---------- ----- ----
95564 4
- 上一篇:8255应用程序及电路图说明
- 下一篇:广义高斯分布参数估计(GGD)
评论
共有 条评论