From 2c8c4ddf77db16d09fe3619ec2a788ed275c41f8 Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Wed, 24 Sep 2014 16:40:18 +0400 Subject: [PATCH] added benchmark for ar_hmdb --- modules/datasets/CMakeLists.txt | 3 +- modules/datasets/doc/datasets/ar_hmdb.rst | 13 + modules/datasets/doc/datasets/fr_lfw.rst | 12 +- .../datasets/samples/ar_hmdb_benchmark.cpp | 276 ++++++++++++++++++ 4 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 modules/datasets/samples/ar_hmdb_benchmark.cpp diff --git a/modules/datasets/CMakeLists.txt b/modules/datasets/CMakeLists.txt index 3c82ba2da..d01e5b288 100644 --- a/modules/datasets/CMakeLists.txt +++ b/modules/datasets/CMakeLists.txt @@ -1,3 +1,4 @@ set(the_description "datasets framework") -ocv_define_module(datasets opencv_core opencv_face) +ocv_define_module(datasets opencv_core opencv_face opencv_ml opencv_flann) +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4267) # flann, Win64 diff --git a/modules/datasets/doc/datasets/ar_hmdb.rst b/modules/datasets/doc/datasets/ar_hmdb.rst index b7258d807..9cd1c78d3 100644 --- a/modules/datasets/doc/datasets/ar_hmdb.rst +++ b/modules/datasets/doc/datasets/ar_hmdb.rst @@ -14,3 +14,16 @@ _`"HMDB: A Large Human Motion Database"`: http://serre-lab.clps.brown.edu/resour 3. To load data run: ./opencv/build/bin/example_datasets_ar_hmdb -p=/home/user/path_to_unpacked_folders/ +Benchmark +""""""""" + +For this dataset was implemented benchmark, which gives accuracy: 0.107407 (using precomputed HOG/HOF "STIP" features from site, averaging for 3 splits) + +To run this benchmark execute: + +.. code-block:: bash + + ./opencv/build/bin/example_datasets_ar_hmdb_benchmark -p=/home/user/path_to_unpacked_folders/ + +(precomputed features should be unpacked in the same folder: /home/user/path_to_unpacked_folders/hmdb51_org_stips/) + diff --git a/modules/datasets/doc/datasets/fr_lfw.rst b/modules/datasets/doc/datasets/fr_lfw.rst index fb7f9f2b5..00182a179 100644 --- a/modules/datasets/doc/datasets/fr_lfw.rst +++ b/modules/datasets/doc/datasets/fr_lfw.rst @@ -14,8 +14,14 @@ _`"Labeled Faces in the Wild"`: http://vis-www.cs.umass.edu/lfw/ 3. To load data run: ./opencv/build/bin/example_datasets_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ -.. note:: Benchmark +Benchmark +""""""""" - - For this dataset was implemented benchmark, which gives accuracy: 0.623833 +- 0.005223 (train split: pairsDevTrain.txt, dataset: lfwa) - - To run this benchmark execute: ./opencv/build/bin/example_datasets_fr_lfw_benchmark -p=/home/user/path_to_unpacked_folder/lfw2/ +For this dataset was implemented benchmark, which gives accuracy: 0.623833 +- 0.005223 (train split: pairsDevTrain.txt, dataset: lfwa) + +To run this benchmark execute: + +.. code-block:: bash + + ./opencv/build/bin/example_datasets_fr_lfw_benchmark -p=/home/user/path_to_unpacked_folder/lfw2/ diff --git a/modules/datasets/samples/ar_hmdb_benchmark.cpp b/modules/datasets/samples/ar_hmdb_benchmark.cpp new file mode 100644 index 000000000..39ff07c31 --- /dev/null +++ b/modules/datasets/samples/ar_hmdb_benchmark.cpp @@ -0,0 +1,276 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "opencv2/datasets/ar_hmdb.hpp" +#include "opencv2/datasets/util.hpp" + +#include +#include +#include + +#include + +#include +#include +#include + +using namespace std; +using namespace cv; +using namespace cv::datasets; +using namespace cv::flann; +using namespace cv::ml; + +unsigned int getNumFiles(vector< Ptr > &curr); +unsigned int getNumFiles(vector< Ptr > &curr) +{ + unsigned int numFiles = 0; + for (unsigned int i=0; i(curr[i].get()); + vector &videoNames = example->videoNames; + for (vector::iterator it=videoNames.begin(); it!=videoNames.end(); ++it) + { + numFiles++; + } + } + + return numFiles; +} + +void fillData(const string &path, vector< Ptr > &curr, Index &flann_index, Mat1f &data, Mat1i &labels); +void fillData(const string &path, vector< Ptr > &curr, Index &flann_index, Mat1f &data, Mat1i &labels) +{ + const unsigned int descriptorNum = 162; + Mat1f sample(1, descriptorNum); + Mat1i nresps(1, 1); + Mat1f dists(1, 1); + + unsigned int numFiles = 0; + for (unsigned int i=0; i(curr[i].get()); + vector &videoNames = example->videoNames; + for (vector::iterator it=videoNames.begin(); it!=videoNames.end(); ++it) + { + string featuresFile = *it + ".txt"; + string featuresFullPath = path + "hmdb51_org_stips/" + example->name + "/" + featuresFile; + + ifstream infile(featuresFullPath.c_str()); + string line; + // skip header + for (unsigned int j=0; j<3; ++j) + { + getline(infile, line); + } + while (getline(infile, line)) + { + // 7 skip, hog+hof: 72+90 read + vector elems; + split(line, elems, '\t'); + + for (unsigned int j=0; j("path")); + if (parser.has("help") || path=="true") + { + parser.printMessage(); + return -1; + } + + // loading dataset + Ptr dataset = AR_hmdb::create(); + dataset->load(path); + + int numSplits = dataset->getNumSplits(); + printf("splits number: %u\n", numSplits); + + + const unsigned int descriptorNum = 162; + const unsigned int clusterNum = 4000; + const unsigned int sampleNum = 5613856; // max for all 3 splits + + vector res; + for (int currSplit=0; currSplit > &curr = dataset->getTrain(currSplit); + unsigned int numTrainFiles = getNumFiles(curr); + unsigned int numFeatures = 0; + for (unsigned int i=0; i(curr[i].get()); + vector &videoNames = example->videoNames; + for (vector::iterator it=videoNames.begin(); it!=videoNames.end(); ++it) + { + string featuresFile = *it + ".txt"; + string featuresFullPath = path + "hmdb51_org_stips/" + example->name + "/" + featuresFile; + + ifstream infile(featuresFullPath.c_str()); + string line; + // skip header + for (unsigned int j=0; j<3; ++j) + { + getline(infile, line); + } + while (getline(infile, line)) + { + numFeatures++; + if (currSample < sampleNum) + { + // 7 skip, hog+hof: 72+90 read + vector elems; + split(line, elems, '\t'); + + for (unsigned int j=0; j >(samples, centers, kmean_params); + if (resultClusters < clusterNum) + { + centers = centers.rowRange(Range(0, resultClusters)); + } + Index flann_index(centers, KDTreeIndexParams()); + printf("resulted clusters number: %u\n", resultClusters); + + + Mat1f trainData(numTrainFiles, resultClusters); + Mat1i trainLabels(numTrainFiles, 1); + + for (unsigned int i=0; i svm = SVM::create(params); + svm->train(trainData, ROW_SAMPLE, trainLabels); + + // prepare to predict + curr = dataset->getTest(currSplit); + unsigned int numTestFiles = getNumFiles(curr); + Mat1f testData(numTestFiles, resultClusters); + Mat1i testLabels(numTestFiles, 1); // ground true + + for (unsigned int i=0; ipredict(testData, testPredicted); + + unsigned int correct = 0; + for (unsigned int i=0; i