Ask Your Question
0

reduce HOG features with PCA

asked 2018-04-21 08:31:30 -0600

Shivanshu gravatar image

updated 2018-04-22 01:57:14 -0600

berak gravatar image

I wrote a program,in which I am targeting for classification of object via neural net.I calculated HOG vector by my own(I didn't used prebuild HOG descriptor).I reduced those feature using PCA...where I obtained three Eigen values and its corresponding Eigen vector.Now how shall I feed those Eigen values to neural net??I mean each Eigen vector is of nine dimension and there are total three...do we need to catenate all together to make a (9x3=27 dimensional vector in a single row) or do something else like resultanting all together??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-22 01:40:38 -0600

berak gravatar image

updated 2018-04-22 01:55:34 -0600

if you wanted to reduce the size(length) of your hog features, you have to do a projection with the eigenvectors from the PCA, not use the eigenvectors themselves.

// assuming, you have 1000 hog vectors, each with a length of 200:
Mat hogvecs(1000, 200, CV_32F);

// do the PCA, and retain only 50 eigenvecs:
PCA pca(hogvecs, Mat(), PCA::DATA_AS_ROW,  50);

// equivalent to: (hogvecs-mean) * eigenvecs.t()
//
Mat reduced = pca.project(hogvecs);

cout << reduced.size() << endl;
// [50x1000]

so, it still has 1000 features, and we shortened the length of the features from 200 to 50.

edit flag offensive delete link more

Comments

@berak do you remember the problem on HOG feature we were troubleshooting ..i extended the same program over here...actually i am using haar cascade to detect face and then i obtain a square ROI which i fed to a function to estimate HOG feature ..catenated feature vector sum up producing 11,025 size HOG vector which i fed to PCA like this..

PCA pca(HOGfeature,Mat(),PCA::DATA_AS_ROW,3);

where each row of matrix points 9-bin HOG of each (8x8)patch in image and calculated its eigen vectors...which i fed to neural net to train ...is it right?? am i going right??actually i want to approach recognition system with neural net with HOG feature..

Shivanshu gravatar imageShivanshu ( 2018-04-22 05:31:53 -0600 )edit

@berak also thank you again for supporting!!

Shivanshu gravatar imageShivanshu ( 2018-04-22 05:36:50 -0600 )edit
1

so, each of your hog features is 11025 floats ?

maybe it needs clarification, that you have to make a Mat of ALL your HOG features for the PCA, not do that on a single feature. in other words, if you have 1234 images, and compute a hog feature for each, the input for the PCA is a Mat(1234, 11025, CV_32F)

berak gravatar imageberak ( 2018-04-22 06:03:18 -0600 )edit

@berak shall i mail you the code..its lenthy a bit...I would be more clear..!!

Shivanshu gravatar imageShivanshu ( 2018-04-22 06:07:21 -0600 )edit

put it on some gist or pastebin.

we also have this already and looking at it, i'd say the problem is, you only work on a single image ! you have to do that for all of your images, then stack the hog vectors into a single mat. nfeatures x nimages.

berak gravatar imageberak ( 2018-04-22 06:24:32 -0600 )edit

Ok wait forget what i said... NEW::Actually i obtained concatenated HOG vector of requested image(ROI) is about (total_no_of_patch x 9) for example i took a 114x114 size image then total no of patch will be (114/8)~14 patch along row and col then total_no_of_patch=14x14~196. then i have to iterate through all these 196 patches and estimate HOG .Means each patch gives 9-dimension HOG vector and there are total 196 patch so total size of final HOG will be 196x9~1764 dimensional HOGvector.final vector which is fed into PCA is actually a matrix of say1764 rows and 9 col..so that each row represent a HOG/patch and then i obtain 3 eigen values and vector as i requested and fed those eigen vector to neural net...I did this

Shivanshu gravatar imageShivanshu ( 2018-04-22 09:43:41 -0600 )edit

i see, what you mean now, though i object :

if you have each per-patch histogram on a single row, and do a PCA of it, you get the most prominent patches, but lose their locality and somehow defeat the purpose of "patches".

also, if you do that "per image", the outcome will wildly differ between images.

3 eigenvectors a 9 floats, that's 27 input neurons (only ?)

berak gravatar imageberak ( 2018-04-22 10:14:13 -0600 )edit

Yes 27 neurons in input layer...Is it something wrong here??Thats what i did...By the way if i ask for eigen vector and eigen values from PCA object then will it arrange eigen vector according to 1st,2nd....principal components or i have to find the one with maxium variance??

Shivanshu gravatar imageShivanshu ( 2018-04-22 11:27:00 -0600 )edit

@berak am i doing right??are those eigen vectors enoughf to feed neural net or i need to do something more??

Shivanshu gravatar imageShivanshu ( 2018-04-23 06:12:13 -0600 )edit

there is no wrong or right here, but imho, your eigenvectors might not be good features (and what you do is at least "unusual")

yes, those are sorted already. and probably you would not even need a full blown PCA, but you could use the simpler eigen()

berak gravatar imageberak ( 2018-04-23 06:18:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-21 08:31:30 -0600

Seen: 1,092 times

Last updated: Apr 22 '18