2014-02-28 06:17:12 -0600 | answered a question | KMean and PCA connection I did not use KMean but I used PCA for my neural network training data to reduce features. It is in C++ interface of OpenCV. Let's start by reading csv file. My csv file is like : im_path_1;label1 So to read that csv file, my function : void read_csv(const string& filename, vector<mat>& images, vector<int>& labels, char separator = ';') { std::ifstream file(filename.c_str(), ifstream::in); if (!file) { string error_message = "No valid input file was given, please check the given filename."; CV_Error(1, error_message); } string line, path, classlabel; while (getline(file, line)) { stringstream liness(line); getline(liness, path, separator); getline(liness, classlabel); if(!path.empty() && !classlabel.empty()) { Mat im = imread(path, 0); images.push_back(im); labels.push_back(atoi(classlabel.c_str())); } } } It is holding data in vector of Mat variables. OpenCV's PCA requires data to be rolled as row vectors in a Mat variable. To do that : A simple usage of this functions : trainData variable is the reduced version of the train set. And for pca_size variable; instead of using it as 500; you can give pca to 0.95 to retain %95 variance. I hope this helps for the PCA part. I used this reduced data to train a Neural Network. |
2014-02-28 06:15:06 -0600 | received badge | ● Critic (source) |
2014-02-28 04:27:12 -0600 | received badge | ● Nice Answer (source) |
2014-02-28 03:54:43 -0600 | received badge | ● Teacher (source) |
2014-02-28 00:25:12 -0600 | answered a question | How to compile OpenCV 2.4.8 static libs using MinGW on Windows 7 I think you are having a syntax error. You should set BUILD_SHARED_LIBS to off. This is the way how opencv can be compiled as static libs. |
2014-02-26 07:36:58 -0600 | received badge | ● Student (source) |
2014-02-26 07:33:53 -0600 | received badge | ● Autobiographer |
2014-02-26 07:27:25 -0600 | received badge | ● Organizer (source) |
2014-02-26 07:25:54 -0600 | asked a question | OpenCV Neural Network Sigmoid Output I have been using OpenCV for a quite time. I decided to check its power for Machine Learning lately. So I ended up with implementing a neural network for face recognition. To summarize my strategy for face recognition :
So everything was OK until the prediction stage. I was using the max responsed output unit to classify the face. So normally OpenCV's sigmoid implementation should give values in range of -1 to 1 which is stated at the docs. 1 is the max closure to class. After I got nearly 0 accuracy I checked the output responses for each class for each test data. I was suprised with the values : 14.53, -1.7 , #IND . If sigmoid was applied, how could i get these values ? Where am i doing wrong ? To help you understand the matter and for the ones wondering how to apply PCA and use it with NN I m sharing my code : Reading csv: void read_csv(const string& filename, vector<mat>& images, vector<int>& labels, char separator = ';') { std::ifstream file(filename.c_str(), ifstream::in); if (!file) { string error_message = "No valid input file was given, please check the given filename."; CV_Error(1, error_message); } string line, path, classlabel; while (getline(file, line)) { stringstream liness(line); getline(liness, path, separator); getline(liness, classlabel); if(!path.empty() && !classlabel.empty()) { Mat im = imread(path, 0); images.push_back(im); labels.push_back(atoi(classlabel.c_str())); } } } Rolling images row by row : Converting vector of labels to Mat of labels MAIN (more) |