final refactoring and test for training

This commit is contained in:
marina.kolpakova
2013-01-30 13:34:34 +04:00
parent d314c602d5
commit 14ac8a528e
14 changed files with 287 additions and 102 deletions

View File

@@ -114,4 +114,27 @@ struct Random
#endif
#if defined _WIN32 && (_WIN32 || _WIN64)
# if _WIN64
# define USE_LONG_SEEDS
# endif
#endif
#if defined (__GNUC__) &&__GNUC__
# if defined(__x86_64__) || defined(__ppc64__)
# define USE_LONG_SEEDS
# endif
#endif
#if defined USE_LONG_SEEDS
# define FEATURE_RECT_SEED 8854342234LU
# define INDEX_ENGINE_SEED 764224349868LU
#else
# define FEATURE_RECT_SEED 88543422LU
# define INDEX_ENGINE_SEED 76422434LU
#endif
#undef USE_LONG_SEEDS
#define DCHANNELS_SEED 314152314LU
#define DX_DY_SEED 65633343LU
#endif

View File

@@ -41,7 +41,6 @@
//M*/
#include "precomp.hpp"
#include "_random.hpp"
namespace {
@@ -199,25 +198,6 @@ void ChannelFeaturePool::write( cv::FileStorage& fs, int index) const
fs << pool[index];
}
#if defined _WIN32 && (_WIN32 || _WIN64)
# if _WIN64
# define USE_LONG_SEEDS
# endif
#endif
#if defined (__GNUC__) &&__GNUC__
# if defined(__x86_64__) || defined(__ppc64__)
# define USE_LONG_SEEDS
# endif
#endif
#if defined USE_LONG_SEEDS
# define FEATURE_RECT_SEED 8854342234LU
#else
# define FEATURE_RECT_SEED 88543422LU
#endif
# define DCHANNELS_SEED 314152314LU
#undef USE_LONG_SEEDS
void ChannelFeaturePool::fill(int desired)
{
int mw = model.width;
@@ -226,8 +206,6 @@ void ChannelFeaturePool::fill(int desired)
int maxPoolSize = (mw -1) * mw / 2 * (mh - 1) * mh / 2 * N_CHANNELS;
int nfeatures = std::min(desired, maxPoolSize);
// dprintf("Requeste feature pool %d max %d suggested %d\n", desired, maxPoolSize, nfeatures);
pool.reserve(nfeatures);
sft::Random::engine eng(FEATURE_RECT_SEED);
@@ -262,7 +240,6 @@ void ChannelFeaturePool::fill(int desired)
if (std::find(pool.begin(), pool.end(),f) == pool.end())
{
pool.push_back(f);
std::cout << f << std::endl;
}
}
}

View File

@@ -53,7 +53,6 @@
#include "opencv2/core/core_c.h"
#include "opencv2/core/internal.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/opencv_modules.hpp"
#include "_random.hpp"
#endif

View File

@@ -43,17 +43,6 @@
#include "precomp.hpp"
#include <queue>
#include <string>
#include "_random.hpp"
#define WITH_DEBUG_OUT
#if defined WITH_DEBUG_OUT
# include <stdio.h>
# define dprintf(format, ...) printf(format, ##__VA_ARGS__)
#else
# define dprintf(format, ...)
#endif
using cv::Dataset;
using cv::FeaturePool;
@@ -90,7 +79,7 @@ protected:
float predict( const Mat& _sample, const cv::Range range) const;
private:
void traverse(const CvBoostTree* tree, cv::FileStorage& fs, int& nfeatures, int* used, const double* th) const;
virtual void initial_weights(double (&p)[2]);
virtual void initialize_weights(double (&p)[2]);
int logScale;
cv::Rect boundingBox;
@@ -159,8 +148,6 @@ bool BoostedSoftCascadeOctave::train( const cv::Mat& _trainData, const cv::Mat&
void BoostedSoftCascadeOctave::setRejectThresholds(cv::OutputArray _thresholds)
{
dprintf("set thresholds according to DBP strategy\n");
// labels decided by classifier
cv::Mat desisions(responses.cols, responses.rows, responses.type());
float* dptr = desisions.ptr<float>(0);
@@ -223,33 +210,10 @@ void BoostedSoftCascadeOctave::processPositives(const Dataset* dataset)
if (++total >= npositives) break;
}
dprintf("Processing positives finished:\n\trequested %d positives, collected %d samples.\n", npositives, total);
npositives = total;
nnegatives = cvRound(nnegatives * total / (double)npositives);
}
#if defined _WIN32 && (_WIN32 || _WIN64)
# if _WIN64
# define USE_LONG_SEEDS
# endif
#endif
#if defined (__GNUC__) &&__GNUC__
# if defined(__x86_64__) || defined(__ppc64__)
# define USE_LONG_SEEDS
# endif
#endif
#if defined USE_LONG_SEEDS
# define INDEX_ENGINE_SEED 764224349868LU
#else
# define INDEX_ENGINE_SEED 76422434LU
#endif
# define DX_DY_SEED 65633343LU
#undef USE_LONG_SEEDS
void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset)
{
// ToDo: set seed, use offsets
@@ -285,15 +249,12 @@ void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset)
cv::Mat channels = integrals.row(i).reshape(0, h / shrinkage * 10 + 1);
_builder(frame, channels);
dprintf("generated %d %d\n", dx, dy);
// // if (predict(sum))
{
responses.ptr<float>(i)[0] = 0.f;
++i;
}
}
dprintf("Processing negatives finished:\n\trequested %d negatives, viewed %d samples.\n", nnegatives, total);
}
@@ -390,7 +351,7 @@ void BoostedSoftCascadeOctave::write( cv::FileStorage &fso, const FeaturePool* p
<< "}";
}
void BoostedSoftCascadeOctave::initial_weights(double (&p)[2])
void BoostedSoftCascadeOctave::initialize_weights(double (&p)[2])
{
double n = data->sample_count;
p[0] = n / (2. * (double)(nnegatives));