00001 /*!@file VFAT/test-featureNPC.C Test the non-parametric classifier */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-featureNPC.C $ 00035 // $Id: test-featureNPC.C 6003 2005-11-29 17:22:45Z rjpeters $ 00036 // 00037 00038 // ############################################################ 00039 // ############################################################ 00040 // ##### ---NPclassify--- 00041 // ##### non-parametric classifier: 00042 // ##### T. Nathan Mundhenk nathan@mundhenk.com 00043 // ##### Vidhya Navalpakkam - navalpak@usc.edu 00044 // ##### partners full name - email 00045 // ############################################################ 00046 // ############################################################ 00047 00048 //This is the start of the execution path for the NPclassify test alg. 00049 00050 #include "Util/Timer.H" 00051 #include "VFAT/NPclassify.H" 00052 00053 #include <fstream> 00054 #include <iostream> 00055 00056 //! This is the configFile name 00057 char* configFile; 00058 //! This is the configFile object 00059 readConfig configIn(25); 00060 readConfig polySet(25); 00061 //! number of items if training 00062 int itemNumber; 00063 00064 int main(int argc, char* argv[]) 00065 { 00066 00067 std::cerr << "STARTING\n"; 00068 std::cerr << "Opening config file" << argv[1] << "\n"; 00069 std::ifstream inFile(argv[1],std::ios::in); 00070 std::vector<double> dataIn(7,0.0F); 00071 std::vector< std::vector<double> > vectorIn(1000,dataIn); 00072 int column = 0; 00073 int row = 0; 00074 int family = 0; 00075 bool comment = false; 00076 00077 std::string in; 00078 std::cerr << "Parsing config file" << argv[1] << "\n"; 00079 while (inFile >> in) 00080 { 00081 00082 if(!in.compare("#")) //comment code # found 00083 { 00084 if(!comment) 00085 { 00086 comment = true; 00087 } 00088 else //end of comment 00089 { 00090 comment = false; 00091 } 00092 } 00093 if((!comment) && in.compare("#")) //real line found 00094 { 00095 if(column == 1) 00096 { 00097 //vectorIn[row][family] = atof(in.c_str()); 00098 //std::cerr << "Adding " << in << "[" << row << "]" 00099 // << "[" << family*2 << "]\n"; 00100 } 00101 if(column == 3) 00102 { 00103 vectorIn[row][family] = atof(in.c_str()); 00104 //std::cerr << "Adding " << in << "[" << row << "]" 00105 // << "[" << (family*2)+1 << "]\n"; 00106 } 00107 column++; 00108 if(column == 5) 00109 { 00110 column = 0; 00111 row++; 00112 } 00113 if(!in.compare("%")) 00114 { 00115 row = 0; 00116 column = 0; 00117 family++; 00118 std::cerr << "New Family " << family << "\n"; 00119 } 00120 } 00121 } 00122 00123 // start timer 00124 Timer tim; 00125 tim.reset(); 00126 uint64 t0 = tim.get(); // to measure display time 00127 // get test image 00128 00129 if(argc > 2) 00130 itemNumber = atoi(argv[2]); 00131 else 00132 itemNumber = -666; 00133 00134 // create operating objects 00135 configIn.openFile("NPclassify.conf"); 00136 polySet.openFile("polySet.conf"); 00137 00138 NPclassify NP(configIn,polySet,true); 00139 if(argc > 3) 00140 { 00141 NP.inputCommandLineSettings(atof(argv[3]),atof(argv[4]),atof(argv[5]), 00142 atof(argv[6]),atoi(argv[7]),atoi(argv[8]), 00143 atof(argv[9]),atof(argv[10]),atof(argv[11])); 00144 } 00145 00146 //inport data 00147 00148 std::vector<double> feature(2,0); 00149 std::vector<long> roots; 00150 std::vector<long> parents; 00151 std::vector<double> density; 00152 00153 NP.addSpace(vectorIn,(row-1)); 00154 NP.classifySpaceNew(); 00155 uint64 t1 = tim.get(); 00156 t0 = t1 - t0; 00157 00158 roots = NP.getStems(); 00159 parents = NP.getParents(); 00160 density = NP.getDensity(); 00161 00162 std::vector<std::vector<long> > theReturn = NP.getChildren(); 00163 for(int i = 0; i < NP.getStemNumber(); i++) 00164 { 00165 if(NP.getClassSize(i) > NP.getMinClassSize()) 00166 { 00167 LINFO("CLASS %d size %ld",i,NP.getClassSize(i)); 00168 } 00169 } 00170 //outport classification data 00171 00172 NP.metaClassify(itemNumber); 00173 00174 std::ofstream outfile("feature_trian.dat",std::ios::out); 00175 std::ofstream matfile("feature_trian_mat.dat",std::ios::out); 00176 for(int i = 0; i < NP.getStemNumber(); i++) 00177 { 00178 for(int j = 0; j < NP.getClassSize(i); j++) 00179 { 00180 long item = NP.getClass(i,j); 00181 outfile << item << "\t" << i << "\t" << j << "\t" 00182 << NP.getFeature(item,0) << "\t" 00183 << NP.getFeature(item,1) << "\n"; 00184 matfile << item << "\t" << i << "\n"; 00185 } 00186 } 00187 00188 00189 }