00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00027 #include "peddetect.h" 00028 00029 int main (int argc, char **argv) 00030 { 00031 00032 /* STEP 2. Opening the file */ 00033 //1. Declare a structure to keep the data 00034 CvMLData cvml; 00035 //2. Read the file 00036 cvml.read_csv ("/home/pedrobatista/workingcopy/lar3/perception/pedestrians/PedestrianDetect/train_seed1234_rand.csv"); 00037 //3. Indicate which column is the response 00038 cvml.set_response_idx (0); 00039 00040 /* STEP 3. Splitting the samples */ 00041 //1. Select 40 for the training 00042 CvTrainTestSplit cvtts (8000, true); 00043 //2. Assign the division to the data 00044 cvml.set_train_test_split (&cvtts); 00045 00046 printf ("Training ... "); 00047 /* STEP 4. The training */ 00048 //1. Declare the classifier 00049 CvBoost boost; 00050 //2. Train it with 100 features 00051 boost.train (&cvml, CvBoostParams (CvBoost::REAL,1500, 0.95, 2, false, 0), 00052 false); 00053 00054 /* STEP 5. Calculating the testing and training error */ 00055 // 1. Declare a couple of vectors to save the predictions of each sample 00056 std::vector<float> train_responses, test_responses; 00057 // 2. Calculate the training error 00058 float fl1 = boost.calc_error (&cvml, CV_TRAIN_ERROR, &train_responses); 00059 // 3. Calculate the test error 00060 float fl2 = boost.calc_error (&cvml, CV_TEST_ERROR, &test_responses); 00061 00062 cout<<"Error train: "<<fl1<<endl; 00063 00064 cout<<"Error test: "<<fl2<<endl; 00065 00066 /* STEP 6. Save your classifier */ 00067 // Save the trained classifier 00068 // boost.save ("./trained_boost_8000samples-1000ftrs.xml", "boost"); 00069 00070 return 0; 00071 }