Effacer les filtres
Effacer les filtres

How can i vectorize the binning process for HOG feature computation and run on GPU ?

3 vues (au cours des 30 derniers jours)
Varun Pai
Varun Pai le 10 Août 2015
Modifié(e) : Varun Pai le 10 Août 2015
Dear Friends,
I have been trying to implement the HOG feature calculation on matlab GPU (PCT toolbox). The code which i am using for it is provided in the link here : (<http://in.mathworks.com/matlabcentral/fileexchange/46408-histogram-of-oriented-gradients--hog--code-using-matlab)>.
In the above code, I was able to run on GPU up to the gradient computation which gave me a speed gain of 8x. But my GPU performance degraded drastically when i tried to implement the below part:
% Iterations for Blocks
for i = 0: rows/8 - 2 for j= 0: cols/8 -2
mag_patch = magnitude(8*i+1 : 8*i+16 , 8*j+1 : 8*j+16);
%mag_patch = imfilter(mag_patch,gauss);
ang_patch = angle(8*i+1 : 8*i+16 , 8*j+1 : 8*j+16);
block_feature=[];
%Iterations for cells in a block
for x= 0:1
for y= 0:1
angleA =ang_patch(8*x+1:8*x+8, 8*y+1:8*y+8);
magA =mag_patch(8*x+1:8*x+8, 8*y+1:8*y+8);
histr =zeros(1,9);
%Iterations for pixels in one cell
for p=1:8
for q=1:8
alpha= angleA(p,q);
% Binning Process (Bi-Linear Interpolation)
if alpha>10 && alpha<=30
histr(1)=histr(1)+ magA(p,q)*(30-alpha)/20;
histr(2)=histr(2)+ magA(p,q)*(alpha-10)/20;
elseif alpha>30 && alpha<=50
histr(2)=histr(2)+ magA(p,q)*(50-alpha)/20;
histr(3)=histr(3)+ magA(p,q)*(alpha-30)/20;
elseif alpha>50 && alpha<=70
histr(3)=histr(3)+ magA(p,q)*(70-alpha)/20;
histr(4)=histr(4)+ magA(p,q)*(alpha-50)/20;
elseif alpha>70 && alpha<=90
histr(4)=histr(4)+ magA(p,q)*(90-alpha)/20;
histr(5)=histr(5)+ magA(p,q)*(alpha-70)/20;
elseif alpha>90 && alpha<=110
histr(5)=histr(5)+ magA(p,q)*(110-alpha)/20;
histr(6)=histr(6)+ magA(p,q)*(alpha-90)/20;
elseif alpha>110 && alpha<=130
histr(6)=histr(6)+ magA(p,q)*(130-alpha)/20;
histr(7)=histr(7)+ magA(p,q)*(alpha-110)/20;
elseif alpha>130 && alpha<=150
histr(7)=histr(7)+ magA(p,q)*(150-alpha)/20;
histr(8)=histr(8)+ magA(p,q)*(alpha-130)/20;
elseif alpha>150 && alpha<=170
histr(8)=histr(8)+ magA(p,q)*(170-alpha)/20;
histr(9)=histr(9)+ magA(p,q)*(alpha-150)/20;
elseif alpha>=0 && alpha<=10
histr(1)=histr(1)+ magA(p,q)*(alpha+10)/20;
histr(9)=histr(9)+ magA(p,q)*(10-alpha)/20;
elseif alpha>170 && alpha<=180
histr(9)=histr(9)+ magA(p,q)*(190-alpha)/20;
histr(1)=histr(1)+ magA(p,q)*(alpha-170)/20;
end
toc;
end
end
block_feature=[block_feature histr]; % Concatenation of Four histograms to form one block feature
end
end
% Normalize the values in the block using L1-Norm
block_feature=block_feature/sqrt(norm(block_feature)^2+.01);
feature=[feature block_feature]; %Features concatenation
end
end
What all changes should i make to run this section. Please do help me in vectorizing this section and run the code on GPU. Any answer is welcome. Thank You.

Réponses (0)

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by